diff --git a/benchmark/samples/block-tables.md b/benchmark/samples/block-tables.md new file mode 100644 index 0000000..5fd6321 --- /dev/null +++ b/benchmark/samples/block-tables.md @@ -0,0 +1,21 @@ +| Heading 1 | Heading 2 +| --------- | --------- +| Cell 1 | Cell 2 +| Cell 3 | Cell 4 + +| Header 1 | Header 2 | Header 3 | Header 4 | +| :------: | -------: | :------- | -------- | +| Cell 1 | Cell 2 | Cell 3 | Cell 4 | +| Cell 5 | Cell 6 | Cell 7 | Cell 8 | + + Test code + +Header 1 | Header 2 +-------- | -------- +Cell 1 | Cell 2 +Cell 3 | Cell 4 + +Header 1|Header 2|Header 3|Header 4 +:-------|:------:|-------:|-------- +Cell 1 |Cell 2 |Cell 3 |Cell 4 +*Cell 5*|Cell 6 |Cell 7 |Cell 8 diff --git a/lib/renderer.js b/lib/renderer.js index aad29b9..f9d5af6 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -140,8 +140,20 @@ rules.table_open = function (/*tokens, idx, options*/) { rules.table_close = function (/*tokens, idx, options*/) { return '\n'; }; +rules.thead_open = function (/*tokens, idx, options*/) { + return '\t\n'; +}; +rules.thead_close = function (/*tokens, idx, options*/) { + return '\t\n'; +}; +rules.tbody_open = function (/*tokens, idx, options*/) { + return '\t\n'; +}; +rules.tbody_close = function (/*tokens, idx, options*/) { + return '\t\n'; +}; rules.tr_open = function (/*tokens, idx, options*/) { - return '\n'; + return '\t\t'; }; rules.tr_close = function (/*tokens, idx, options*/) { return '\n'; @@ -149,20 +161,20 @@ rules.tr_close = function (/*tokens, idx, options*/) { rules.th_open = function (tokens, idx /*, options*/) { var token = tokens[idx]; return ''; }; rules.th_close = function (/*tokens, idx, options*/) { - return '\n'; + return ''; }; rules.td_open = function (tokens, idx /*, options*/) { var token = tokens[idx]; return ''; }; rules.td_close = function (/*tokens, idx, options*/) { - return '\n'; + return ''; }; diff --git a/lib/rules_block/table.js b/lib/rules_block/table.js index f934c1f..f8a945b 100644 --- a/lib/rules_block/table.js +++ b/lib/rules_block/table.js @@ -21,7 +21,7 @@ module.exports = function table(state, startLine, endLine, silent) { // first character of the second line should be '|' or '-' ch = state.src.charCodeAt(state.bMarks[startLine + 1] + state.tShift[startLine + 1]); - if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */) { return false; } + if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */) { return false; } secondLineMatch = lineMatch(state, startLine + 1, /^ *\|?(( *[:-]-+[:-] *\|)+( *[:-]-+[:-] *))\|? *$/); @@ -48,6 +48,7 @@ module.exports = function table(state, startLine, endLine, silent) { if (silent) { return true; } state.tokens.push({ type: 'table_open', level: state.level++ }); + state.tokens.push({ type: 'thead_open', level: state.level++ }); state.tokens.push({ type: 'tr_open', level: state.level++ }); for (i = 0; i < rows.length; i++) { @@ -60,6 +61,8 @@ module.exports = function table(state, startLine, endLine, silent) { state.tokens.push({ type: 'th_close', level: --state.level }); } state.tokens.push({ type: 'tr_close', level: --state.level }); + state.tokens.push({ type: 'thead_close', level: --state.level }); + state.tokens.push({ type: 'tbody_open', level: state.level++ }); for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { m = lineMatch(state, nextLine, /^ *\|?(.*?\|.*?)\|? *$/); @@ -77,6 +80,7 @@ module.exports = function table(state, startLine, endLine, silent) { } state.tokens.push({ type: 'tr_close', level: --state.level }); } + state.tokens.push({ type: 'tbody_close', level: --state.level }); state.tokens.push({ type: 'table_close', level: --state.level }); state.line = nextLine; diff --git a/test/fixtures/remarkable/tables.txt b/test/fixtures/remarkable/tables.txt new file mode 100644 index 0000000..307f4aa --- /dev/null +++ b/test/fixtures/remarkable/tables.txt @@ -0,0 +1,69 @@ +Tests from marked: + +. +| Heading 1 | Heading 2 +| --------- | --------- +| Cell 1 | Cell 2 +| Cell 3 | Cell 4 +. + + + + + + + + +
Heading 1Heading 2
Cell 1Cell 2
Cell 3Cell 4
+. + +. +| Header 1 | Header 2 | Header 3 | Header 4 | +| :------: | -------: | :------- | -------- | +| Cell 1 | Cell 2 | Cell 3 | Cell 4 | +| Cell 5 | Cell 6 | Cell 7 | Cell 8 | +. + + + + + + + + +
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
+. + +. +Header 1 | Header 2 +-------- | -------- +Cell 1 | Cell 2 +Cell 3 | Cell 4 +. + + + + + + + + +
Header 1Header 2
Cell 1Cell 2
Cell 3Cell 4
+. + +. +Header 1|Header 2|Header 3|Header 4 +:-------|:------:|-------:|-------- +Cell 1 |Cell 2 |Cell 3 |Cell 4 +*Cell 5*|Cell 6 |Cell 7 |Cell 8 +. + + + + + + + + +
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
+.