From 2cf09dcf03989ac1e981314c2a0ac14829870a3f Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Mon, 7 Jan 2019 20:26:27 +0100 Subject: [PATCH] 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. --- org/headline.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org/headline.go b/org/headline.go index 3b54408..4788f34 100644 --- a/org/headline.go +++ b/org/headline.go @@ -35,14 +35,14 @@ var tagRegexp = regexp.MustCompile(`(.*?)\s+(:[A-Za-z0-9_@#%:]+:\s*$)`) func lexHeadline(line string) (token, bool) { 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 } func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { t, headline := d.tokens[i], Headline{} - headline.Lvl = len(t.matches[1]) + headline.Lvl = t.lvl headline.Index = d.addHeadline(&headline)