|
@ -4,42 +4,67 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function lheading(state, startLine, endLine/*, silent*/) { |
|
|
module.exports = function lheading(state, startLine, endLine/*, silent*/) { |
|
|
var marker, pos, max, token, level, |
|
|
var content, terminate, i, l, token, pos, max, level, marker, |
|
|
next = startLine + 1; |
|
|
nextLine = startLine + 1, |
|
|
|
|
|
terminatorRules = state.md.block.ruler.getRules('paragraph'); |
|
|
if (next >= endLine) { return false; } |
|
|
|
|
|
if (state.sCount[next] < state.blkIndent) { return false; } |
|
|
// jump line-by-line until empty one or EOF
|
|
|
|
|
|
for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { |
|
|
// Scan next line
|
|
|
// this would be a code block normally, but after paragraph
|
|
|
|
|
|
// it's considered a lazy continuation regardless of what's there
|
|
|
if (state.sCount[next] - state.blkIndent > 3) { return false; } |
|
|
if (state.sCount[nextLine] - state.blkIndent > 3) { continue; } |
|
|
|
|
|
|
|
|
pos = state.bMarks[next] + state.tShift[next]; |
|
|
//
|
|
|
max = state.eMarks[next]; |
|
|
// Check for underline in setext header
|
|
|
|
|
|
//
|
|
|
if (pos >= max) { return false; } |
|
|
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); |
|
|
marker = state.src.charCodeAt(pos); |
|
|
|
|
|
|
|
|
if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; } |
|
|
if (marker === 0x2D/* - */ || marker === 0x3D/* = */) { |
|
|
|
|
|
|
|
|
pos = state.skipChars(pos, marker); |
|
|
pos = state.skipChars(pos, marker); |
|
|
|
|
|
|
|
|
pos = state.skipSpaces(pos); |
|
|
pos = state.skipSpaces(pos); |
|
|
|
|
|
|
|
|
if (pos < max) { return false; } |
|
|
if (pos >= max) { |
|
|
|
|
|
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
|
|
|
|
|
|
|
|
|
state.line = next + 1; |
|
|
|
|
|
level = (marker === 0x3D/* = */ ? 1 : 2); |
|
|
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 = state.push('heading_open', 'h' + String(level), 1); |
|
|
token.markup = String.fromCharCode(marker); |
|
|
token.markup = String.fromCharCode(marker); |
|
|
token.map = [ startLine, state.line ]; |
|
|
token.map = [ startLine, state.line ]; |
|
|
|
|
|
|
|
|
token = state.push('inline', '', 0); |
|
|
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.map = [ startLine, state.line - 1 ]; |
|
|
token.children = []; |
|
|
token.children = []; |
|
|
|
|
|
|
|
|