You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

footnote.go 999B

1234567891011121314151617181920212223242526272829303132333435
  1. package org
  2. import (
  3. "regexp"
  4. )
  5. type FootnoteDefinition struct {
  6. Name string
  7. Children []Node
  8. Inline bool
  9. }
  10. var footnoteDefinitionRegexp = regexp.MustCompile(`^\[fn:([\w-]+)\](\s+(.+)|\s*$)`)
  11. func lexFootnoteDefinition(line string) (token, bool) {
  12. if m := footnoteDefinitionRegexp.FindStringSubmatch(line); m != nil {
  13. return token{"footnoteDefinition", 0, m[1], m}, true
  14. }
  15. return nilToken, false
  16. }
  17. func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node) {
  18. start, name := i, d.tokens[i].content
  19. d.tokens[i] = tokenize(d.tokens[i].matches[2])
  20. stop := func(d *Document, i int) bool {
  21. return parentStop(d, i) ||
  22. (isSecondBlankLine(d, i) && i > start+1) ||
  23. d.tokens[i].kind == "headline" || d.tokens[i].kind == "footnoteDefinition"
  24. }
  25. consumed, nodes := d.parseMany(i, stop)
  26. definition := FootnoteDefinition{name, nodes, false}
  27. return consumed, definition
  28. }
  29. func (n FootnoteDefinition) String() string { return orgWriter.WriteNodesAsString(n) }