plain_text_inner.go 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package ace
  2. import "io"
  3. // HTML
  4. const (
  5. htmlBr = "<br>"
  6. )
  7. // plainTextInner represents a plain text inner.
  8. type plainTextInner struct {
  9. elementBase
  10. insertBr bool
  11. }
  12. // WriteTo writes data to w.
  13. func (e *plainTextInner) WriteTo(w io.Writer) (int64, error) {
  14. s := ""
  15. if (e.parent.Base().ln.indent+1)*2 <= len(e.ln.str) {
  16. s = e.ln.str[(e.parent.Base().ln.indent+1)*2:]
  17. }
  18. if e.insertBr && !e.lastChild {
  19. s += htmlBr
  20. }
  21. i, err := w.Write([]byte(s + lf))
  22. return int64(i), err
  23. }
  24. // CanHaveChildren returns false.
  25. func (e *plainTextInner) CanHaveChildren() bool {
  26. return false
  27. }
  28. // newPlainTextInner creates and returns a plain text.
  29. func newPlainTextInner(ln *line, rslt *result, src *source, parent element, insertBr bool, opts *Options) *plainTextInner {
  30. return &plainTextInner{
  31. elementBase: newElementBase(ln, rslt, src, parent, opts),
  32. insertBr: insertBr,
  33. }
  34. }