|
|
|
// 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.sCount[next] < state.blkIndent) { return false; }
|
|
|
|
|
|
|
|
// Scan next line
|
|
|
|
|
|
|
|
if (state.sCount[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;
|
|
|
|
};
|