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

fix(renderer): section numbering disabled and re-enabled #1040

Merged
merged 1 commit into from
Jun 11, 2022
Merged
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
2 changes: 1 addition & 1 deletion pkg/renderer/context.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ type Context struct {
Attributes types.Attributes
ElementReferences types.ElementReferences
HasHeader bool
SectionNumbering SectionNumbers
SectionNumbering types.SectionNumbers
}

// NewContext returns a new rendering context for the given document.
42 changes: 0 additions & 42 deletions pkg/renderer/section_numbering.go

This file was deleted.

47 changes: 0 additions & 47 deletions pkg/renderer/section_numbering_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/renderer/sgml/elements.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"github.com/bytesparadise/libasciidoc/pkg/types"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

func (r *sgmlRenderer) renderElements(ctx *renderer.Context, elements []interface{}) (string, error) {
@@ -119,7 +118,7 @@ func (r *sgmlRenderer) renderElement(ctx *renderer.Context, element interface{})
}

func (r *sgmlRenderer) renderPlainText(ctx *renderer.Context, element interface{}) (string, error) {
log.Debugf("rendering plain string for element of type %T", element)
// log.Debugf("rendering plain string for element of type %T", element)
switch e := element.(type) {
case []interface{}:
return r.renderInlineElements(ctx, e, withRenderer(r.renderPlainText))
60 changes: 59 additions & 1 deletion pkg/renderer/sgml/html5/section_test.go
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ var _ = Describe("sections", func() {
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("with numbering", func() {
It("with numbering always enabled", func() {
source := `= A title
:sectnums:

@@ -198,6 +198,64 @@ var _ = Describe("sections", func() {
<div class="sectionbody">
</div>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("with numbering disabled and enabled again", func() {
source := `= A title
:sectnums!:

== Disclaimer

:sectnums:

== Section A

=== Section A.a

=== Section A.b

==== Section that shall not be in ToC

== Section B

=== Section B.a

== Section C`

expected := `<div class="sect1">
<h2 id="_disclaimer">Disclaimer</h2>
<div class="sectionbody">
</div>
</div>
<div class="sect1">
<h2 id="_section_a">1. Section A</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_section_a_a">1.1. Section A.a</h3>
</div>
<div class="sect2">
<h3 id="_section_a_b">1.2. Section A.b</h3>
<div class="sect3">
<h4 id="_section_that_shall_not_be_in_toc">1.2.1. Section that shall not be in ToC</h4>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_section_b">2. Section B</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_section_b_a">2.1. Section B.a</h3>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_section_c">3. Section C</h2>
<div class="sectionbody">
</div>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})
7 changes: 3 additions & 4 deletions pkg/renderer/sgml/inline_elements.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (

"github.com/bytesparadise/libasciidoc/pkg/renderer"
"github.com/bytesparadise/libasciidoc/pkg/types"
log "github.com/sirupsen/logrus"
)

func (r *sgmlRenderer) renderInlineElements(ctx *renderer.Context, elements []interface{}, options ...lineRendererOption) (string, error) {
@@ -32,9 +31,9 @@ func (r *sgmlRenderer) renderInlineElements(ctx *renderer.Context, elements []in
buf.WriteString(renderedElement)
}
}
if log.IsLevelEnabled(log.DebugLevel) {
log.Debugf("rendered inline elements: '%s'", buf.String())
}
// if log.IsLevelEnabled(log.DebugLevel) {
// log.Debugf("rendered inline elements: '%s'", buf.String())
// }
return buf.String(), nil
}

9 changes: 2 additions & 7 deletions pkg/renderer/sgml/renderer.go
Original file line number Diff line number Diff line change
@@ -172,13 +172,8 @@ func (r *sgmlRenderer) Render(ctx *renderer.Context, doc *types.Document, output
}
}
}
if ctx.Attributes.Has(types.AttrSectionNumbering) || ctx.Attributes.Has(types.AttrNumbered) {
var err error
if ctx.SectionNumbering, err = renderer.NewSectionNumbers(doc); err != nil {
return metadata, errors.Wrapf(err, "unable to render full document")
}
} else {
log.Debug("section numbering is not enabled")
if ctx.SectionNumbering, err = doc.SectionNumbers(); err != nil {
return metadata, errors.Wrapf(err, "unable to render full document")
}

// needs to be set before rendering the content elements
Loading