diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cee5b6b2e..1c104cf5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,6 +51,7 @@ jobs: run: | gem install asciidoctor -v "2.0.26" gem install asciidoctor-diagram -v "3.1.0" + gem install asciidoctor-html5s -v "0.5.1" - name: Install GoAT run: go install github.com/blampe/goat/cmd/goat@177de93b192b8ffae608e5d9ec421cc99bf68402 - name: Install Python diff --git a/markup/asciidocext/asciidoc_integration_test.go b/markup/asciidocext/asciidoc_integration_test.go index 72fa54569..68a440bb6 100644 --- a/markup/asciidocext/asciidoc_integration_test.go +++ b/markup/asciidocext/asciidoc_integration_test.go @@ -1153,3 +1153,59 @@ func validatePublishedSite_20(b *hugolib.IntegrationTestBuilder) { b.AssertFileExists(path, true) } } + +// See issue 15121 +func TestAsciiDocHTML5BackendTOC(t *testing.T) { + if !htesting.IsRealCI() { + t.Skip() + } + if ok, err := asciidocext.Supports(); !ok { + t.Skip(err) + } + + t.Cleanup(func() { + resetDefaultAsciiDocExtConfig() + }) + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] + +[markup.asciidocExt] + backend = 'html5s' + extensions = ['asciidoctor-html5s'] + +[security.exec] + allow = ['^asciidoctor$'] +-- content/p1.adoc -- +--- +title: p1 +--- + +:toc: + +## Section 1 + +### Section 1.1 + +### Section 1.2 + +## Section 2 +-- layouts/page.html -- +{{ .TableOfContents }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContentExact("public/p1/index.html", ``) +} diff --git a/markup/asciidocext/internal/converter.go b/markup/asciidocext/internal/converter.go index 1cc0dd541..1512609d7 100644 --- a/markup/asciidocext/internal/converter.go +++ b/markup/asciidocext/internal/converter.go @@ -318,7 +318,7 @@ func (a *AsciiDocConverter) extractTOC(src []byte) ([]byte, *tableofcontents.Fra toVisit []*html.Node ) f = func(n *html.Node) bool { - if n.Type == html.ElementNode && n.Data == "div" && attr(n, "id") == "toc" { + if n.Type == html.ElementNode && (n.Data == "div" || n.Data == "nav") && attr(n, "id") == "toc" { toc = parseTOC(n) if !a.Cfg.MarkupConfig().AsciiDocExt.PreserveTOC { n.Parent.RemoveChild(n) @@ -364,7 +364,7 @@ func parseTOC(doc *html.Node) *tableofcontents.Fragments { f = func(n *html.Node, row, level int) { if n.Type == html.ElementNode { switch n.Data { - case "ul": + case "ul", "ol": if level == 0 { row++ }