|
|
@ -6,9 +6,25 @@ var isSpace = require('../common/utils').isSpace; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
var nextLine, lastLineEmpty, oldTShift, oldSCount, oldBMarks, oldIndent, oldParentType, lines, initial, offset, ch, |
|
|
|
terminatorRules, token, |
|
|
|
i, l, terminate, |
|
|
|
var adjustTab, |
|
|
|
ch, |
|
|
|
i, |
|
|
|
initial, |
|
|
|
l, |
|
|
|
lastLineEmpty, |
|
|
|
lines, |
|
|
|
nextLine, |
|
|
|
offset, |
|
|
|
oldBMarks, |
|
|
|
oldBSCount, |
|
|
|
oldIndent, |
|
|
|
oldParentType, |
|
|
|
oldSCount, |
|
|
|
oldTShift, |
|
|
|
spaceAfterMarker, |
|
|
|
terminate, |
|
|
|
terminatorRules, |
|
|
|
token, |
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
|
max = state.eMarks[startLine]; |
|
|
|
|
|
|
@ -19,15 +35,41 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
// so no point trying to find the end of it in silent mode
|
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
// skip one optional space (but not tab, check cmark impl) after '>'
|
|
|
|
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|
|
|
|
|
|
|
oldIndent = state.blkIndent; |
|
|
|
state.blkIndent = 0; |
|
|
|
|
|
|
|
// skip spaces after ">" and re-calculate offset
|
|
|
|
initial = offset = state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]); |
|
|
|
|
|
|
|
// skip one optional space after '>'
|
|
|
|
if (state.src.charCodeAt(pos) === 0x20 /* space */) { |
|
|
|
// ' > test '
|
|
|
|
// ^ -- position start of line here:
|
|
|
|
pos++; |
|
|
|
initial++; |
|
|
|
offset++; |
|
|
|
adjustTab = false; |
|
|
|
spaceAfterMarker = true; |
|
|
|
} else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { |
|
|
|
spaceAfterMarker = true; |
|
|
|
|
|
|
|
if ((state.bsCount[startLine] + offset) % 4 === 3) { |
|
|
|
// ' >\t test '
|
|
|
|
// ^ -- position start of line here (tab has width===1)
|
|
|
|
pos++; |
|
|
|
initial++; |
|
|
|
offset++; |
|
|
|
adjustTab = false; |
|
|
|
} else { |
|
|
|
// ' >\t test '
|
|
|
|
// ^ -- position start of line here + shift bsCount slightly
|
|
|
|
// to make extra space appear
|
|
|
|
adjustTab = true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
spaceAfterMarker = false; |
|
|
|
} |
|
|
|
|
|
|
|
oldBMarks = [ state.bMarks[startLine] ]; |
|
|
|
state.bMarks[startLine] = pos; |
|
|
|
|
|
|
@ -36,7 +78,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
if (isSpace(ch)) { |
|
|
|
if (ch === 0x09) { |
|
|
|
offset += 4 - offset % 4; |
|
|
|
offset += 4 - (offset + state.bsCount[startLine] + (adjustTab ? 1 : 0)) % 4; |
|
|
|
} else { |
|
|
|
offset++; |
|
|
|
} |
|
|
@ -47,6 +89,9 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
pos++; |
|
|
|
} |
|
|
|
|
|
|
|
oldBSCount = [ state.bsCount[startLine] ]; |
|
|
|
state.bsCount[startLine] = state.sCount[startLine] + 1 + (spaceAfterMarker ? 1 : 0); |
|
|
|
|
|
|
|
lastLineEmpty = pos >= max; |
|
|
|
|
|
|
|
oldSCount = [ state.sCount[startLine] ]; |
|
|
@ -92,12 +137,38 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
if (state.src.charCodeAt(pos++) === 0x3E/* > */) { |
|
|
|
// This line is inside the blockquote.
|
|
|
|
|
|
|
|
// skip one optional space (but not tab, check cmark impl) after '>'
|
|
|
|
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]); |
|
|
|
|
|
|
|
// skip one optional space after '>'
|
|
|
|
if (state.src.charCodeAt(pos) === 0x20 /* space */) { |
|
|
|
// ' > test '
|
|
|
|
// ^ -- position start of line here:
|
|
|
|
pos++; |
|
|
|
initial++; |
|
|
|
offset++; |
|
|
|
adjustTab = false; |
|
|
|
spaceAfterMarker = true; |
|
|
|
} else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { |
|
|
|
spaceAfterMarker = true; |
|
|
|
|
|
|
|
if ((state.bsCount[nextLine] + offset) % 4 === 3) { |
|
|
|
// ' >\t test '
|
|
|
|
// ^ -- position start of line here (tab has width===1)
|
|
|
|
pos++; |
|
|
|
initial++; |
|
|
|
offset++; |
|
|
|
adjustTab = false; |
|
|
|
} else { |
|
|
|
// ' >\t test '
|
|
|
|
// ^ -- position start of line here + shift bsCount slightly
|
|
|
|
// to make extra space appear
|
|
|
|
adjustTab = true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
spaceAfterMarker = false; |
|
|
|
} |
|
|
|
|
|
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
|
state.bMarks[nextLine] = pos; |
|
|
|
|
|
|
@ -106,7 +177,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
if (isSpace(ch)) { |
|
|
|
if (ch === 0x09) { |
|
|
|
offset += 4 - offset % 4; |
|
|
|
offset += 4 - (offset + state.bsCount[nextLine] + (adjustTab ? 1 : 0)) % 4; |
|
|
|
} else { |
|
|
|
offset++; |
|
|
|
} |
|
|
@ -119,6 +190,9 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
lastLineEmpty = pos >= max; |
|
|
|
|
|
|
|
oldBSCount.push(state.bsCount[nextLine]); |
|
|
|
state.bsCount[nextLine] = state.sCount[nextLine] + 1 + (spaceAfterMarker ? 1 : 0); |
|
|
|
|
|
|
|
oldSCount.push(state.sCount[nextLine]); |
|
|
|
state.sCount[nextLine] = offset - initial; |
|
|
|
|
|
|
@ -141,6 +215,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
if (terminate) { break; } |
|
|
|
|
|
|
|
oldBMarks.push(state.bMarks[nextLine]); |
|
|
|
oldBSCount.push(state.bsCount[nextLine]); |
|
|
|
oldTShift.push(state.tShift[nextLine]); |
|
|
|
oldSCount.push(state.sCount[nextLine]); |
|
|
|
|
|
|
@ -167,6 +242,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
state.bMarks[i + startLine] = oldBMarks[i]; |
|
|
|
state.tShift[i + startLine] = oldTShift[i]; |
|
|
|
state.sCount[i + startLine] = oldSCount[i]; |
|
|
|
state.bsCount[i + startLine] = oldBSCount[i]; |
|
|
|
} |
|
|
|
state.blkIndent = oldIndent; |
|
|
|
|
|
|
|