Skip to content

Commit

Permalink
feat(renderer): support predefined attributes
Browse files Browse the repository at this point in the history
use `sp`, `blanck`, etc. attributes during rendering
unless they have been explicitly declared in the
document.

fixes bytesparadise#266

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jan 26, 2019
1 parent f94e69a commit dfd4d2a
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 130 deletions.
4 changes: 2 additions & 2 deletions pkg/parser/blank_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = Describe("Blank lines", func() {
second paragraph`
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -46,7 +46,7 @@ second paragraph
`
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ with multiple lines
a second paragraph`
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/cross_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("cross-references", func() {
with some content linked to <<thetitle>>!`
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{
ElementReferences: types.ElementReferences{
"thetitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
Expand Down Expand Up @@ -77,7 +77,7 @@ with some content linked to <<thetitle>>!`
with some content linked to <<thetitle,a label to the title>>!`
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{
ElementReferences: types.ElementReferences{
"thetitle": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "thetitle",
Expand Down
16 changes: 8 additions & 8 deletions pkg/parser/delimited_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = Describe("delimited blocks", func() {
actualContent := "```\nsome fenced code\nwith an empty line\n\nin the middle\n```\nthen a normal paragraph."
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("delimited blocks", func() {
actualContent := "a paragraph.\n```\n" + content + "\n```\n"
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -309,8 +309,8 @@ in the middle
----
then a normal paragraph.`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -360,8 +360,8 @@ then a normal paragraph.`
some listing code
----`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -631,8 +631,8 @@ paragraphs
----
`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
42 changes: 21 additions & 21 deletions pkg/parser/document_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This journey begins on a bleary Monday morning.`
},
},
},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -507,8 +507,8 @@ v1.0:`
:0Author: Xavier
:Auth0r: Xavier`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand All @@ -530,8 +530,8 @@ v1.0:`
:hardbreaks:
a paragraph`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -559,8 +559,8 @@ a paragraph`
a paragraph`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -591,8 +591,8 @@ a paragraph`
a paragraph`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -623,8 +623,8 @@ a paragraph`
:date: 2017-01-01
:author: Xavier`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -653,8 +653,8 @@ a paragraph`
a paragraph written by {author}.`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -682,8 +682,8 @@ a paragraph written by {author}.`
:author2!:
a paragraph written by {author}.`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -742,7 +742,7 @@ This journey begins on a bleary Monday morning.`
"keywords": "documentation, team, obstacles, journey, victory",
"toc": "",
},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -779,7 +779,7 @@ a paragraph with *bold content*`
},
},
},
ElementReferences: map[string]interface{}{
ElementReferences: types.ElementReferences{
"_section_1": types.SectionTitle{
Attributes: types.ElementAttributes{
types.AttrID: "_section_1",
Expand Down Expand Up @@ -834,8 +834,8 @@ a paragraph with *bold content*`
:date: 2017-01-01
:author: Xavier`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -865,8 +865,8 @@ a paragraph with *bold content*`
actualContent := `:@date: 2017-01-01
:{author}: Xavier`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
14 changes: 7 additions & 7 deletions pkg/parser/footnote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("footnotes", func() {
}
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: []types.Footnote{
footnote1,
},
Expand Down Expand Up @@ -79,7 +79,7 @@ var _ = Describe("footnotes", func() {
}
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: []types.Footnote{
footnote1,
},
Expand Down Expand Up @@ -113,7 +113,7 @@ var _ = Describe("footnotes", func() {
}
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: []types.Footnote{
footnote1,
},
Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = Describe("footnotes", func() {
// }
// expectedResult := types.Document{
// Attributes: types.DocumentAttributes{},
// ElementReferences: map[string]interface{}{},
// ElementReferences: types.ElementReferences{},
// Footnotes: types.Footnotes{
// footnote1,
// },
Expand Down Expand Up @@ -193,7 +193,7 @@ var _ = Describe("footnotes", func() {
}
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{
footnote1,
},
Expand Down Expand Up @@ -245,7 +245,7 @@ var _ = Describe("footnotes", func() {
}
expectedResult := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{
footnote1,
},
Expand Down Expand Up @@ -335,7 +335,7 @@ a paragraph with another footnote:[baz]`
Attributes: types.DocumentAttributes{
"doctitle": docTitle,
},
ElementReferences: map[string]interface{}{
ElementReferences: types.ElementReferences{
"_section_1": section1Title,
},
Footnotes: types.Footnotes{
Expand Down
6 changes: 3 additions & 3 deletions pkg/parser/frontmatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ first paragraph`
"title": "a title", // TODO: convert `title` attribute from front-matter into `doctitle` here ?
"author": "Xavier",
},
ElementReferences: map[string]interface{}{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand All @@ -44,8 +44,8 @@ first paragraph`
first paragraph`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ image::appa.png[]`
It("paragraph with block image with alt and dimensions", func() {
actualContent := "a foo image::foo.png[foo image, 600, 400] bar"
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
24 changes: 12 additions & 12 deletions pkg/parser/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ bar
a normal paragraph.`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -364,8 +364,8 @@ Item 2:: something simple
another fenced block
----`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -444,8 +444,8 @@ Item 2:: something simple
another fenced block
----`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -2048,8 +2048,8 @@ on 2 lines, too.`
"\n" +
"* an item in the second list"
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -2391,8 +2391,8 @@ another delimited block
* bar
`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down Expand Up @@ -2480,8 +2480,8 @@ a delimited block
another delimited block
----`
expectedResult := types.Document{
Attributes: map[string]interface{}{},
ElementReferences: map[string]interface{}{},
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
Expand Down
Loading

0 comments on commit dfd4d2a

Please sign in to comment.