Browse Source

fix: don't strip spaces from all-space code spans

Closes #1180
dev
Vitaly Puzrin 2 months ago
parent
commit
988c82be47
  1. 11
      src/rules_inline/backticks.ts
  2. 7
      test/fixtures/markdown-it/commonmark_extras.txt

11
src/rules_inline/backticks.ts

@ -54,9 +54,14 @@ export default function backtick (state: StateInline, silent: boolean): boolean
if (!silent) {
const token = state.push('code_inline', 'code', 0)
token.markup = marker
token.content = state.src.slice(pos, matchStart)
.replace(/\n/g, ' ')
.replace(/^ (.+) $/, '$1')
let content = state.src.slice(pos, matchStart).replace(/\n/g, ' ')
// Strip one space from each side, unless the content is all spaces
if (content.startsWith(' ') && content.endsWith(' ') && /[^ ]/.test(content)) {
content = content.slice(1, -1)
}
token.content = content
}
state.pos = matchEnd
return true

7
test/fixtures/markdown-it/commonmark_extras.txt

@ -916,3 +916,10 @@ the label cancels the link (CommonMark 0.31.2 6.1).
.
<p>[foo <code>bar](/url)</code> baz</p>
.
No stripping when a code span is all spaces (CommonMark 0.31.2 6.1).
.
` `
.
<p><code> </code></p>
.

Loading…
Cancel
Save