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.
 
 
 

50 lines
1.3 KiB

// lheading (---, ===)
'use strict';
module.exports = function lheading(state, startLine, endLine/*, silent*/) {
var marker, pos, max, token, level,
next = startLine + 1;
if (next >= endLine) { return false; }
if (state.tShift[next] < state.blkIndent) { return false; }
// Scan next line
if (state.tShift[next] - state.blkIndent > 3) { return false; }
pos = state.bMarks[next] + state.tShift[next];
max = state.eMarks[next];
if (pos >= max) { return false; }
marker = state.src.charCodeAt(pos);
if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; }
pos = state.skipChars(pos, marker);
pos = state.skipSpaces(pos);
if (pos < max) { return false; }
pos = state.bMarks[startLine] + state.tShift[startLine];
state.line = next + 1;
level = (marker === 0x3D/* = */ ? 1 : 2);
token = state.push('heading_open', 'h' + String(level), 1);
token.markup = String.fromCharCode(marker);
token.map = [ startLine, state.line ];
token = state.push('inline', '', 0);
token.content = state.src.slice(pos, state.eMarks[startLine]).trim();
token.map = [ startLine, state.line - 1 ];
token.children = [];
token = state.push('heading_close', 'h' + String(level), -1);
token.markup = String.fromCharCode(marker);
return true;
};