Skip to content

Commit

Permalink
feat(parser): support link macros in titles (#999)
Browse files Browse the repository at this point in the history
Fixes #956

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Apr 30, 2022
1 parent 0329b9d commit 25ab040
Show file tree
Hide file tree
Showing 12 changed files with 16,181 additions and 102,254 deletions.
2 changes: 1 addition & 1 deletion pkg/parser/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewParseContext(config *configuration.Configuration, opts ...Option) *Parse
opts = append(opts, Entrypoint("DocumentFragment"))
opts = append(opts, GlobalStore(frontMatterKey, true))
opts = append(opts, GlobalStore(documentHeaderKey, true))
opts = append(opts, GlobalStore(enabledSubstitutions, []string{Attributes}))
opts = append(opts, GlobalStore(enabledSubstitutions, []string{AttributeRefs}))
opts = append(opts, GlobalStore(usermacrosKey, config.Macros))
return &ParseContext{
filename: config.Filename,
Expand Down
47 changes: 47 additions & 0 deletions pkg/parser/delimited_block_listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,53 @@ import <a>
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with quoted text and link in title", func() {
source := `.a *link* to https://github.com[GitHub]
----
content
----`
expected := &types.Document{
Elements: []interface{}{
&types.DelimitedBlock{
Kind: types.Listing,
Attributes: types.Attributes{
types.AttrTitle: []interface{}{
&types.StringElement{
Content: "a ",
},
&types.QuotedText{
Kind: types.SingleQuoteBold,
Elements: []interface{}{
&types.StringElement{
Content: "link",
},
},
},
&types.StringElement{
Content: " to ",
},
&types.InlineLink{
Attributes: types.Attributes{
types.AttrInlineLinkText: "GitHub",
},
Location: &types.Location{
Scheme: "https://",
Path: "github.com",
},
},
},
},
Elements: []interface{}{
&types.StringElement{
Content: "content",
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

Context("with custom substitutions", func() {

// testing custom substitutions on listing blocks only, as
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/document_preprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func preprocess(ctx *ParseContext, source io.Reader) (string, error) {
func includeFile(ctx *ParseContext, incl *types.FileInclusion) (string, error) {
ctx.Opts = append(ctx.Opts, GlobalStore(documentHeaderKey, false))
if l, ok := incl.GetLocation().Path.([]interface{}); ok {
l, _, err := replaceAttributeRefsInSlice(ctx, l)
l, _, err := replaceAttributeRefsInSlice(ctx, l, noneSubstitutions())
if err != nil {
return "", errors.Errorf("Unresolved directive in %s - %s", ctx.filename, incl.RawText)
}
Expand Down
Loading

0 comments on commit 25ab040

Please sign in to comment.