diff options
author | Joe Mooring <[email protected]> | 2024-03-21 10:30:27 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-21 19:14:49 +0100 |
commit | c837f36ab4f1bef581d67a115906556ac16473dc (patch) | |
tree | 98b9dbaf6c8c3eec64a84100829b437f19cc5cfd | |
parent | a2f67152b3cad093361312b0080a66040db4ba60 (diff) | |
download | hugo-c837f36ab4f1bef581d67a115906556ac16473dc.tar.gz hugo-c837f36ab4f1bef581d67a115906556ac16473dc.zip |
markup/asciidocext: Add Level to Heading struct
Closes #12291
-rw-r--r-- | markup/asciidocext/convert_test.go | 11 | ||||
-rw-r--r-- | markup/asciidocext/internal/converter.go | 1 |
2 files changed, 10 insertions, 2 deletions
diff --git a/markup/asciidocext/convert_test.go b/markup/asciidocext/convert_test.go index 9ccc807f1..18c38a621 100644 --- a/markup/asciidocext/convert_test.go +++ b/markup/asciidocext/convert_test.go @@ -266,7 +266,7 @@ func TestAsciidoctorAttributes(t *testing.T) { trace = false [markup.asciidocext.attributes] my-base-url = "https://gohugo.io/" -my-attribute-name = "my value" +my-attribute-name = "my value" `) conf := testconfig.GetTestConfig(nil, cfg) p, err := asciidocext.Provider.New( @@ -301,7 +301,7 @@ func getProvider(c *qt.C, mConfStr string) converter.Provider { confStr := ` [security] [security.exec] -allow = ['asciidoctor'] +allow = ['asciidoctor'] ` confStr += mConfStr @@ -368,6 +368,13 @@ testContent c.Assert(ok, qt.Equals, true) c.Assert(toc.TableOfContents().Identifiers, qt.DeepEquals, collections.SortedStringSlice{"_introduction", "_section_1", "_section_1_1", "_section_1_1_1", "_section_1_2", "_section_2"}) + // Although "Introduction" has a level 3 markup heading, AsciiDoc treats the first heading as level 2. + c.Assert(toc.TableOfContents().HeadingsMap["_introduction"].Level, qt.Equals, 2) + c.Assert(toc.TableOfContents().HeadingsMap["_section_1"].Level, qt.Equals, 2) + c.Assert(toc.TableOfContents().HeadingsMap["_section_1_1"].Level, qt.Equals, 3) + c.Assert(toc.TableOfContents().HeadingsMap["_section_1_1_1"].Level, qt.Equals, 4) + c.Assert(toc.TableOfContents().HeadingsMap["_section_1_2"].Level, qt.Equals, 3) + c.Assert(toc.TableOfContents().HeadingsMap["_section_2"].Level, qt.Equals, 2) c.Assert(string(r.Bytes()), qt.Not(qt.Contains), "<div id=\"toc\" class=\"toc\">") } diff --git a/markup/asciidocext/internal/converter.go b/markup/asciidocext/internal/converter.go index 5108bdd0a..f6ae4136e 100644 --- a/markup/asciidocext/internal/converter.go +++ b/markup/asciidocext/internal/converter.go @@ -243,6 +243,7 @@ func parseTOC(doc *html.Node) *tableofcontents.Fragments { toc.AddAt(&tableofcontents.Heading{ Title: nodeContent(c), ID: href, + Level: level + 1, }, row, level) } f(n.FirstChild, row, level) |