Fix AST headline nesting
Headlines are nested if their level is higher (more stars) than the current headline. We're abusing the token.lvl field for this - as headlines can never be indented we know the indentation must be 0 so we can cache the lvl (count of stars) of the headline in that field. This doesn't change anything right now so I'll postpone adding tests and stuff until there are actual use cases for the AST and stuff.
This commit is contained in:
parent
63fef04fb3
commit
2cf09dcf03
1 changed files with 2 additions and 2 deletions
|
@ -35,14 +35,14 @@ var tagRegexp = regexp.MustCompile(`(.*?)\s+(:[A-Za-z0-9_@#%:]+:\s*$)`)
|
||||||
|
|
||||||
func lexHeadline(line string) (token, bool) {
|
func lexHeadline(line string) (token, bool) {
|
||||||
if m := headlineRegexp.FindStringSubmatch(line); m != nil {
|
if m := headlineRegexp.FindStringSubmatch(line); m != nil {
|
||||||
return token{"headline", 0, m[2], m}, true
|
return token{"headline", len(m[1]), m[2], m}, true
|
||||||
}
|
}
|
||||||
return nilToken, false
|
return nilToken, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) {
|
func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) {
|
||||||
t, headline := d.tokens[i], Headline{}
|
t, headline := d.tokens[i], Headline{}
|
||||||
headline.Lvl = len(t.matches[1])
|
headline.Lvl = t.lvl
|
||||||
|
|
||||||
headline.Index = d.addHeadline(&headline)
|
headline.Index = d.addHeadline(&headline)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue