While adding another test case from the goorgeous issues it became clear that inline markup and html entity replacement were erronously applied to raw text elements like inline code =foo=, src/example/export blocks, example lines, etc. To correctly handle those cases in both org and html exports a new parseRawInline method had to be added. Also some misc html export whitespace fixes and stuff
26 lines
608 B
Go
26 lines
608 B
Go
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, true})
|
|
}
|
|
return i - start, example
|
|
}
|