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