github.com/cockroachdb/tools@v0.0.0-20230222021103-a6d27438930d/present/html.go (about) 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 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 } 28 return HTML{text, template.HTML(b)}, nil 29 } 30 31 type HTML struct { 32 Cmd string // original command from present source 33 template.HTML 34 } 35 36 func (s HTML) PresentCmd() string { return s.Cmd } 37 func (s HTML) TemplateName() string { return "html" }