|
@ -2,9 +2,11 @@ |
|
|
|
|
|
|
|
|
'use strict'; |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var isSpace = require('../common/utils').isSpace; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
var nextLine, lastLineEmpty, oldTShift, oldBMarks, oldIndent, oldParentType, lines, |
|
|
var nextLine, lastLineEmpty, oldTShift, oldSCount, oldBMarks, oldIndent, oldParentType, lines, initial, offset, ch, |
|
|
terminatorRules, token, |
|
|
terminatorRules, token, |
|
|
i, l, terminate, |
|
|
i, l, terminate, |
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
@ -17,19 +19,39 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
// so no point trying to find the end of it in silent mode
|
|
|
// so no point trying to find the end of it in silent mode
|
|
|
if (silent) { return true; } |
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
|
// skip one optional space after '>'
|
|
|
// skip one optional space (but not tab, check cmark impl) after '>'
|
|
|
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|
|
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|
|
|
|
|
|
|
|
oldIndent = state.blkIndent; |
|
|
oldIndent = state.blkIndent; |
|
|
state.blkIndent = 0; |
|
|
state.blkIndent = 0; |
|
|
|
|
|
|
|
|
|
|
|
// skip spaces after ">" and re-calculate offset
|
|
|
|
|
|
initial = offset = state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]); |
|
|
|
|
|
|
|
|
oldBMarks = [ state.bMarks[startLine] ]; |
|
|
oldBMarks = [ state.bMarks[startLine] ]; |
|
|
state.bMarks[startLine] = pos; |
|
|
state.bMarks[startLine] = pos; |
|
|
|
|
|
|
|
|
// check if we have an empty blockquote
|
|
|
while (pos < max) { |
|
|
pos = pos < max ? state.skipSpaces(pos) : pos; |
|
|
ch = state.src.charCodeAt(pos); |
|
|
|
|
|
|
|
|
|
|
|
if (isSpace(ch)) { |
|
|
|
|
|
if (ch === 0x09) { |
|
|
|
|
|
offset += 4 - offset % 4; |
|
|
|
|
|
} else { |
|
|
|
|
|
offset++; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pos++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
lastLineEmpty = pos >= max; |
|
|
lastLineEmpty = pos >= max; |
|
|
|
|
|
|
|
|
|
|
|
oldSCount = [ state.sCount[startLine] ]; |
|
|
|
|
|
state.sCount[startLine] = offset - initial; |
|
|
|
|
|
|
|
|
oldTShift = [ state.tShift[startLine] ]; |
|
|
oldTShift = [ state.tShift[startLine] ]; |
|
|
state.tShift[startLine] = pos - state.bMarks[startLine]; |
|
|
state.tShift[startLine] = pos - state.bMarks[startLine]; |
|
|
|
|
|
|
|
@ -54,7 +76,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
// - - -
|
|
|
// - - -
|
|
|
// ```
|
|
|
// ```
|
|
|
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) { |
|
|
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) { |
|
|
if (state.tShift[nextLine] < oldIndent) { break; } |
|
|
if (state.sCount[nextLine] < oldIndent) { break; } |
|
|
|
|
|
|
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
max = state.eMarks[nextLine]; |
|
|
max = state.eMarks[nextLine]; |
|
@ -67,15 +89,36 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
if (state.src.charCodeAt(pos++) === 0x3E/* > */) { |
|
|
if (state.src.charCodeAt(pos++) === 0x3E/* > */) { |
|
|
// This line is inside the blockquote.
|
|
|
// This line is inside the blockquote.
|
|
|
|
|
|
|
|
|
// skip one optional space after '>'
|
|
|
// skip one optional space (but not tab, check cmark impl) after '>'
|
|
|
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|
|
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|
|
|
|
|
|
|
|
|
|
|
// skip spaces after ">" and re-calculate offset
|
|
|
|
|
|
initial = offset = state.sCount[nextLine] + pos - (state.bMarks[nextLine] + state.tShift[nextLine]); |
|
|
|
|
|
|
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
state.bMarks[nextLine] = pos; |
|
|
state.bMarks[nextLine] = pos; |
|
|
|
|
|
|
|
|
pos = pos < max ? state.skipSpaces(pos) : pos; |
|
|
while (pos < max) { |
|
|
|
|
|
ch = state.src.charCodeAt(pos); |
|
|
|
|
|
|
|
|
|
|
|
if (isSpace(ch)) { |
|
|
|
|
|
if (ch === 0x09) { |
|
|
|
|
|
offset += 4 - offset % 4; |
|
|
|
|
|
} else { |
|
|
|
|
|
offset++; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pos++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
lastLineEmpty = pos >= max; |
|
|
lastLineEmpty = pos >= max; |
|
|
|
|
|
|
|
|
|
|
|
oldSCount.push(state.sCount[nextLine]); |
|
|
|
|
|
state.sCount[nextLine] = offset - initial; |
|
|
|
|
|
|
|
|
oldTShift.push(state.tShift[nextLine]); |
|
|
oldTShift.push(state.tShift[nextLine]); |
|
|
state.tShift[nextLine] = pos - state.bMarks[nextLine]; |
|
|
state.tShift[nextLine] = pos - state.bMarks[nextLine]; |
|
|
continue; |
|
|
continue; |
|
@ -96,12 +139,11 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
oldTShift.push(state.tShift[nextLine]); |
|
|
oldTShift.push(state.tShift[nextLine]); |
|
|
|
|
|
oldSCount.push(state.sCount[nextLine]); |
|
|
|
|
|
|
|
|
// A negative number means that this is a paragraph continuation;
|
|
|
// A negative indentation means that this is a paragraph continuation
|
|
|
//
|
|
|
//
|
|
|
// Any negative number will do the job here, but it's better for it
|
|
|
state.sCount[nextLine] = -1; |
|
|
// to be large enough to make any bugs obvious.
|
|
|
|
|
|
state.tShift[nextLine] = -1; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
oldParentType = state.parentType; |
|
|
oldParentType = state.parentType; |
|
@ -124,6 +166,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
for (i = 0; i < oldTShift.length; i++) { |
|
|
for (i = 0; i < oldTShift.length; i++) { |
|
|
state.bMarks[i + startLine] = oldBMarks[i]; |
|
|
state.bMarks[i + startLine] = oldBMarks[i]; |
|
|
state.tShift[i + startLine] = oldTShift[i]; |
|
|
state.tShift[i + startLine] = oldTShift[i]; |
|
|
|
|
|
state.sCount[i + startLine] = oldSCount[i]; |
|
|
} |
|
|
} |
|
|
state.blkIndent = oldIndent; |
|
|
state.blkIndent = oldIndent; |
|
|
|
|
|
|
|
|