Refactor: Move some code
Example nodes are a kind of block and it's not much code so we can just put it next to the Block code. Feels cleaner but doesn't change much.
This commit is contained in:
parent
edd22b5014
commit
148eef5aeb
3 changed files with 21 additions and 26 deletions
20
org/block.go
20
org/block.go
|
@ -12,6 +12,11 @@ type Block struct {
|
|||
Children []Node
|
||||
}
|
||||
|
||||
type Example struct {
|
||||
Children []Node
|
||||
}
|
||||
|
||||
var exampleLineRegexp = regexp.MustCompile(`^(\s*):(\s(.*)|\s*$)`)
|
||||
var beginBlockRegexp = regexp.MustCompile(`(?i)^(\s*)#\+BEGIN_(\w+)(.*)`)
|
||||
var endBlockRegexp = regexp.MustCompile(`(?i)^(\s*)#\+END_(\w+)`)
|
||||
|
||||
|
@ -24,6 +29,13 @@ func lexBlock(line string) (token, bool) {
|
|||
return nilToken, false
|
||||
}
|
||||
|
||||
func lexExample(line string) (token, bool) {
|
||||
if m := exampleLineRegexp.FindStringSubmatch(line); m != nil {
|
||||
return token{"example", len(m[1]), m[3], m}, true
|
||||
}
|
||||
return nilToken, false
|
||||
}
|
||||
|
||||
func isRawTextBlock(name string) bool { return name == "SRC" || name == "EXAMPLE" || name == "EXPORT" }
|
||||
|
||||
func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) {
|
||||
|
@ -51,6 +63,14 @@ func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
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, true})
|
||||
}
|
||||
return i - start, example
|
||||
}
|
||||
|
||||
func trimIndentUpTo(max int) func(string) string {
|
||||
return func(line string) string {
|
||||
i := 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue