Browse Source

Fix tables inside lists/blockquotes

pull/14/head
Alex Kocharin 10 years ago
parent
commit
ec90a38df2
  1. 14
      lib/rules_block/table.js
  2. 43
      test/fixtures/remarkable/tables.txt

14
lib/rules_block/table.js

@ -4,7 +4,7 @@
function lineMatch(state, line, reg) { function lineMatch(state, line, reg) {
var pos = state.bMarks[line], var pos = state.bMarks[line] + state.blkIndent,
max = state.eMarks[line]; max = state.eMarks[line];
return state.src.substr(pos, max - pos).match(reg); return state.src.substr(pos, max - pos).match(reg);
@ -18,6 +18,9 @@ module.exports = function table(state, startLine, endLine, silent) {
// should have at least three lines // should have at least three lines
if (startLine + 2 > endLine) { return false; } if (startLine + 2 > endLine) { return false; }
if (state.tShift[startLine + 1] < state.blkIndent) { return false; }
if (state.bqMarks[startLine + 1] < state.bqLevel) { return false; }
// first character of the second line should be '|' or '-' // first character of the second line should be '|' or '-'
ch = state.src.charCodeAt(state.bMarks[startLine + 1] ch = state.src.charCodeAt(state.bMarks[startLine + 1]
+ state.tShift[startLine + 1]); + state.tShift[startLine + 1]);
@ -31,9 +34,9 @@ module.exports = function table(state, startLine, endLine, silent) {
aligns = []; aligns = [];
for (i = 0; i < rows.length; i++) { for (i = 0; i < rows.length; i++) {
t = rows[i].trim(); t = rows[i].trim();
if (t[t.length - 1] === ':') { if (t.charCodeAt(t.length - 1) === 0x3A/* : */) {
aligns[i] = t[0] === ':' ? 'center' : 'right'; aligns[i] = t.charCodeAt(0) === 0x3A/* : */ ? 'center' : 'right';
} else if (t[0] === ':') { } else if (t.charCodeAt(0) === 0x3A/* : */) {
aligns[i] = 'left'; aligns[i] = 'left';
} else { } else {
aligns[i] = ''; aligns[i] = '';
@ -65,6 +68,9 @@ module.exports = function table(state, startLine, endLine, silent) {
state.tokens.push({ type: 'tbody_open', level: state.level++ }); state.tokens.push({ type: 'tbody_open', level: state.level++ });
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { for (nextLine = startLine + 2; nextLine < endLine; nextLine++) {
if (state.tShift[nextLine] < state.blkIndent) { break; }
if (state.bqMarks[nextLine] < state.bqLevel) { break; }
m = lineMatch(state, nextLine, /^ *\|?(.*?\|.*?)\|? *$/); m = lineMatch(state, nextLine, /^ *\|?(.*?\|.*?)\|? *$/);
if (!m) { break; } if (!m) { break; }
rows = m[1].split('|'); rows = m[1].split('|');

43
test/fixtures/remarkable/tables.txt

@ -67,3 +67,46 @@ Cell 1 |Cell 2 |Cell 3 |Cell 4
</tbody> </tbody>
</table> </table>
. .
Nested tables inside blockquotes:
.
> foo|foo
> ---|---
> bar|bar
baz|baz
.
<blockquote>
<table>
<thead>
<tr><th>foo</th><th>foo</th></tr>
</thead>
<tbody>
<tr><td>bar</td><td>bar</td></tr>
</tbody>
</table>
</blockquote>
<p>baz|baz</p>
.
Nested tables inside lists:
.
- foo|foo
---|---
bar|bar
baz|baz
.
<ul>
<li><table>
<thead>
<tr><th>foo</th><th>foo</th></tr>
</thead>
<tbody>
<tr><td>bar</td><td>bar</td></tr>
</tbody>
</table>
</li>
</ul>
<p>baz|baz</p>
.

Loading…
Cancel
Save