Add support for ": example" elements

This commit is contained in:
Niklas Fasching 2018-12-16 23:21:26 +01:00
parent 24ace5aa0e
commit c012b0a533
8 changed files with 75 additions and 0 deletions

26
org/example.go Normal file
View file

@ -0,0 +1,26 @@
package org
import (
"regexp"
)
type Example struct {
Children []Node
}
var exampleLineRegexp = regexp.MustCompile(`^(\s*): (.*)`)
func lexExample(line string) (token, bool) {
if m := exampleLineRegexp.FindStringSubmatch(line); m != nil {
return token{"example", len(m[1]), m[2], m}, true
}
return nilToken, false
}
func (d *Document) parseExample(i int, parentStop stopFn) (int, Node) {
example, start := Example{}, i
for ; !parentStop(d, i) && d.tokens[i].kind == "example"; i++ {
example.Children = append(example.Children, Text{d.tokens[i].content})
}
return i - start, example
}