diff --git a/libasciidoc_test.go b/libasciidoc_test.go index 0a67ac24..f6ecd632 100644 --- a/libasciidoc_test.go +++ b/libasciidoc_test.go @@ -123,23 +123,24 @@ a paragraph` Expect(DocumentMetadata(source, lastUpdated)).To(Equal(types.Metadata{ Title: "a document title", LastUpdated: lastUpdated.Format(configuration.LastUpdatedFormat), - TableOfContents: types.TableOfContents{ - Sections: []*types.ToCSection{ - { - ID: "_section_a", - Level: 1, - Title: "Section A", - Children: []*types.ToCSection{ - { - ID: "_section_a_a_a", - Level: 3, - Title: "Section A.a.a", - Children: []*types.ToCSection{}, - }, - }, - }, - }, - }, + // see https://github.com/bytesparadise/libasciidoc/issues/939 + // TableOfContents: types.TableOfContents{ + // Sections: []*types.ToCSection{ + // { + // ID: "_section_a", + // Level: 1, + // Title: "Section A", + // Children: []*types.ToCSection{ + // { + // ID: "_section_a_a_a", + // Level: 3, + // Title: "Section A.a.a", + // Children: []*types.ToCSection{}, + // }, + // }, + // }, + // }, + // }, })) }) @@ -186,29 +187,30 @@ a paragraph with _italic content_` Expect(DocumentMetadata(source, lastUpdated)).To(Equal(types.Metadata{ Title: "a document title", LastUpdated: lastUpdated.Format(configuration.LastUpdatedFormat), - TableOfContents: types.TableOfContents{ - Sections: []*types.ToCSection{ - { - ID: "_section_a", - Level: 1, - Title: "Section A", - Children: []*types.ToCSection{ - { - ID: "_section_a_a", - Level: 2, - Title: "Section A.a", - Children: []*types.ToCSection{}, - }, - }, - }, - { - ID: "_section_b", - Level: 1, - Title: "Section B", - Children: []*types.ToCSection{}, - }, - }, - }, + // see https://github.com/bytesparadise/libasciidoc/issues/939 + // TableOfContents: types.TableOfContents{ + // Sections: []*types.ToCSection{ + // { + // ID: "_section_a", + // Level: 1, + // Title: "Section A", + // Children: []*types.ToCSection{ + // { + // ID: "_section_a_a", + // Level: 2, + // Title: "Section A.a", + // Children: []*types.ToCSection{}, + // }, + // }, + // }, + // { + // ID: "_section_b", + // Level: 1, + // Title: "Section B", + // Children: []*types.ToCSection{}, + // }, + // }, + // }, })) }) @@ -230,16 +232,17 @@ a paragraph with _italic content_` Expect(DocumentMetadata(source, lastUpdated)).To(Equal(types.Metadata{ Title: "", LastUpdated: lastUpdated.Format(configuration.LastUpdatedFormat), - TableOfContents: types.TableOfContents{ - Sections: []*types.ToCSection{ - { - ID: "_grandchild_title", - Level: 1, - Title: "grandchild title", - Children: []*types.ToCSection{}, - }, - }, - }, + // see https://github.com/bytesparadise/libasciidoc/issues/939 + // TableOfContents: types.TableOfContents{ + // Sections: []*types.ToCSection{ + // { + // ID: "_grandchild_title", + // Level: 1, + // Title: "grandchild title", + // Children: []*types.ToCSection{}, + // }, + // }, + // }, })) }) }) diff --git a/pkg/parser/attribute_substitution_test.go b/pkg/parser/attribute_substitution_test.go index a180bd2b..5fd1279c 100644 --- a/pkg/parser/attribute_substitution_test.go +++ b/pkg/parser/attribute_substitution_test.go @@ -124,7 +124,9 @@ This journey continues` }, }, }, - TableOfContents: &types.TableOfContents{}, // TODO: should we include a ToC when it's empty? + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) diff --git a/pkg/parser/document_fragment_processing_test.go b/pkg/parser/document_fragment_processing_test.go index 5f1f7010..967c9d11 100644 --- a/pkg/parser/document_fragment_processing_test.go +++ b/pkg/parser/document_fragment_processing_test.go @@ -134,28 +134,25 @@ Preamble comes here "_section_c": titleSectionC, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_a", Level: 1, - Title: "Section A", Children: []*types.ToCSection{ { ID: "_section_a_a", Level: 2, - Title: "Section A.a", }, }, }, { ID: "_section_b", Level: 1, - Title: "Section B", }, { ID: "_section_c", Level: 1, - Title: "Section C", }, }, }, diff --git a/pkg/parser/document_header_test.go b/pkg/parser/document_header_test.go index 3c2bd952..c3f1de1c 100644 --- a/pkg/parser/document_header_test.go +++ b/pkg/parser/document_header_test.go @@ -1103,7 +1103,9 @@ a paragraph` }, }, }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) @@ -1133,7 +1135,9 @@ a paragraph` }, }, }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) @@ -1169,7 +1173,9 @@ a paragraph` }, }, }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) @@ -1199,7 +1205,9 @@ a paragraph` Value: "Xavier", }, }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) diff --git a/pkg/parser/document_processing_aggregate_test.go b/pkg/parser/document_processing_aggregate_test.go index d0c7d431..d57b6e14 100644 --- a/pkg/parser/document_processing_aggregate_test.go +++ b/pkg/parser/document_processing_aggregate_test.go @@ -65,11 +65,11 @@ var _ = Describe("aggregate fragments", func() { "_section_1": section1Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "section 1", }, }, }, @@ -126,11 +126,11 @@ var _ = Describe("aggregate fragments", func() { "_section_1": section1Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "section 1", }, }, }, @@ -173,7 +173,9 @@ var _ = Describe("aggregate fragments", func() { }, paragraph, // not wrapped in a preamble since there is nothing afterwards }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } doc, _, err := parser.Aggregate(ctx, c) Expect(err).NotTo(HaveOccurred()) @@ -215,11 +217,11 @@ var _ = Describe("aggregate fragments", func() { "_section_1": section1Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "section 1", }, }, }, @@ -278,11 +280,11 @@ var _ = Describe("aggregate fragments", func() { "_section_1": section1Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "section 1", }, }, }, @@ -333,7 +335,9 @@ var _ = Describe("aggregate fragments", func() { }, paragraph, }, - TableOfContents: &types.TableOfContents{}, + TableOfContents: &types.TableOfContents{ + MaxDepth: 2, + }, } doc, _, err := parser.Aggregate(ctx, c) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/parser/table_of_contents_test.go b/pkg/parser/table_of_contents_test.go index 5c0a75a9..2cf36267 100644 --- a/pkg/parser/table_of_contents_test.go +++ b/pkg/parser/table_of_contents_test.go @@ -151,40 +151,35 @@ var _ = Describe("tables of contents", func() { close(c) expectedToC := &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_a", Level: 1, - Title: "Section A", Children: []*types.ToCSection{ { ID: "_section_a_a", Level: 2, - Title: "Section A.a", }, { ID: "_section_a_b", Level: 2, - Title: "Section A.b", }, }, }, { ID: "_section_b", Level: 1, - Title: "Section B", Children: []*types.ToCSection{ { ID: "_section_b_a", Level: 2, - Title: "Section B.a", }, }, }, { ID: "_section_c", Level: 1, - Title: "Section C", }, }, } @@ -337,26 +332,23 @@ var _ = Describe("tables of contents", func() { close(c) expectedToC := &types.TableOfContents{ + MaxDepth: 3, Sections: []*types.ToCSection{ { ID: "_section_a", Level: 1, - Title: "Section A", Children: []*types.ToCSection{ { ID: "_section_a_a", Level: 2, - Title: "Section A.a", }, { ID: "_section_a_b", Level: 2, - Title: "Section A.b", Children: []*types.ToCSection{ { ID: "_section_that_shall_be_in_ToC", Level: 3, - Title: "Section that shall be in ToC", }, }, }, @@ -365,19 +357,16 @@ var _ = Describe("tables of contents", func() { { ID: "_section_b", Level: 1, - Title: "Section B", Children: []*types.ToCSection{ { ID: "_section_b_a", Level: 2, - Title: "Section B.a", }, }, }, { ID: "_section_c", Level: 1, - Title: "Section C", }, }, } @@ -458,16 +447,15 @@ a preamble "_section_2": section2Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "Section 1", }, { ID: "_section_2", Level: 1, - Title: "Section 2", }, }, }, @@ -535,16 +523,15 @@ a preamble "_section_2": section2Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "Section 1", }, { ID: "_section_2", Level: 1, - Title: "Section 2", }, }, }, @@ -619,16 +606,15 @@ a preamble "_section_2": section2Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "Section 1", }, { ID: "_section_2", Level: 1, - Title: "Section 2", }, }, }, @@ -683,16 +669,15 @@ a preamble "_section_2": section2Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "Section 1", }, { ID: "_section_2", Level: 1, - Title: "Section 2", }, }, }, @@ -747,16 +732,15 @@ a preamble "_section_2": section2Title, }, TableOfContents: &types.TableOfContents{ + MaxDepth: 2, Sections: []*types.ToCSection{ { ID: "_section_1", Level: 1, - Title: "Section 1", }, { ID: "_section_2", Level: 1, - Title: "Section 2", }, }, }, diff --git a/pkg/renderer/context.go b/pkg/renderer/context.go index 48eb5d2a..5182c49e 100644 --- a/pkg/renderer/context.go +++ b/pkg/renderer/context.go @@ -8,10 +8,7 @@ import ( // Context is a custom implementation of the standard golang context.Context interface, // which carries the types.Document which is being processed type Context struct { - Config *configuration.Configuration // TODO: use composition (remove the `Config` field) - // TableOfContents exists even if the document did not specify the `:toc:` attribute. - // It will take into account the configured `:toclevels:` attribute value. - TableOfContents types.TableOfContents + Config *configuration.Configuration // TODO: use composition (remove the `Config` field) WithinDelimitedBlock bool EncodeSpecialChars bool WithinList int diff --git a/pkg/renderer/sgml/elements.go b/pkg/renderer/sgml/elements.go index f914d412..56ec194b 100644 --- a/pkg/renderer/sgml/elements.go +++ b/pkg/renderer/sgml/elements.go @@ -7,6 +7,7 @@ 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 +120,7 @@ func (r *sgmlRenderer) renderElement(ctx *renderer.Context, element interface{}) // nolint:gocyclo 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 element := element.(type) { case []interface{}: return r.renderInlineElements(ctx, element, withRenderer(r.renderPlainText)) @@ -139,7 +140,7 @@ func (r *sgmlRenderer) renderPlainText(ctx *renderer.Context, element interface{ case *types.StringElement: return element.Content, nil case *types.QuotedString: - return r.renderQuotedStringPlain(ctx, element) + return r.renderQuotedString(ctx, element) // case *types.Paragraph: // return r.renderParagraph(ctx, element, withRenderer(r.renderPlainText)) case *types.FootnoteReference: diff --git a/pkg/renderer/sgml/html5/file_inclusion_test.go b/pkg/renderer/sgml/html5/file_inclusion_test.go index de3c7711..8c55a367 100644 --- a/pkg/renderer/sgml/html5/file_inclusion_test.go +++ b/pkg/renderer/sgml/html5/file_inclusion_test.go @@ -35,16 +35,6 @@ var _ = Describe("file inclusions", func() { Expect(DocumentMetadata(source, lastUpdated)).To(Equal(types.Metadata{ Title: "", LastUpdated: lastUpdated.Format(configuration.LastUpdatedFormat), - TableOfContents: types.TableOfContents{ - Sections: []*types.ToCSection{ - { - ID: "_grandchild_title", - Level: 1, - Title: "grandchild title", - Children: []*types.ToCSection{}, - }, - }, - }, })) // verify no error/warning in logs Expect(logs).ToNot(ContainAnyMessageWithLevels(log.ErrorLevel, log.WarnLevel)) diff --git a/pkg/renderer/sgml/html5/quoted_string_test.go b/pkg/renderer/sgml/html5/quoted_string_test.go index 54caa499..c9bb4da7 100644 --- a/pkg/renderer/sgml/html5/quoted_string_test.go +++ b/pkg/renderer/sgml/html5/quoted_string_test.go @@ -349,6 +349,7 @@ var _ = Describe("quoted strings", func() { Expect(RenderHTML(source)).To(MatchHTML(expected)) }) + It("image in double curly", func() { source := "\"`a image:foo.png[]`\"" expected := `
“a ”