Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed https://markdown-it.github.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
1.6 KiB

// Block quotes
'use strict';
var getLines = require('../helpers').getLines;
var isEmpty = require('../helpers').isEmpty;
module.exports = function blockquote(state, startLine, endLine, silent) {
var nextLine, subState, insideLines, lineMax,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
if (pos > max) { return false; }
// check the block quote marker
if (state.src.charCodeAt(pos++) !== 0x3E/* > */) { return false; }
// we know that it's going to be a valid blockquote,
// so no point trying to find the end of it in silent mode
if (silent) { return true; }
lineMax = state.lineMax;
insideLines = 1;
state.tokens.push({ type: 'blockquote_open' });
nextLine = startLine + 1;
for (;;) {
if (nextLine < lineMax) {
pos = state.bMarks[nextLine] + state.tShift[nextLine];
max = state.eMarks[nextLine];
if (pos < max && state.src.charCodeAt(pos++) === 0x3E/* > */) {
if (nextLine >= endLine) { break; }
nextLine++;
insideLines++;
continue;
}
}
if (insideLines === 0) { break; }
while (nextLine < lineMax) {
if (isEmpty(state, nextLine)) { break; }
nextLine++;
}
subState = state.clone(getLines(state, startLine, nextLine, 0, true)
.replace(/^ {0,3}> ?/mg, ''));
state.lexerBlock.tokenize(subState, 0, insideLines);
nextLine = startLine = subState.line + startLine;
insideLines = 0;
}
state.tokens.push({ type: 'blockquote_close' });
state.line = nextLine;
return true;
};