diff --git a/src/rules_inline/backticks.ts b/src/rules_inline/backticks.ts index 479e1e0..144e91e 100644 --- a/src/rules_inline/backticks.ts +++ b/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 diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index df7cdcc..3307531 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -916,3 +916,10 @@ the label cancels the link (CommonMark 0.31.2 6.1). .
[foo bar](/url) baz