File: html_comment.go

package info (click to toggle)
golang-github-yosssi-ace 0.0.4%2Bgit20160102.51.71afeb7-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 468 kB
  • ctags: 249
  • sloc: makefile: 3; sh: 1
file content (69 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ace

import (
	"bytes"
	"io"
	"strings"
)

// htmlComment represents an HTML comment.
type htmlComment struct {
	elementBase
}

// WriteTo writes data to w.
func (e *htmlComment) WriteTo(w io.Writer) (int64, error) {
	var bf bytes.Buffer

	// Write an open tag.
	bf.WriteString(e.opts.DelimLeft)
	bf.WriteString(preDefinedFuncNameHTML)
	bf.WriteString(space)
	bf.WriteString(doubleQuote)
	bf.WriteString(lt)
	bf.WriteString(exclamation)
	bf.WriteString(doubleQuote)
	bf.WriteString(e.opts.DelimRight)
	bf.WriteString(hyphen)
	bf.WriteString(hyphen)

	// Write the HTML comment
	if len(e.ln.tokens) > 1 {
		bf.WriteString(space)
		bf.WriteString(strings.Join(e.ln.tokens[1:], space))
	}

	// Write the children's HTML.
	if len(e.children) > 0 {
		bf.WriteString(lf)

		if i, err := e.writeChildren(&bf); err != nil {
			return i, err
		}
	} else {
		bf.WriteString(space)

	}

	// Write a close tag.
	bf.WriteString(hyphen)
	bf.WriteString(hyphen)
	bf.WriteString(gt)

	// Write the buffer.
	i, err := w.Write(bf.Bytes())

	return int64(i), err
}

// ContainPlainText returns true.
func (e *htmlComment) ContainPlainText() bool {
	return true
}

// newHTMLComment creates and returns an HTML comment.
func newHTMLComment(ln *line, rslt *result, src *source, parent element, opts *Options) *htmlComment {
	return &htmlComment{
		elementBase: newElementBase(ln, rslt, src, parent, opts),
	}
}