Skip to content

Commit

Permalink
Parse link reference definitions surrounded by angle brackets (#476)
Browse files Browse the repository at this point in the history
I created issue #475, and it seemed like a simple enough change,
I wanted to take a stab at solving it. I've adjusted the regex,
and added some tests to allow angle brackets to surround link
reference definitions, like this one:

```markdown
This is [an example][id] reference-style link.

[id]: <http://example.com/>  "Optional Title Here"
```

All tests are passing.

Signed-off-by: Elliot Voris <elliot@voris.me>
  • Loading branch information
ElliotFriend committed Feb 10, 2023
1 parent adf9eab commit 5bd4503
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,44 @@ describe('links', () => {
`)
})

it('should handle a link reference with angle brackets', () => {
render(compiler(['[foo][1]', '[1]: </xyz.png>'].join('\n')))

expect(root.innerHTML).toMatchInlineSnapshot(`
<p>
<a href="/xyz.png">
foo
</a>
</p>
`)
})

it('should handle a link reference with angle brackets and a space', () => {
render(compiler(['[foo] [1]', '[1]: </xyz.png>'].join('\n')))

expect(root.innerHTML).toMatchInlineSnapshot(`
<p>
<a href="/xyz.png">
foo
</a>
</p>
`)
})

it('should handle a link reference with angle brackets and a title', () => {
render(compiler(['[foo][1]', '[1]: </xyz.png> "bar"'].join('\n')))

expect(root.innerHTML).toMatchInlineSnapshot(`
<p>
<a href="/xyz.png"
title="bar"
>
foo
</a>
</p>
`)
})

it('list item should break paragraph', () => {
render(compiler('foo\n- item'))

Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const LINK_AUTOLINK_R = /^<([^ >]+:\/[^ >]+)>/
const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi
const NP_TABLE_R = /^(.*\|?.*)\n *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*)\n?/
const PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+(\S+)\s*("([^"]*)")?/
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/
const REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/
const REFERENCE_LINK_R = /^\[([^\]]*)\] ?\[([^\]]*)\]/
const SQUARE_BRACKETS_R = /(\[|\])/g
Expand Down

0 comments on commit 5bd4503

Please sign in to comment.