Browse Source

Fix backtick handling inside tables

Fix https://github.com/markdown-it/markdown-it/issues/303
pull/306/head
Alex Kocharin 8 years ago
parent
commit
9eb2a26005
  1. 17
      lib/rules_block/table.js
  2. 47
      test/fixtures/markdown-it/tables.txt

17
lib/rules_block/table.js

@ -25,13 +25,22 @@ function escapedSplit(str) {
ch = str.charCodeAt(pos); ch = str.charCodeAt(pos);
while (pos < max) { while (pos < max) {
if (ch === 0x60/* ` */ && (escapes % 2 === 0)) { if (ch === 0x60/* ` */) {
backTicked = !backTicked; if (backTicked) {
lastBackTick = pos; // 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) { } else if (ch === 0x7c/* | */ && (escapes % 2 === 0) && !backTicked) {
result.push(str.substring(lastPos, pos)); result.push(str.substring(lastPos, pos));
lastPos = pos + 1; lastPos = pos + 1;
} else if (ch === 0x5c/* \ */) { }
if (ch === 0x5c/* \ */) {
escapes++; escapes++;
} else { } else {
escapes = 0; escapes = 0;

47
test/fixtures/markdown-it/tables.txt

@ -400,6 +400,53 @@ Another complicated backticks case
</table> </table>
. .
`\` in tables should not count as escaped backtick
.
# | 1 | 2
--|--|--
x | `\` | `x`
.
<table>
<thead>
<tr>
<th>#</th>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>x</td>
<td><code>\</code></td>
<td><code>x</code></td>
</tr>
</tbody>
</table>
.
Tables should handle escaped backticks
.
# | 1 | 2
--|--|--
x | \`\` | `x`
.
<table>
<thead>
<tr>
<th>#</th>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>x</td>
<td>``</td>
<td><code>x</code></td>
</tr>
</tbody>
</table>
.
Should be parsed before code blocks: Should be parsed before code blocks:
. .

Loading…
Cancel
Save