diff --git a/org/document.go b/org/document.go index b9b82bf..acdd5c4 100644 --- a/org/document.go +++ b/org/document.go @@ -169,7 +169,7 @@ func (d *Document) Get(key string) string { // - < (export timestamps) // - e (export org entities) // - f (export footnotes) -// - toc (export table of content) +// - toc (export table of content. an int limits the included org headline lvl) // - todo (export headline todo status) // - pri (export headline priority) // - tags (export headline tags) diff --git a/org/html_writer.go b/org/html_writer.go index a170184..0c830de 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -5,6 +5,7 @@ import ( "html" "log" "regexp" + "strconv" "strings" "unicode" @@ -184,24 +185,32 @@ func (w *HTMLWriter) WriteFootnotes(d *Document) { func (w *HTMLWriter) WriteOutline(d *Document) { if w.document.GetOption("toc") != "nil" && len(d.Outline.Children) != 0 { + maxLvl, _ := strconv.Atoi(w.document.GetOption("toc")) w.WriteString("\n") } } -func (w *HTMLWriter) writeSection(section *Section) { +func (w *HTMLWriter) writeSection(section *Section, maxLvl int) { + if maxLvl != 0 && section.Headline.Lvl > maxLvl { + return + } // NOTE: To satisfy hugo ExtractTOC() check we cannot use `
:END:
++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. +
++you get the gist… +
diff --git a/org/testdata/headlines.org b/org/testdata/headlines.org index 1cbf9b8..17c08e3 100644 --- a/org/testdata/headlines.org +++ b/org/testdata/headlines.org @@ -1,4 +1,5 @@ #+SETUPFILE: setup_file_org +#+OPTIONS: toc:1 * Simple Headline [1/2] - [X] checked - [ ] unchecked @@ -31,3 +32,10 @@ By default =EXCLUDE_TAGS= is just =:noexport:=. :PROPERTIES: not a property :END: +* level limit for headlines to be included in the table of contents +The toc option allows setting a [[https://orgmode.org/manual/Export-settings.html][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... diff --git a/org/testdata/headlines.pretty_org b/org/testdata/headlines.pretty_org index 7fb00bd..5c6c940 100644 --- a/org/testdata/headlines.pretty_org +++ b/org/testdata/headlines.pretty_org @@ -1,4 +1,5 @@ #+SETUPFILE: setup_file_org +#+OPTIONS: toc:1 * Simple Headline [1/2] - [X] checked - [ ] unchecked @@ -31,3 +32,10 @@ By default =EXCLUDE_TAGS= is just =:noexport:=. :PROPERTIES: not a property :END: +* level limit for headlines to be included in the table of contents +The toc option allows setting a [[https://orgmode.org/manual/Export-settings.html][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... diff --git a/org/testdata/misc.html b/org/testdata/misc.html index b56dbb1..242bf7c 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -131,6 +131,7 @@ src block
#+SETUPFILE: setup_file_org
+#+OPTIONS: toc:1
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
@@ -163,6 +164,13 @@ By default =EXCLUDE_TAGS= is just =:noexport:=.
:PROPERTIES:
not a property
:END:
+* level limit for headlines to be included in the table of contents
+The toc option allows setting a [[https://orgmode.org/manual/Export-settings.html][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...