From 4c804319f6db0b8459cc9b5df4a904fd2c55dedd Mon Sep 17 00:00:00 2001 From: "Gavin D. Howard" Date: Wed, 11 Dec 2019 23:48:40 -0700 Subject: [PATCH] markup/tableofcontents: Add config option for ordered list --- .../getting-started/configuration-markup.md | 5 +- docs/data/docs.json | 3 +- hugolib/page__per_output.go | 2 +- markup/goldmark/toc_test.go | 2 +- markup/tableofcontents/tableofcontents.go | 20 ++++++-- .../tableofcontents/tableofcontents_test.go | 49 ++++++++++++++++--- 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/docs/content/en/getting-started/configuration-markup.md b/docs/content/en/getting-started/configuration-markup.md index 2a24fcdd..ff009502 100644 --- a/docs/content/en/getting-started/configuration-markup.md +++ b/docs/content/en/getting-started/configuration-markup.md @@ -70,4 +70,7 @@ startLevel : The heading level, values starting at 1 (`h1`), to start render the table of contents. endLevel -: The heading level, inclusive, to stop render the table of contents. \ No newline at end of file +: The heading level, inclusive, to stop render the table of contents. + +ordered +: Whether or not to generate an ordered list instead of an unordered list. diff --git a/docs/data/docs.json b/docs/data/docs.json index 0944ab88..dea7f0bc 100644 --- a/docs/data/docs.json +++ b/docs/data/docs.json @@ -1387,7 +1387,8 @@ }, "tableOfContents": { "startLevel": 2, - "endLevel": 3 + "endLevel": 3, + "ordered": false }, "goldmark": { "renderer": { diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index bc2a0acc..9697468f 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -292,7 +292,7 @@ func (p *pageContentOutput) TableOfContents() template.HTML { p.p.s.initInit(p.initMain, p.p) if tocProvider, ok := p.convertedResult.(converter.TableOfContentsProvider); ok { cfg := p.p.s.ContentSpec.Converters.GetMarkupConfig() - return template.HTML(tocProvider.TableOfContents().ToHTML(cfg.TableOfContents.StartLevel, cfg.TableOfContents.EndLevel)) + return template.HTML(tocProvider.TableOfContents().ToHTML(cfg.TableOfContents.StartLevel, cfg.TableOfContents.EndLevel, cfg.TableOfContents.Ordered)) } return p.tableOfContents } diff --git a/markup/goldmark/toc_test.go b/markup/goldmark/toc_test.go index d3a1613c..19928dd8 100644 --- a/markup/goldmark/toc_test.go +++ b/markup/goldmark/toc_test.go @@ -58,7 +58,7 @@ And then some. c.Assert(err, qt.IsNil) b, err := conv.Convert(converter.RenderContext{Src: []byte(content), RenderTOC: true}) c.Assert(err, qt.IsNil) - got := b.(converter.TableOfContentsProvider).TableOfContents().ToHTML(2, 3) + got := b.(converter.TableOfContentsProvider).TableOfContents().ToHTML(2, 3, false) c.Assert(got, qt.Equals, `