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

feat(parser): support for inline anchors #902

Merged
merged 1 commit into from
Jan 1, 2022
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
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 @@ -922,6 +922,9 @@ func replaceAttributeRefsInElement(ctx *ParseContext, element interface{}) (inte
}

func replaceAttributeRefsInLocation(ctx *ParseContext, b types.BlockWithLocation) (bool, error) {
if b.GetLocation() == nil {
return false, nil
}
path, found, err := replaceAttributeRefsInElements(ctx, b.GetLocation().Path)
if err != nil {
return false, err
Expand Down
46 changes: 35 additions & 11 deletions pkg/parser/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ a link to {scheme}://{path} and https://foo.com`

Context("relative links", func() {

It("relative link to doc without text", func() {
It("to doc without text", func() {
source := "a link to link:foo.adoc[]"
expected := &types.Document{
Elements: []interface{}{
Expand All @@ -958,7 +958,7 @@ a link to {scheme}://{path} and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link to doc with text", func() {
It("to doc with text", func() {
source := "a link to link:foo.adoc[foo doc]"
expected := &types.Document{
Elements: []interface{}{
Expand All @@ -985,7 +985,7 @@ a link to {scheme}://{path} and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link to external URL with text only", func() {
It("to external URL with text only", func() {
source := "a link to link:https://example.com[foo doc]"
expected := &types.Document{
Elements: []interface{}{
Expand All @@ -1012,7 +1012,7 @@ a link to {scheme}://{path} and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link to external URL with text and extra attributes", func() {
It("to external URL with text and extra attributes", func() {
source := "a link to link:https://example.com[foo doc, foo=bar]"
expected := &types.Document{
Elements: []interface{}{
Expand Down Expand Up @@ -1040,7 +1040,7 @@ a link to {scheme}://{path} and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link to external URL with extra attributes only", func() {
It("to external URL with extra attributes only", func() {
source := "a link to link:https://example.com[foo=bar]"
expected := &types.Document{
Elements: []interface{}{
Expand All @@ -1067,7 +1067,7 @@ a link to {scheme}://{path} and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("invalid relative link to doc", func() {
It("invalid syntax", func() {
source := "a link to link:foo.adoc"
expected := &types.Document{
Elements: []interface{}{
Expand Down Expand Up @@ -1262,7 +1262,7 @@ a link to {scheme}:{path}[] and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link within quoted text", func() {
It("within quoted text", func() {
source := "*link:foo[]*"
expected := &types.Document{
Elements: []interface{}{
Expand All @@ -1289,7 +1289,7 @@ a link to {scheme}:{path}[] and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("links with underscores", func() {
It("with underscores", func() {
source := "link:a_[A] link:a_[A]"
expected := &types.Document{
Elements: []interface{}{
Expand Down Expand Up @@ -1329,7 +1329,7 @@ a link to {scheme}:{path}[] and https://foo.com`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("links with line breaks in attributes", func() {
It("with line breaks in attributes", func() {
source := `link:x[
title]`
expected := &types.Document{
Expand Down Expand Up @@ -1357,7 +1357,7 @@ title]`

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

It("relative link only with text having comma", func() {
It("with text having comma", func() {
source := `a link to link:https://example.com[A, B, and C]`
expected := &types.Document{
Elements: []interface{}{
Expand Down Expand Up @@ -1386,7 +1386,7 @@ title]`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("relative link only with doublequoted text having comma", func() {
It("with doublequoted text having comma", func() {
source := `a link to link:https://example.com["A, B, and C"]`
expected := &types.Document{
Elements: []interface{}{
Expand Down Expand Up @@ -1472,5 +1472,29 @@ title]`
})
})
})

Context("inline anchors", func() {

It("opening a paragraph", func() {
source := `[[bookmark-a]]Inline anchors make arbitrary content referenceable.`
expected := &types.Document{
Elements: []interface{}{
&types.Paragraph{
Elements: []interface{}{
&types.InlineLink{
Attributes: types.Attributes{
types.AttrID: "bookmark-a",
},
},
&types.StringElement{
Content: "Inline anchors make arbitrary content referenceable.",
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
})
})
})
Loading