diff --git a/org/headline.go b/org/headline.go index 749d1ff..7e0b8eb 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", len(m[1]), m[2], m}, true + return token{"headline", 0, 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 = t.lvl + headline.Lvl = len(t.matches[1]) headline.Index = d.addHeadline(&headline) @@ -69,7 +69,7 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { headline.Title = d.parseInline(text) stop := func(d *Document, i int) bool { - return parentStop(d, i) || d.tokens[i].kind == "headline" && d.tokens[i].lvl <= headline.Lvl + return parentStop(d, i) || d.tokens[i].kind == "headline" && len(d.tokens[i].matches[1]) <= headline.Lvl } consumed, nodes := d.parseMany(i+1, stop) if len(nodes) > 0 { diff --git a/org/testdata/misc.html b/org/testdata/misc.html index 35ba018..6f84275 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -72,9 +72,15 @@
  • index out of range in explicit line break parsing
  • +
  • list items don't end on child headline +
  • -
  • Footnotes + +
  • +
  • Footnotes
  • @@ -550,10 +556,34 @@ index out of range in explicit line break parsing

    0\\

    +
    +

    +list items don't end on child headline +

    +
    + +
    +
    +followed by a child headline +
    +
    +
      +
    • +

      followed by another list item

      +
    • +
    -
    -

    +

    +
    +
    + +
    +

    Footnotes

    diff --git a/org/testdata/misc.org b/org/testdata/misc.org index b2b95ca..8614633 100644 --- a/org/testdata/misc.org +++ b/org/testdata/misc.org @@ -140,6 +140,10 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- *** index out of range in explicit line break parsing 0\\ +*** list items don't end on child headline +- a list item +**** followed by a child headline +- followed by another list item * Footnotes [fn:1] a footnote /with/ *markup* diff --git a/org/testdata/misc.pretty_org b/org/testdata/misc.pretty_org index 08e3c9f..b227d1e 100644 --- a/org/testdata/misc.pretty_org +++ b/org/testdata/misc.pretty_org @@ -140,6 +140,10 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- *** index out of range in explicit line break parsing 0\\ +*** list items don't end on child headline +- a list item +**** followed by a child headline +- followed by another list item * Footnotes [fn:1] a footnote /with/ *markup*