Browse Source

Add workarounds to lists to conform with CM spec

pull/204/merge
Alex Kocharin 9 years ago
parent
commit
07cfbc9264
  1. 15
      lib/rules_block/code.js
  2. 13
      lib/rules_block/list.js
  3. 57
      test/fixtures/commonmark/bad.txt
  4. 36
      test/fixtures/commonmark/good.txt

15
lib/rules_block/code.js

@ -4,7 +4,7 @@
module.exports = function code(state, startLine, endLine/*, silent*/) {
var nextLine, last, token;
var nextLine, last, token, emptyLines = 0;
if (state.sCount[startLine] - state.blkIndent < 4) { return false; }
@ -12,9 +12,20 @@ module.exports = function code(state, startLine, endLine/*, silent*/) {
while (nextLine < endLine) {
if (state.isEmpty(nextLine)) {
emptyLines++;
// workaround for lists: 2 blank lines should terminate indented
// code block, but not fenced code block
if (emptyLines >= 2 && state.parentType === 'list') {
break;
}
nextLine++;
continue;
}
emptyLines = 0;
if (state.sCount[nextLine] - state.blkIndent >= 4) {
nextLine++;
last = nextLine;
@ -23,7 +34,7 @@ module.exports = function code(state, startLine, endLine/*, silent*/) {
break;
}
state.line = nextLine;
state.line = last;
token = state.push('code_block', 'code', 0);
token.content = state.getLines(startLine, last, 4 + state.blkIndent, true);

13
lib/rules_block/list.js

@ -223,7 +223,18 @@ module.exports = function list(state, startLine, endLine, silent) {
state.tShift[startLine] = contentStart - state.bMarks[startLine];
state.sCount[startLine] = offset;
state.md.block.tokenize(state, startLine, endLine, true);
if (contentStart >= max && state.isEmpty(startLine + 1)) {
// workaround for this case
// (list item is empty, list terminates before "foo"):
// ~~~~~~~~
// -
//
// foo
// ~~~~~~~~
state.line = Math.min(state.line + 2, endLine);
} else {
state.md.block.tokenize(state, startLine, endLine, true);
}
// If any of list item is tight, mark list as tight
if (!state.tight || prevEmptyEnd) {

57
test/fixtures/commonmark/bad.txt

@ -1,57 +0,0 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 3777
.
- Foo
bar
baz
.
<ul>
<li>
<p>Foo</p>
<pre><code>bar
</code></pre>
</li>
</ul>
<pre><code> baz
</code></pre>
.
error:
<ul>
<li>
<p>Foo</p>
<pre><code>bar
baz
</code></pre>
</li>
</ul>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4044
.
-
foo
.
<ul>
<li></li>
</ul>
<p>foo</p>
.
error:
<ul>
<li>foo</li>
</ul>

36
test/fixtures/commonmark/good.txt

@ -3060,6 +3060,28 @@ baz
</ul>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 3777
.
- Foo
bar
baz
.
<ul>
<li>
<p>Foo</p>
<pre><code>bar
</code></pre>
</li>
</ul>
<pre><code> baz
</code></pre>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 3799
@ -3272,6 +3294,20 @@ src line: 4016
</ul>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4044
.
-
foo
.
<ul>
<li></li>
</ul>
<p>foo</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4058

Loading…
Cancel
Save