From 7bc6100fc7573641b5a026a6f8dc814758aeb23f Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Tue, 20 Aug 2024 15:22:59 +0200 Subject: [PATCH] Do not include excluded headlines when calculating headline index --- org/document.go | 4 +++- org/headline.go | 5 +---- org/testdata/headlines.html | 32 ++++++++++++++++---------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/org/document.go b/org/document.go index 8dba04f..b9435d1 100644 --- a/org/document.go +++ b/org/document.go @@ -260,7 +260,9 @@ func (d *Document) parseMany(i int, stop stopFn) (int, []Node) { func (d *Document) addHeadline(headline *Headline) int { current := &Section{Headline: headline} d.Outline.last.add(current) - d.Outline.count++ + if !headline.IsExcluded(d) { + d.Outline.count++ + } d.Outline.last = current return d.Outline.count } diff --git a/org/headline.go b/org/headline.go index f9a77c7..beb772b 100644 --- a/org/headline.go +++ b/org/headline.go @@ -43,9 +43,6 @@ func lexHeadline(line string) (token, bool) { func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { t, headline := d.tokens[i], Headline{} headline.Lvl = len(t.matches[1]) - - headline.Index = d.addHeadline(&headline) - text := t.content todoKeywords := trimFastTags( strings.FieldsFunc(d.Get("TODO"), func(r rune) bool { return unicode.IsSpace(r) || r == '|' }), @@ -67,7 +64,7 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { text = m[1] headline.Tags = strings.FieldsFunc(m[2], func(r rune) bool { return r == ':' }) } - + headline.Index = d.addHeadline(&headline) headline.Title = d.parseInline(text) stop := func(d *Document, i int) bool { diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index e598777..ce09dc1 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -10,9 +10,9 @@
  • headline with custom status
  • -
  • malformed property drawer +
  • malformed property drawer
  • -
  • level limit for headlines to be included in the table of contents +
  • level limit for headlines to be included in the table of contents
  • @@ -75,40 +75,40 @@ headline with custom status -
    -

    +
    +

    malformed property drawer

    -
    +

    :PROPERTIES: not a property

    :END:

    -
    -

    +
    +

    level limit for headlines to be included in the table of contents

    -
    +

    The toc option allows setting a level limit. For this file we set it to 1 - which means that the following headlines won't be included in the table of contents.

    -
    -

    +
    +

    headline 2 not in toc

    -
    -
    -

    +
    +
    +

    headline 3 not in toc

    -
    -

    +
    +

    anoter headline 2 not in toc

    -
    +

    you get the gist…