|
|
@ -4,7 +4,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function heading(state, startLine, endLine, silent) { |
|
|
|
var ch, level, |
|
|
|
var ch, level, tmp, |
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
|
max = state.eMarks[startLine]; |
|
|
|
|
|
|
@ -24,27 +24,16 @@ module.exports = function heading(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
if (level > 6 || (pos < max && ch !== 0x20/* space */)) { return false; } |
|
|
|
|
|
|
|
// skip spaces before heading text
|
|
|
|
pos = state.skipSpaces(pos); |
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
// Now pos contains offset of first heared char
|
|
|
|
// Let's cut tails like ' ### ' from the end of string
|
|
|
|
|
|
|
|
max = state.skipCharsBack(max, 0x20/* space */, pos); |
|
|
|
max = state.skipCharsBack(max, 0x23/* # */, pos); |
|
|
|
|
|
|
|
if (max < state.eMarks[startLine] && |
|
|
|
state.src.charCodeAt(max) === 0x23/* # */ && |
|
|
|
state.src.charCodeAt(max - 1) === 0x5C/* \ */) { |
|
|
|
max++; |
|
|
|
tmp = state.skipCharsBack(max, 0x23/* # */, pos); |
|
|
|
if (tmp > pos && state.src.charCodeAt(tmp - 1) === 0x20/* space */) { |
|
|
|
max = tmp; |
|
|
|
} |
|
|
|
|
|
|
|
// ## Foo ####
|
|
|
|
// ^^^
|
|
|
|
max = state.skipCharsBack(max, 0x20/* space */, pos); |
|
|
|
|
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
state.line = startLine + 1; |
|
|
|
|
|
|
|
state.tokens.push({ type: 'heading_open', |
|
|
|