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.
 
 
 

55 lines
1.3 KiB

// lheading (---, ===)
'use strict';
module.exports = function lheading(state, startLine, endLine/*, silent*/) {
var marker, pos, max,
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;
state.tokens.push({
type: 'heading_open',
hLevel: marker === 0x3D/* = */ ? 1 : 2,
lines: [ startLine, state.line ],
level: state.level
});
state.tokens.push({
type: 'inline',
content: state.src.slice(pos, state.eMarks[startLine]).trim(),
level: state.level + 1,
lines: [ startLine, state.line - 1 ],
children: []
});
state.tokens.push({
type: 'heading_close',
hLevel: marker === 0x3D/* = */ ? 1 : 2,
level: state.level
});
return true;
};