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.
49 lines
1.5 KiB
49 lines
1.5 KiB
10 years ago
|
// Paragraph
|
||
|
|
||
1 year ago
|
export default function paragraph(state, startLine, endLine) {
|
||
8 years ago
|
var content, terminate, i, l, token, oldParentType,
|
||
10 years ago
|
nextLine = startLine + 1,
|
||
3 years ago
|
terminatorRules = state.md.block.ruler.getRules('paragraph');
|
||
10 years ago
|
|
||
8 years ago
|
oldParentType = state.parentType;
|
||
|
state.parentType = 'paragraph';
|
||
|
|
||
10 years ago
|
// jump line-by-line until empty one or EOF
|
||
10 years ago
|
for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) {
|
||
|
// this would be a code block normally, but after paragraph
|
||
|
// it's considered a lazy continuation regardless of what's there
|
||
10 years ago
|
if (state.sCount[nextLine] - state.blkIndent > 3) { continue; }
|
||
10 years ago
|
|
||
10 years ago
|
// quirk for blockquotes, this line should already be checked by that rule
|
||
10 years ago
|
if (state.sCount[nextLine] < 0) { continue; }
|
||
10 years ago
|
|
||
10 years ago
|
// Some tags can terminate paragraph without empty line.
|
||
|
terminate = false;
|
||
|
for (i = 0, l = terminatorRules.length; i < l; i++) {
|
||
|
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
||
|
terminate = true;
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
if (terminate) { break; }
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
content = state.getLines(startLine, nextLine, state.blkIndent, false).trim();
|
||
10 years ago
|
|
||
10 years ago
|
state.line = nextLine;
|
||
10 years ago
|
|
||
|
token = state.push('paragraph_open', 'p', 1);
|
||
|
token.map = [ startLine, state.line ];
|
||
|
|
||
|
token = state.push('inline', '', 0);
|
||
|
token.content = content;
|
||
|
token.map = [ startLine, state.line ];
|
||
|
token.children = [];
|
||
|
|
||
|
token = state.push('paragraph_close', 'p', -1);
|
||
10 years ago
|
|
||
8 years ago
|
state.parentType = oldParentType;
|
||
|
|
||
10 years ago
|
return true;
|
||
1 year ago
|
}
|