From 9eb2a26005936496ad244edf08f92754e48791f1 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Wed, 30 Nov 2016 15:53:16 +0300 Subject: [PATCH] Fix backtick handling inside tables Fix https://github.com/markdown-it/markdown-it/issues/303 --- lib/rules_block/table.js | 17 +++++++--- test/fixtures/markdown-it/tables.txt | 47 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/rules_block/table.js b/lib/rules_block/table.js index 478a7e4..e29c12f 100644 --- a/lib/rules_block/table.js +++ b/lib/rules_block/table.js @@ -25,13 +25,22 @@ function escapedSplit(str) { ch = str.charCodeAt(pos); while (pos < max) { - if (ch === 0x60/* ` */ && (escapes % 2 === 0)) { - backTicked = !backTicked; - lastBackTick = pos; + if (ch === 0x60/* ` */) { + if (backTicked) { + // make \` close code sequence, but not open it; + // the reason is: `\` is correct code block + backTicked = false; + lastBackTick = pos; + } else if (escapes % 2 === 0) { + backTicked = true; + lastBackTick = pos; + } } else if (ch === 0x7c/* | */ && (escapes % 2 === 0) && !backTicked) { result.push(str.substring(lastPos, pos)); lastPos = pos + 1; - } else if (ch === 0x5c/* \ */) { + } + + if (ch === 0x5c/* \ */) { escapes++; } else { escapes = 0; diff --git a/test/fixtures/markdown-it/tables.txt b/test/fixtures/markdown-it/tables.txt index ff45529..15e26c8 100644 --- a/test/fixtures/markdown-it/tables.txt +++ b/test/fixtures/markdown-it/tables.txt @@ -400,6 +400,53 @@ Another complicated backticks case . +`\` in tables should not count as escaped backtick +. +# | 1 | 2 +--|--|-- +x | `\` | `x` +. + + + + + + + + + + + + + + + +
#12
x\x
+. + +Tables should handle escaped backticks +. +# | 1 | 2 +--|--|-- +x | \`\` | `x` +. + + + + + + + + + + + + + + + +
#12
x``x
+. Should be parsed before code blocks: .