Browse Source

Allow tabs inside GFM tables

pull/302/head
Alex Kocharin 8 years ago
parent
commit
1bb254b879
  1. 17
      lib/rules_block/table.js
  2. 23
      test/fixtures/markdown-it/tables.txt

17
lib/rules_block/table.js

@ -2,6 +2,8 @@
'use strict';
var isSpace = require('../common/utils').isSpace;
function getLine(state, line) {
var pos = state.bMarks[line] + state.blkIndent,
@ -64,16 +66,25 @@ module.exports = function table(state, startLine, endLine, silent) {
if (state.sCount[nextLine] < state.blkIndent) { return false; }
// first character of the second line should be '|' or '-'
// first character of the second line should be '|', '-', ':',
// and no other characters are allowed but spaces;
// basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp
pos = state.bMarks[nextLine] + state.tShift[nextLine];
if (pos >= state.eMarks[nextLine]) { return false; }
ch = state.src.charCodeAt(pos);
ch = state.src.charCodeAt(pos++);
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */) { return false; }
while (pos < state.eMarks[nextLine]) {
ch = state.src.charCodeAt(pos);
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */ && !isSpace(ch)) { return false; }
pos++;
}
lineText = getLine(state, startLine + 1);
if (!/^[-:| ]+$/.test(lineText)) { return false; }
columns = lineText.split('|');
aligns = [];

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

@ -225,6 +225,29 @@ bar|bar</p>
.
Allow tabs as a separator on 2nd line
.
| foo | bar |
| --- | --- |
| baz | quux |
.
<table>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>baz</td>
<td>quux</td>
</tr>
</tbody>
</table>
.
Should terminate paragraph:
.
paragraph

Loading…
Cancel
Save