action.go 828 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package ace
  2. import (
  3. "bytes"
  4. "io"
  5. "strings"
  6. )
  7. // action represents an action.
  8. type action struct {
  9. elementBase
  10. }
  11. // WriteTo writes data to w.
  12. func (e *action) WriteTo(w io.Writer) (int64, error) {
  13. var bf bytes.Buffer
  14. // Write the action
  15. bf.WriteString(strings.TrimSpace(e.ln.str))
  16. // Write the children's HTML.
  17. if i, err := e.writeChildren(&bf); err != nil {
  18. return i, err
  19. }
  20. // Write the buffer.
  21. i, err := w.Write(bf.Bytes())
  22. return int64(i), err
  23. }
  24. func (e *action) IsBlockElement() bool {
  25. return e.parent.IsBlockElement()
  26. }
  27. func (e *action) IsControlElement() bool {
  28. return true
  29. }
  30. // newAction creates and returns an action.
  31. func newAction(ln *line, rslt *result, src *source, parent element, opts *Options) *action {
  32. return &action{
  33. elementBase: newElementBase(ln, rslt, src, parent, opts),
  34. }
  35. }