Skip to content

Commit

Permalink
markup/asciidocext: Add Level to Heading struct
Browse files Browse the repository at this point in the history
Closes #12291
  • Loading branch information
jmooring authored and bep committed Mar 21, 2024
1 parent a2f6715 commit c837f36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions markup/asciidocext/convert_test.go
Expand Up @@ -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(
Expand Down Expand Up @@ -301,7 +301,7 @@ func getProvider(c *qt.C, mConfStr string) converter.Provider {
confStr := `
[security]
[security.exec]
allow = ['asciidoctor']
allow = ['asciidoctor']
`
confStr += mConfStr

Expand Down Expand Up @@ -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\">")
}

Expand Down
1 change: 1 addition & 0 deletions markup/asciidocext/internal/converter.go
Expand Up @@ -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)
Expand Down

0 comments on commit c837f36

Please sign in to comment.