|
|
@ -4,42 +4,67 @@ |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
var content, terminate, i, l, token, pos, max, level, marker, |
|
|
|
nextLine = startLine + 1, |
|
|
|
terminatorRules = state.md.block.ruler.getRules('paragraph'); |
|
|
|
|
|
|
|
// jump line-by-line until empty one or EOF
|
|
|
|
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
|
|
|
|
if (state.sCount[nextLine] - state.blkIndent > 3) { continue; } |
|
|
|
|
|
|
|
//
|
|
|
|
// Check for underline in setext header
|
|
|
|
//
|
|
|
|
if (state.sCount[nextLine] >= state.blkIndent) { |
|
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
|
max = state.eMarks[nextLine]; |
|
|
|
|
|
|
|
if (pos < max) { |
|
|
|
marker = state.src.charCodeAt(pos); |
|
|
|
|
|
|
|
if (marker === 0x2D/* - */ || marker === 0x3D/* = */) { |
|
|
|
pos = state.skipChars(pos, marker); |
|
|
|
pos = state.skipSpaces(pos); |
|
|
|
|
|
|
|
if (pos >= max) { |
|
|
|
level = (marker === 0x3D/* = */ ? 1 : 2); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// quirk for blockquotes, this line should already be checked by that rule
|
|
|
|
if (state.sCount[nextLine] < 0) { continue; } |
|
|
|
|
|
|
|
// 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; |
|
|
|
} |
|
|
|
} |
|
|
|
if (terminate) { break; } |
|
|
|
} |
|
|
|
|
|
|
|
if (!level) { |
|
|
|
// Didn't find valid underline
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); |
|
|
|
|
|
|
|
state.line = nextLine + 1; |
|
|
|
|
|
|
|
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.content = content; |
|
|
|
token.map = [ startLine, state.line - 1 ]; |
|
|
|
token.children = []; |
|
|
|
|
|
|
|