-
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 admonitions (#70)
support admonition paragraphs and blocks (ie, "masquerade" on paragraph) Fixes #67 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
13 changed files
with
2,865 additions
and
2,278 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package parser_test | ||
|
||
import ( | ||
"github.com/bytesparadise/libasciidoc/parser" | ||
"github.com/bytesparadise/libasciidoc/types" | ||
. "github.com/onsi/ginkgo" | ||
) | ||
|
||
var _ = Describe("admonitions", func() { | ||
|
||
Context("admonition paragraphs", func() { | ||
It("note admonition paragraph", func() { | ||
actualContent := `NOTE: this is a note.` | ||
expectedResult := &types.Admonition{ | ||
Kind: types.Note, | ||
Content: &types.AdmonitionParagraph{ | ||
Lines: []*types.InlineContent{ | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "this is a note.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("BlockElement")) | ||
}) | ||
|
||
It("warning admonition paragraph", func() { | ||
actualContent := `WARNING: this is a multiline | ||
warning!` | ||
expectedResult := &types.Admonition{ | ||
Kind: types.Warning, | ||
Content: &types.AdmonitionParagraph{ | ||
Lines: []*types.InlineContent{ | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "this is a multiline", | ||
}, | ||
}, | ||
}, | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "warning!", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("BlockElement")) | ||
}) | ||
|
||
It("admonition note paragraph with id and title", func() { | ||
actualContent := `[[foo]] | ||
.bar | ||
NOTE: this is a note.` | ||
expectedResult := &types.Admonition{ | ||
ID: &types.ElementID{ | ||
Value: "foo", | ||
}, | ||
Title: &types.ElementTitle{ | ||
Value: "bar", | ||
}, | ||
Kind: types.Note, | ||
Content: &types.AdmonitionParagraph{ | ||
Lines: []*types.InlineContent{ | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "this is a note.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("BlockElement")) | ||
}) | ||
}) | ||
|
||
Context("admonition blocks", func() { | ||
It("caution admonition block", func() { | ||
actualContent := `[CAUTION] | ||
this is a caution!` | ||
expectedResult := &types.Admonition{ | ||
Kind: types.Caution, | ||
Content: &types.AdmonitionParagraph{ | ||
Lines: []*types.InlineContent{ | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "this is a caution!", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("BlockElement")) | ||
}) | ||
|
||
It("multiline caution admonition block with title and id", func() { | ||
actualContent := `[[foo]] | ||
[CAUTION] | ||
.bar | ||
this is a | ||
*caution*!` | ||
expectedResult := &types.Admonition{ | ||
ID: &types.ElementID{ | ||
Value: "foo", | ||
}, | ||
Title: &types.ElementTitle{ | ||
Value: "bar", | ||
}, | ||
Kind: types.Caution, | ||
Content: &types.AdmonitionParagraph{ | ||
Lines: []*types.InlineContent{ | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "this is a ", | ||
}, | ||
}, | ||
}, | ||
{ | ||
Elements: []types.InlineElement{ | ||
&types.QuotedText{ | ||
Kind: types.Bold, | ||
Elements: []types.InlineElement{ | ||
&types.StringElement{ | ||
Content: "caution", | ||
}, | ||
}, | ||
}, | ||
&types.StringElement{ | ||
Content: "!", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
verify(GinkgoT(), expectedResult, actualContent, parser.Entrypoint("BlockElement")) | ||
}) | ||
}) | ||
|
||
}) |
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
Oops, something went wrong.