Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(renderer): support inline formatting in table of contents #1098

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pkg/parser/table_of_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,15 @@ var _ = Describe("tables of contents", func() {
// same titles for all tests in this context
section1Title := []interface{}{
&types.StringElement{
Content: "Section 1",
Content: "Section ",
},
&types.QuotedText{
Kind: types.SingleQuoteBold,
Elements: []interface{}{
&types.StringElement{
Content: "1",
},
},
},
}
section2Title := []interface{}{
Expand All @@ -398,7 +406,7 @@ var _ = Describe("tables of contents", func() {
a preamble
== Section 1
== Section *1*
== Section 2`
expected := &types.Document{
Expand Down Expand Up @@ -472,7 +480,7 @@ a preamble
a preamble
== Section 1
== Section *1*
== Section 2`
expected := &types.Document{
Expand Down Expand Up @@ -555,7 +563,7 @@ block
a preamble
== Section 1
== Section *1*
== Section 2`
expected := &types.Document{
Expand Down Expand Up @@ -627,7 +635,7 @@ a preamble
:toc:
:toc-title: <h3>Table of Contents</h3>
== Section 1
== Section *1*
== Section 2
`
Expand Down Expand Up @@ -712,7 +720,7 @@ a preamble
:toc:
:toc-title: pass:[<h3>Table of Contents</h3>]
== Section 1
== Section *1*
== Section 2
`
Expand Down
3 changes: 2 additions & 1 deletion pkg/renderer/sgml/html5/footnote_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ a preamble with a footnote:[foo]
a paragraph with another footnote:[baz]`

// NOTE: differs from asciidoc in the section and footnote numbering (which also impacts the 'footnotes' portion at the end of the doc)
// also, differs in the rendering of the footnote reference in the table of contents
expected := `<div id="toc" class="toc">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_section_1">section 1 <sup class="footnote">[2]</sup></a></li>
<li><a href="#_section_1">section 1 <sup class="footnote">[<a id="_footnoteref_2" class="footnote" href="#_footnotedef_2" title="View footnote.">2</a>]</sup></a></li>
</ul>
</div>
<div id="preamble">
Expand Down
14 changes: 7 additions & 7 deletions pkg/renderer/sgml/html5/table_of_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("table of contents", func() {
var _ = Describe("tables of contents", func() {

Context("in document with header", func() {

Expand All @@ -21,9 +21,9 @@ A preamble...
== Section A
=== Section A.a
=== Section *A.a*
=== Section A.b
=== Section _A.b_
==== Section that shall not be in ToC
Expand All @@ -38,8 +38,8 @@ A preamble...
<ul class="sectlevel1">
<li><a href="#_section_a">Section A</a>
<ul class="sectlevel2">
<li><a href="#_section_a_a">Section A.a</a></li>
<li><a href="#_section_a_b">Section A.b</a></li>
<li><a href="#_section_a_a">Section <strong>A.a</strong></a></li>
<li><a href="#_section_a_b">Section <em>A.b</em></a></li>
</ul>
</li>
<li><a href="#_section_b">Section B</a>
Expand All @@ -61,10 +61,10 @@ A preamble...
<h2 id="_section_a">Section A</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_section_a_a">Section A.a</h3>
<h3 id="_section_a_a">Section <strong>A.a</strong></h3>
</div>
<div class="sect2">
<h3 id="_section_a_b">Section A.b</h3>
<h3 id="_section_a_b">Section <em>A.b</em></h3>
<div class="sect3">
<h4 id="_section_that_shall_not_be_in_toc">Section that shall not be in ToC</h4>
</div>
Expand Down
17 changes: 13 additions & 4 deletions pkg/renderer/sgml/table_of_contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ func (r *sgmlRenderer) prerenderTableOfContentsEntry(ctx *context, entry *types.
if !found {
return errors.New("unable to render table of contents entry title (missing element reference")
}
title, err := RenderPlainText(s)
if err != nil {
return errors.Wrap(err, "unable to render table of contents entry title (missing element reference")
switch s := s.(type) {
case []interface{}:
title, err := r.renderElements(ctx, s)
if err != nil {
return errors.Wrap(err, "unable to render table of contents entry title (missing element reference")
}
entry.Title = title
default:
title, err := r.renderElement(ctx, s)
if err != nil {
return errors.Wrap(err, "unable to render table of contents entry title (missing element reference")
}
entry.Title = title
}
entry.Title = title
return nil
}

Expand Down