Skip to content

Commit

Permalink
feat(parser): support custom substitutions on literal blocks
Browse files Browse the repository at this point in the history
also, fixes the default substitutions

Fixes bytesparadise#770

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Oct 13, 2020
1 parent 68a9843 commit f455f72
Show file tree
Hide file tree
Showing 5 changed files with 675 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/parser/delimited_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ and <more text> on the +
`

It("should apply the default substitution", func() {
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]", "")
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]\n", "")
expected := types.DraftDocument{
Attributes: types.Attributes{
"github-url": "https://github.com",
Expand All @@ -592,7 +592,6 @@ and <more text> on the +
Value: "https://github.com",
},
types.BlankLine{},
types.BlankLine{},
types.ExampleBlock{
Elements: []interface{}{
types.Paragraph{
Expand Down Expand Up @@ -2734,7 +2733,7 @@ another paragraph`
// share the same implementation

source := `:github-url: https://github.com
[subs="$SUBS"]
----
a link to https://example.com[] <1>
Expand All @@ -2748,7 +2747,7 @@ and <more text> on the +
`

It("should apply the default substitution", func() {
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]", "")
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]\n", "") // remove the 'subs' attribute
expected := types.DraftDocument{
Attributes: types.Attributes{
"github-url": "https://github.com",
Expand All @@ -2759,7 +2758,6 @@ and <more text> on the +
Value: "https://github.com",
},
types.BlankLine{},
types.BlankLine{},
types.ListingBlock{
Lines: [][]interface{}{
{
Expand Down Expand Up @@ -4176,7 +4174,7 @@ ____
`

It("should apply the default substitution", func() {
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]", "")
s := strings.ReplaceAll(source, "[subs=\"$SUBS\"]\n", "")
expected := types.DraftDocument{
Attributes: types.Attributes{
"github-url": "https://github.com",
Expand All @@ -4187,7 +4185,6 @@ ____
Value: "https://github.com",
},
types.BlankLine{},
types.BlankLine{},
types.VerseBlock{
Attributes: types.Attributes{
types.AttrKind: types.Verse,
Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/document_processing_apply_substitutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ var defaultSubstitutionsForBlockLines = []elementsSubstitution{
}
var defaultFencedBlockSubstitutions = defaultSubstitutionsForBlockLines
var defaultListingBlockSubstitutions = defaultSubstitutionsForBlockLines
var defaultLiteralBlockSubstitutions = defaultSubstitutionsForBlockLines

// other blocks
var defaultPassthroughBlockSubstitutions = []elementsSubstitution{}
Expand Down Expand Up @@ -252,6 +253,8 @@ func defaultSubstitutionsFor(block interface{}) ([]elementsSubstitution, error)
return defaultListingBlockSubstitutions, nil
case types.VerseBlock:
return defaultVerseBlockSubstitutions, nil
case types.LiteralBlock:
return defaultLiteralBlockSubstitutions, nil
case types.PassthroughBlock:
return defaultPassthroughBlockSubstitutions, nil
case types.CommentBlock:
Expand Down
Loading

0 comments on commit f455f72

Please sign in to comment.