|
@ -12,8 +12,7 @@ var skipSpaces = require('../helpers').skipSpaces; |
|
|
function skipBulletListMarker(state, startLine) { |
|
|
function skipBulletListMarker(state, startLine) { |
|
|
var marker, pos, max; |
|
|
var marker, pos, max; |
|
|
|
|
|
|
|
|
|
|
|
if (state.tShift[startLine] - state.blkIndent > 3) { return -1; } |
|
|
if (state.tShift[startLine] > 3) { return -1; } |
|
|
|
|
|
|
|
|
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
max = state.eMarks[startLine]; |
|
|
max = state.eMarks[startLine]; |
|
@ -36,7 +35,7 @@ function skipBulletListMarker(state, startLine) { |
|
|
return pos; |
|
|
return pos; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Search `\d+\.[\n ]`, returns next pos arter marker on success
|
|
|
// Search `\d+[.)][\n ]`, returns next pos arter marker on success
|
|
|
// or -1 on fail.
|
|
|
// or -1 on fail.
|
|
|
function skipOrderedListMarker(state, startLine) { |
|
|
function skipOrderedListMarker(state, startLine) { |
|
|
var ch, |
|
|
var ch, |
|
@ -79,18 +78,16 @@ function skipOrderedListMarker(state, startLine) { |
|
|
module.exports = function list(state, startLine, endLine, silent) { |
|
|
module.exports = function list(state, startLine, endLine, silent) { |
|
|
var nextLine, |
|
|
var nextLine, |
|
|
indent, |
|
|
indent, |
|
|
|
|
|
oldIndent, |
|
|
|
|
|
oldTight, |
|
|
start, |
|
|
start, |
|
|
posAfterMarker, |
|
|
posAfterMarker, |
|
|
max, |
|
|
max, |
|
|
indentAfterMarker, |
|
|
indentAfterMarker, |
|
|
markerValue, |
|
|
markerValue, |
|
|
isOrdered, |
|
|
isOrdered, |
|
|
lastLine, |
|
|
|
|
|
subState, |
|
|
|
|
|
subString, |
|
|
|
|
|
contentStart, |
|
|
contentStart, |
|
|
listTokIdx, |
|
|
listTokIdx, |
|
|
lineMax, |
|
|
|
|
|
endOfList; |
|
|
endOfList; |
|
|
//rules_named = state.lexerBlock.rules_named;
|
|
|
//rules_named = state.lexerBlock.rules_named;
|
|
|
|
|
|
|
|
@ -131,10 +128,10 @@ module.exports = function list(state, startLine, endLine, silent) { |
|
|
//
|
|
|
//
|
|
|
|
|
|
|
|
|
nextLine = startLine; |
|
|
nextLine = startLine; |
|
|
lineMax = state.lineMax; |
|
|
|
|
|
endOfList = false; |
|
|
endOfList = false; |
|
|
|
|
|
|
|
|
while (nextLine < endLine && !endOfList) { |
|
|
while (nextLine < endLine && !endOfList) { |
|
|
|
|
|
if (state.tShift[startLine] < state.blkIndent) { return -1; } |
|
|
if (isOrdered) { |
|
|
if (isOrdered) { |
|
|
posAfterMarker = skipOrderedListMarker(state, nextLine); |
|
|
posAfterMarker = skipOrderedListMarker(state, nextLine); |
|
|
if (posAfterMarker < 0) { break; } |
|
|
if (posAfterMarker < 0) { break; } |
|
@ -165,56 +162,30 @@ module.exports = function list(state, startLine, endLine, silent) { |
|
|
// ^^^^^ - calculating total length of this thing
|
|
|
// ^^^^^ - calculating total length of this thing
|
|
|
indent = (posAfterMarker - state.bMarks[nextLine]) + indentAfterMarker; |
|
|
indent = (posAfterMarker - state.bMarks[nextLine]) + indentAfterMarker; |
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
// Scan lines inside list items
|
|
|
|
|
|
//
|
|
|
|
|
|
lastLine = startLine; |
|
|
|
|
|
|
|
|
|
|
|
// Run sublexer & write tokens
|
|
|
// Run sublexer & write tokens
|
|
|
state.tokens.push({ type: 'list_item_open' }); |
|
|
state.tokens.push({ type: 'list_item_open' }); |
|
|
|
|
|
|
|
|
nextLine++; |
|
|
nextLine++; |
|
|
for (;;) { |
|
|
|
|
|
// if this line is indented more than with N spaces,
|
|
|
|
|
|
// it's the new paragraph of the same list item
|
|
|
|
|
|
if (nextLine < lineMax) { |
|
|
|
|
|
if (isEmpty(state, nextLine)) { |
|
|
|
|
|
nextLine++; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (state.tShift[nextLine] >= indent) { |
|
|
|
|
|
if (nextLine < endLine) { lastLine = nextLine; } |
|
|
|
|
|
nextLine++; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (lastLine < 0) { break; } |
|
|
|
|
|
|
|
|
|
|
|
subString = state.src.slice(contentStart, state.eMarks[lastLine]) |
|
|
|
|
|
.replace(RegExp('^ {' + indent + '}', 'mg'), ''); |
|
|
|
|
|
if (lastLine < lineMax) { |
|
|
|
|
|
// TODO: we should slice up to next empty line, not up to the end of the document
|
|
|
|
|
|
// (or even better - up to the next valid token)
|
|
|
|
|
|
//
|
|
|
|
|
|
// This has no impact on the algorithm except for performance
|
|
|
|
|
|
subString += state.src.slice(state.eMarks[lastLine]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
subState = state.clone(subString); |
|
|
oldIndent = state.blkIndent; |
|
|
state.lexerBlock.tokenize(subState, 0, lastLine - startLine + 1, true); |
|
|
oldTight = state.tight; |
|
|
nextLine = startLine = subState.line + startLine; |
|
|
state.blkIndent = state.tShift[startLine] = indent; |
|
|
lastLine = -1; |
|
|
|
|
|
contentStart = state.eMarks[startLine]; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: need to detect loose type.
|
|
|
state.lexerBlock.tokenize(state, startLine, endLine, true); |
|
|
// Problem: blocks. separated by empty lines can be member of sublists.
|
|
|
|
|
|
|
|
|
|
|
|
// If any of list item is loose, mark list as loose
|
|
|
// If any of list item is loose, mark list as loose
|
|
|
if (!subState.tight) { |
|
|
if (!state.tight || isEmpty(state, state.line - 1)) { |
|
|
state.tokens[listTokIdx].tight = false; |
|
|
state.tokens[listTokIdx].tight = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.blkIndent = state.tShift[startLine] = oldIndent; |
|
|
|
|
|
state.tight = oldTight; |
|
|
|
|
|
|
|
|
|
|
|
state.tokens.push({ type: 'list_item_close' }); |
|
|
|
|
|
|
|
|
|
|
|
nextLine = startLine = state.line; |
|
|
|
|
|
contentStart = state.bMarks[startLine]; |
|
|
|
|
|
|
|
|
if (nextLine >= endLine) { break; } |
|
|
if (nextLine >= endLine) { break; } |
|
|
|
|
|
|
|
|
if (isEmpty(state, nextLine)) { |
|
|
if (isEmpty(state, nextLine)) { |
|
@ -226,9 +197,6 @@ module.exports = function list(state, startLine, endLine, silent) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.tokens.push({ type: 'list_item_close' }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Finilize list
|
|
|
// Finilize list
|
|
|
if (isOrdered) { |
|
|
if (isOrdered) { |
|
|
state.tokens.push({ type: 'ordered_list_close' }); |
|
|
state.tokens.push({ type: 'ordered_list_close' }); |
|
|