Rebecca Stambler | 9277847 | 2021-01-05 23:05:35 -0500 | [diff] [blame] | 1 | // 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 Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 5 | package present |
| 6 | |
| 7 | import ( |
| 8 | "errors" |
| 9 | "html/template" |
| 10 | "path/filepath" |
| 11 | "strings" |
| 12 | ) |
| 13 | |
| 14 | func init() { |
| 15 | Register("html", parseHTML) |
| 16 | } |
| 17 | |
| 18 | func 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 Cox | 657575a | 2020-03-09 22:20:35 -0400 | [diff] [blame] | 28 | return HTML{text, template.HTML(b)}, nil |
Andrew Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | type HTML struct { |
Russ Cox | 657575a | 2020-03-09 22:20:35 -0400 | [diff] [blame] | 32 | Cmd string // original command from present source |
Andrew Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 33 | template.HTML |
| 34 | } |
| 35 | |
Russ Cox | 657575a | 2020-03-09 22:20:35 -0400 | [diff] [blame] | 36 | func (s HTML) PresentCmd() string { return s.Cmd } |
Andrew Gerrand | 9fc5164 | 2013-09-19 10:55:46 +1000 | [diff] [blame] | 37 | func (s HTML) TemplateName() string { return "html" } |