Skip to content

Commit

Permalink
fix: simplify link reference fallback handling
Browse files Browse the repository at this point in the history
Closes #608
  • Loading branch information
quantizor committed Nov 12, 2024
1 parent 69a9856 commit fb3d716
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-beds-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-to-jsx': patch
---

Simplify handling of fallback scenario if a link reference is missing its corresponding footnote.
10 changes: 3 additions & 7 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ const PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/
const REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/
const REFERENCE_LINK_R = /^\[([^\]]*)\] ?\[([^\]]*)\]/
const SQUARE_BRACKETS_R = /(\[|\])/g
const SHOULD_RENDER_AS_BLOCK_R = /(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/
const TAB_R = /\t/g
const TABLE_TRIM_PIPES = /(^ *\||\| *$)/g
Expand Down Expand Up @@ -1764,10 +1763,7 @@ export function compiler(
parse(capture, parse, state) {
return {
children: parse(capture[1], state),
fallbackChildren: parse(
capture[0].replace(SQUARE_BRACKETS_R, '\\$1'),
state
),
fallbackChildren: capture[0],
ref: capture[2],
}
},
Expand All @@ -1781,7 +1777,7 @@ export function compiler(
{output(node.children, state)}
</a>
) : (
<span key={state.key}>{output(node.fallbackChildren, state)}</span>
<span key={state.key}>{node.fallbackChildren}</span>
)
},
},
Expand Down Expand Up @@ -2152,7 +2148,7 @@ export namespace MarkdownToJSX {
export interface ReferenceLinkNode {
type: typeof RuleType.refLink
children: MarkdownToJSX.ParserResult[]
fallbackChildren: MarkdownToJSX.ParserResult[]
fallbackChildren: string
ref: string
}

Expand Down

0 comments on commit fb3d716

Please sign in to comment.