Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Jul 5, 2019
1 parent 73b41b0 commit b252903
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
36 changes: 30 additions & 6 deletions lib/rules_block/list.js
Expand Up @@ -114,9 +114,9 @@ module.exports = function list(state, startLine, endLine, silent) {
max,
nextLine,
offset,
oldIndent,
oldLIndent,
oldListIndent,
oldParentType,
oldSCount,
oldTShift,
oldTight,
pos,
Expand All @@ -132,6 +132,18 @@ module.exports = function list(state, startLine, endLine, silent) {
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }

// Special case:
// - item 1
// - item 2
// - item 3
// - item 4
// - this one is a paragraph continuation
if (state.listIndent >= 0 &&
state.sCount[startLine] - state.listIndent >= 4 &&
state.sCount[startLine] < state.blkIndent) {
return false;
}

// limit conditions when list can interrupt
// a paragraph (validation mode only)
if (silent && state.parentType === 'paragraph') {
Expand Down Expand Up @@ -243,11 +255,19 @@ module.exports = function list(state, startLine, endLine, silent) {
token.markup = String.fromCharCode(markerCharCode);
token.map = itemLines = [ startLine, 0 ];

oldIndent = state.blkIndent;
// change current state, then restore it after parser subcall
oldTight = state.tight;
oldTShift = state.tShift[startLine];
oldLIndent = state.sCount[startLine];
oldSCount = state.sCount[startLine];

// - example list
// ^ listIndent position will be here
// ^ blkIndent position will be here
//
oldListIndent = state.listIndent;
state.listIndent = state.blkIndent;
state.blkIndent = indent;

state.tight = true;
state.tShift[startLine] = contentStart - state.bMarks[startLine];
state.sCount[startLine] = offset;
Expand All @@ -273,9 +293,10 @@ module.exports = function list(state, startLine, endLine, silent) {
// but we should filter last element, because it means list finish
prevEmptyEnd = (state.line - startLine) > 1 && state.isEmpty(state.line - 1);

state.blkIndent = oldIndent;
state.blkIndent = state.listIndent;
state.listIndent = oldListIndent;
state.tShift[startLine] = oldTShift;
state.sCount[startLine] = oldLIndent;
state.sCount[startLine] = oldSCount;
state.tight = oldTight;

token = state.push('list_item_close', 'li', -1);
Expand All @@ -292,6 +313,9 @@ module.exports = function list(state, startLine, endLine, silent) {
//
if (state.sCount[nextLine] < state.blkIndent) { break; }

// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { break; }

// fail if terminating block found
terminate = false;
for (i = 0, l = terminatorRules.length; i < l; i++) {
Expand Down
5 changes: 3 additions & 2 deletions lib/rules_block/state_block.js
Expand Up @@ -40,12 +40,13 @@ function StateBlock(src, md, env, tokens) {
this.bsCount = [];

// block parser variables
this.blkIndent = 0; // required block content indent
// (for example, if we are in list)
this.blkIndent = 0; // required block content indent (for example, if we are
// inside a list, it would be positioned after list marker)
this.line = 0; // line index in src
this.lineMax = 0; // lines count
this.tight = false; // loose/tight mode for lists
this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any)
this.listIndent = -1; // indent of the current list block (-1 if there isn't any)

// can be 'blockquote', 'list', 'root', 'paragraph' or 'reference'
// used in lists to determine if they interrupt a paragraph
Expand Down

0 comments on commit b252903

Please sign in to comment.