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

Brackets in link text #551

Merged
merged 2 commits into from
Mar 21, 2024
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
23 changes: 23 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4067,3 +4067,26 @@ it('handles a holistic example', () => {

expect(root.innerHTML).toMatchSnapshot()
})


it('handles <code> brackets in link text', () => {
render(compiler('[`[text]`](https://example.com)'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<a href="https://example.com">
<code>
[text]
</code>
</a>
`)
})

it('handles naked brackets in link text', () => {
render(compiler('[[text]](https://example.com)'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<a href="https://example.com">
[text]
</a>
`)
})
9 changes: 7 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,13 @@ function generateListRule(
}
}

const LINK_R = /^\[([^\]]*)]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/
const IMAGE_R = /^!\[([^\]]*)]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/
const LINK_INSIDE = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*";
const LINK_HREF_AND_TITLE =
"\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*";
const LINK_R = new RegExp(
"^\\[(" + LINK_INSIDE + ")\\]\\(" + LINK_HREF_AND_TITLE + "\\)",
)
const IMAGE_R = /^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/

const NON_PARAGRAPH_BLOCK_SYNTAXES = [
BLOCKQUOTE_R,
Expand Down
Loading