html_comment.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package ace
  2. import (
  3. "bytes"
  4. "io"
  5. "strings"
  6. )
  7. // htmlComment represents an HTML comment.
  8. type htmlComment struct {
  9. elementBase
  10. }
  11. // WriteTo writes data to w.
  12. func (e *htmlComment) WriteTo(w io.Writer) (int64, error) {
  13. var bf bytes.Buffer
  14. // Write an open tag.
  15. bf.WriteString(e.opts.DelimLeft)
  16. bf.WriteString(preDefinedFuncNameHTML)
  17. bf.WriteString(space)
  18. bf.WriteString(doubleQuote)
  19. bf.WriteString(lt)
  20. bf.WriteString(exclamation)
  21. bf.WriteString(doubleQuote)
  22. bf.WriteString(e.opts.DelimRight)
  23. bf.WriteString(hyphen)
  24. bf.WriteString(hyphen)
  25. // Write the HTML comment
  26. if len(e.ln.tokens) > 1 {
  27. bf.WriteString(space)
  28. bf.WriteString(strings.Join(e.ln.tokens[1:], space))
  29. }
  30. // Write the children's HTML.
  31. if len(e.children) > 0 {
  32. bf.WriteString(lf)
  33. if i, err := e.writeChildren(&bf); err != nil {
  34. return i, err
  35. }
  36. } else {
  37. bf.WriteString(space)
  38. }
  39. // Write a close tag.
  40. bf.WriteString(hyphen)
  41. bf.WriteString(hyphen)
  42. bf.WriteString(gt)
  43. // Write the buffer.
  44. i, err := w.Write(bf.Bytes())
  45. return int64(i), err
  46. }
  47. // ContainPlainText returns true.
  48. func (e *htmlComment) ContainPlainText() bool {
  49. return true
  50. }
  51. // newHTMLComment creates and returns an HTML comment.
  52. func newHTMLComment(ln *line, rslt *result, src *source, parent element, opts *Options) *htmlComment {
  53. return &htmlComment{
  54. elementBase: newElementBase(ln, rslt, src, parent, opts),
  55. }
  56. }