-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser/renderer): support for document attributes (#22)
Support document attribute in the form: ":name: value" or ":name:" at any location in the document. For now, document attributes are silently ignored during rendering. Rename "Metadata" -> "Attributes" for document and elements. Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
20 changed files
with
465 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
package parser_test | ||
|
||
import ( | ||
"github.com/bytesparadise/libasciidoc/types" | ||
. "github.com/onsi/ginkgo" | ||
) | ||
|
||
var _ = Describe("Parsing Document Attributes", func() { | ||
|
||
Context("Valid document attributes", func() { | ||
|
||
It("heading section with attributes", func() { | ||
|
||
actualContent := `= a heading | ||
:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier | ||
a paragraph` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{ | ||
"title": "a heading", | ||
}, | ||
Elements: []types.DocElement{ | ||
&types.Section{ | ||
Heading: types.Heading{ | ||
Level: 1, | ||
Content: &types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a heading"}, | ||
}, | ||
}, | ||
ID: &types.ElementID{ | ||
Value: "_a_heading", | ||
}, | ||
}, | ||
Elements: []types.DocElement{ | ||
&types.DocumentAttribute{Name: "toc"}, | ||
&types.DocumentAttribute{Name: "date", Value: "2017-01-01"}, | ||
&types.DocumentAttribute{Name: "author", Value: "Xavier"}, | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
|
||
It("attributes and paragraph without blank line in-between", func() { | ||
|
||
actualContent := `:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier | ||
a paragraph` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{}, | ||
Elements: []types.DocElement{ | ||
&types.DocumentAttribute{Name: "toc"}, | ||
&types.DocumentAttribute{Name: "date", Value: "2017-01-01"}, | ||
&types.DocumentAttribute{Name: "author", Value: "Xavier"}, | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
|
||
It("contiguous attributes and paragraph with blank line in-between", func() { | ||
|
||
actualContent := `:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier | ||
a paragraph` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{}, | ||
Elements: []types.DocElement{ | ||
&types.DocumentAttribute{Name: "toc"}, | ||
&types.DocumentAttribute{Name: "date", Value: "2017-01-01"}, | ||
&types.DocumentAttribute{Name: "author", Value: "Xavier"}, | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
|
||
It("splitted attributes and paragraph with blank line in-between", func() { | ||
|
||
actualContent := `:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier | ||
a paragraph` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{}, | ||
Elements: []types.DocElement{ | ||
&types.DocumentAttribute{Name: "toc"}, | ||
&types.DocumentAttribute{Name: "date", Value: "2017-01-01"}, | ||
&types.DocumentAttribute{Name: "author", Value: "Xavier"}, | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
|
||
It("no heading and attributes in body", func() { | ||
|
||
actualContent := `a paragraph | ||
:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{}, | ||
Elements: []types.DocElement{ | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&types.DocumentAttribute{Name: "toc"}, | ||
&types.DocumentAttribute{Name: "date", Value: "2017-01-01"}, | ||
&types.DocumentAttribute{Name: "author", Value: "Xavier"}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
}) | ||
|
||
Context("Valid document attributes", func() { | ||
It("paragraph and without blank line in between", func() { | ||
|
||
actualContent := `a paragraph | ||
:toc: | ||
:date: 2017-01-01 | ||
:author: Xavier` | ||
expectedDocument := &types.Document{ | ||
Attributes: &types.DocumentAttributes{}, | ||
Elements: []types.DocElement{ | ||
&types.Paragraph{ | ||
Lines: []*types.InlineContent{ | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: "a paragraph"}, | ||
}, | ||
}, | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: ":toc:"}, | ||
}, | ||
}, | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: ":date: 2017-01-01"}, | ||
}, | ||
}, | ||
&types.InlineContent{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{Content: ":author: Xavier"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedDocument, actualContent) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.