Skip to content

Commit 07b4280

Browse files
committed
single backticks are allowed inside multi-backtick inline code
1 parent 0ddaabb commit 07b4280

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/nine-owls-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'markdown-to-jsx': patch
3+
---
4+
5+
Better handle exotic backtick scenarios for inline code blocks.

index.compiler.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,16 @@ describe('inline code blocks', () => {
40274027
</code>
40284028
`)
40294029
})
4030+
4031+
it('naked backticks can be used unescaped if there are two or more outer backticks', () => {
4032+
render(compiler('``hi `foo` there``'))
4033+
4034+
expect(root.innerHTML).toMatchInlineSnapshot(`
4035+
<code>
4036+
hi \`foo\` there
4037+
</code>
4038+
`)
4039+
})
40304040
})
40314041

40324042
describe('footnotes', () => {

index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const BREAK_THEMATIC_R = /^(?:( *[-*_])){3,} *(?:\n *)+\n/
190190
const CODE_BLOCK_FENCED_R =
191191
/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/
192192
const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/
193-
const CODE_INLINE_R = /^(`+)((?:\\`|[^`])+)\1/
193+
const CODE_INLINE_R = /^(`+)((?:\\`|(?!\1)`|[^`])+)\1/
194194
const CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/
195195
const CR_NEWLINE_R = /\r\n?/g
196196

0 commit comments

Comments
 (0)