Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): support commas in link text attribute #389

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 230 additions & 0 deletions pkg/parser/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,121 @@ next lines`
verifyDocumentBlock(expected, source)
})

Context("text attribute with comma", func() {

It("relative link only with text having comma", func() {
source := `a link to http://website.com[A, B, and C]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "http://website.com",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link only with doublequoted text having comma", func() {
source := `a link to http://website.com["A, B, and C"]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "http://website.com",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link with doublequoted text having comma and other attrs", func() {
source := `a link to http://website.com["A, B, and C", role=foo]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "http://website.com",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
"role": "foo",
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link with text having comma and other attributes", func() {
source := `a link to http://website.com[A, B, and C, role=foo]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "http://website.com",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A",
},
},
"B": nil,
"and C": nil,
"role": "foo",
},
},
},
},
}
verifyDocumentBlock(expected, source)
})
})

})

Context("relative links", func() {
Expand Down Expand Up @@ -380,6 +495,121 @@ next lines`
verifyDocumentBlock(expected, source)
})

Context("text attribute with comma", func() {

It("relative link only with text having comma", func() {
source := `a link to link:https://foo.bar[A, B, and C]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "https://foo.bar",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link only with doublequoted text having comma", func() {
source := `a link to link:https://foo.bar["A, B, and C"]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "https://foo.bar",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link with doublequoted text having comma and other attrs", func() {
source := `a link to link:https://foo.bar["A, B, and C", role=foo]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "https://foo.bar",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A, B, and C",
},
},
"role": "foo",
},
},
},
},
}
verifyDocumentBlock(expected, source)
})

It("relative link with text having comma and other attributes", func() {
source := `a link to link:https://foo.bar[A, B, and C, role=foo]`
expected := types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: []types.InlineElements{
{
types.StringElement{Content: "a link to "},
types.InlineLink{
Location: types.Location{
types.StringElement{
Content: "https://foo.bar",
},
},
Attributes: types.ElementAttributes{
types.AttrInlineLinkText: types.InlineElements{
types.StringElement{
Content: "A",
},
},
"B": nil,
"and C": nil,
"role": "foo",
},
},
},
},
}
verifyDocumentBlock(expected, source)
})
})

})

})
Loading