Skip to content

Commit

Permalink
fix(renderer): smart quotes in table of contents (#943)
Browse files Browse the repository at this point in the history
also: remove renderer.Context.TableOfContents

BREAKING CHANGES:
- `types.Metadata.TableOfContents` is `*types.TableOfContents` (pointer)
- `types.TableOfContents.MaxDepth` field exported

Fixes #937

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Feb 18, 2022
1 parent e0902fb commit f6cd546
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 249 deletions.
103 changes: 53 additions & 50 deletions libasciidoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
// },
// },
// },
// },
// },
}))
})

Expand Down Expand Up @@ -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{},
// },
// },
// },
}))
})

Expand All @@ -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{},
// },
// },
// },
}))
})
})
Expand Down
4 changes: 3 additions & 1 deletion pkg/parser/attribute_substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
5 changes: 1 addition & 4 deletions pkg/parser/document_fragment_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down
16 changes: 12 additions & 4 deletions pkg/parser/document_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ a paragraph`
},
},
},
TableOfContents: &types.TableOfContents{},
TableOfContents: &types.TableOfContents{
MaxDepth: 2,
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
Expand Down Expand Up @@ -1133,7 +1135,9 @@ a paragraph`
},
},
},
TableOfContents: &types.TableOfContents{},
TableOfContents: &types.TableOfContents{
MaxDepth: 2,
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
Expand Down Expand Up @@ -1169,7 +1173,9 @@ a paragraph`
},
},
},
TableOfContents: &types.TableOfContents{},
TableOfContents: &types.TableOfContents{
MaxDepth: 2,
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
Expand Down Expand Up @@ -1199,7 +1205,9 @@ a paragraph`
Value: "Xavier",
},
},
TableOfContents: &types.TableOfContents{},
TableOfContents: &types.TableOfContents{
MaxDepth: 2,
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
Expand Down
16 changes: 10 additions & 6 deletions pkg/parser/document_processing_aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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())
Expand Down
Loading

0 comments on commit f6cd546

Please sign in to comment.