blob: 0c1548cf883b4ae9f9082bebb561b5ceab415503 [file] [log] [blame]
Rebecca Stambler92778472021-01-05 23:05:35 -05001// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Andrew Gerrand9fc51642013-09-19 10:55:46 +10005package present
6
7import (
8 "errors"
9 "html/template"
10 "path/filepath"
11 "strings"
12)
13
14func init() {
15 Register("html", parseHTML)
16}
17
18func parseHTML(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
19 p := strings.Fields(text)
20 if len(p) != 2 {
21 return nil, errors.New("invalid .html args")
22 }
23 name := filepath.Join(filepath.Dir(fileName), p[1])
24 b, err := ctx.ReadFile(name)
25 if err != nil {
26 return nil, err
27 }
Russ Cox657575a2020-03-09 22:20:35 -040028 return HTML{text, template.HTML(b)}, nil
Andrew Gerrand9fc51642013-09-19 10:55:46 +100029}
30
31type HTML struct {
Russ Cox657575a2020-03-09 22:20:35 -040032 Cmd string // original command from present source
Andrew Gerrand9fc51642013-09-19 10:55:46 +100033 template.HTML
34}
35
Russ Cox657575a2020-03-09 22:20:35 -040036func (s HTML) PresentCmd() string { return s.Cmd }
Andrew Gerrand9fc51642013-09-19 10:55:46 +100037func (s HTML) TemplateName() string { return "html" }