Browse Source

Fix list terminating paragraph shenanigans

pull/293/head
Alex Kocharin 8 years ago
parent
commit
18dd8e3a71
  1. 68
      lib/rules_block/list.js
  2. 66
      test/fixtures/commonmark/bad.txt
  3. 38
      test/fixtures/commonmark/good.txt

68
lib/rules_block/list.js

@ -98,43 +98,73 @@ function markTightParagraphs(state, idx) {
module.exports = function list(state, startLine, endLine, silent) { module.exports = function list(state, startLine, endLine, silent) {
var nextLine, var ch,
contentStart,
i,
indent,
indentAfterMarker,
initial, initial,
isOrdered,
itemLines,
l,
listLines,
listTokIdx,
markerCharCode,
markerValue,
max,
nextLine,
offset, offset,
indent,
oldTShift,
oldIndent, oldIndent,
oldLIndent, oldLIndent,
oldTight,
oldParentType, oldParentType,
start, oldTShift,
posAfterMarker, oldTight,
ch,
pos, pos,
max, posAfterMarker,
indentAfterMarker,
markerValue,
markerCharCode,
isOrdered,
contentStart,
listTokIdx,
prevEmptyEnd, prevEmptyEnd,
listLines, start,
itemLines, terminate,
tight = true,
terminatorRules, terminatorRules,
token, token,
i, l, terminate; isTerminatingParagraph = false,
tight = true;
// limit conditions when list can interrupt
// a paragraph (validation mode only)
if (silent && state.parentType === 'paragraph') {
// Next list item should still terminate previous list item;
//
// This code can fail if plugins use blkIndent as well as lists,
// but I hope the spec gets fixed long before that happens.
//
if (state.tShift[startLine] >= state.blkIndent) {
isTerminatingParagraph = true;
}
}
// Detect list type and position after marker // Detect list type and position after marker
if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) { if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) {
isOrdered = true; isOrdered = true;
start = state.bMarks[startLine] + state.tShift[startLine];
markerValue = Number(state.src.substr(start, posAfterMarker - start - 1));
// If we're starting a new ordered list right after
// a paragraph, it should start with 1.
if (isTerminatingParagraph && markerValue !== 1) return false;
} else if ((posAfterMarker = skipBulletListMarker(state, startLine)) >= 0) { } else if ((posAfterMarker = skipBulletListMarker(state, startLine)) >= 0) {
isOrdered = false; isOrdered = false;
} else { } else {
return false; return false;
} }
// If we're starting a new unordered list right after
// a paragraph, first line should not be empty.
if (isTerminatingParagraph) {
if (state.skipSpaces(posAfterMarker) >= state.eMarks[startLine]) return false;
}
// We should terminate list on style change. Remember first one to compare. // We should terminate list on style change. Remember first one to compare.
markerCharCode = state.src.charCodeAt(posAfterMarker - 1); markerCharCode = state.src.charCodeAt(posAfterMarker - 1);
@ -145,8 +175,6 @@ module.exports = function list(state, startLine, endLine, silent) {
listTokIdx = state.tokens.length; listTokIdx = state.tokens.length;
if (isOrdered) { if (isOrdered) {
start = state.bMarks[startLine] + state.tShift[startLine];
markerValue = Number(state.src.substr(start, posAfterMarker - start - 1));
token = state.push('ordered_list_open', 'ol', 1); token = state.push('ordered_list_open', 'ol', 1);
if (markerValue !== 1) { if (markerValue !== 1) {
token.attrs = [ [ 'start', markerValue ] ]; token.attrs = [ [ 'start', markerValue ] ];

66
test/fixtures/commonmark/bad.txt

@ -18,69 +18,3 @@ error:
</blockquote> </blockquote>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4214
.
foo
*
foo
1.
.
<p>foo
*</p>
<p>foo
1.</p>
.
error:
<p>foo</p>
<ul>
<li></li>
</ul>
<p>foo</p>
<ol>
<li></li>
</ol>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4866
.
The number of windows in my house is
14. The number of doors is 6.
.
<p>The number of windows in my house is
14. The number of doors is 6.</p>
.
error:
<p>The number of windows in my house is</p>
<ol start="14">
<li>The number of doors is 6.</li>
</ol>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6137
.
*foo bar
*
.
<p>*foo bar
*</p>
.
error:
<p>*foo bar</p>
<ul>
<li></li>
</ul>

38
test/fixtures/commonmark/good.txt

@ -3373,6 +3373,22 @@ src line: 4204
</ul> </ul>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4214
.
foo
*
foo
1.
.
<p>foo
*</p>
<p>foo
1.</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4236 src line: 4236
@ -3716,6 +3732,17 @@ Foo
</ul> </ul>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4866
.
The number of windows in my house is
14. The number of doors is 6.
.
<p>The number of windows in my house is
14. The number of doors is 6.</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4876 src line: 4876
@ -4708,6 +4735,17 @@ src line: 6128
<p>*foo bar *</p> <p>*foo bar *</p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6137
.
*foo bar
*
.
<p>*foo bar
*</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6150 src line: 6150

Loading…
Cancel
Save