]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
markup/asciidocext: Add Level to Heading struct
authorJoe Mooring <joe.mooring@veriphor.com>
Thu, 21 Mar 2024 17:30:27 +0000 (10:30 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 21 Mar 2024 18:14:49 +0000 (19:14 +0100)
Closes #12291

markup/asciidocext/convert_test.go
markup/asciidocext/internal/converter.go

index 9ccc807f1fefd0b183fae8f5118dd5be23b7195a..18c38a62189d2c45365b56fde2eae8942a4ecef0 100644 (file)
@@ -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\">")
 }
 
index 5108bdd0a80709f660f3fd897cdc0b6c014ad39e..f6ae4136ea396eea31a1c31428f83510529a4c68 100644 (file)
@@ -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)