|
|
@ -6,11 +6,13 @@ var isSpace = require('../common/utils').isSpace; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function heading(state, startLine, endLine, silent) { |
|
|
|
var ch, level, tmp, token, |
|
|
|
var ch, level, tmp, token, originalPos, originalMax, |
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
|
max = state.eMarks[startLine]; |
|
|
|
|
|
|
|
ch = state.src.charCodeAt(pos); |
|
|
|
originalPos = pos; |
|
|
|
originalMax = max; |
|
|
|
|
|
|
|
if (ch !== 0x23/* # */ || pos >= max) { return false; } |
|
|
|
|
|
|
@ -39,14 +41,20 @@ module.exports = function heading(state, startLine, endLine, silent) { |
|
|
|
token = state.push('heading_open', 'h' + String(level), 1); |
|
|
|
token.markup = '########'.slice(0, level); |
|
|
|
token.map = [ startLine, state.line ]; |
|
|
|
token.position = originalPos; |
|
|
|
token.size = pos - originalPos; |
|
|
|
|
|
|
|
token = state.push('inline', '', 0); |
|
|
|
token.content = state.src.slice(pos, max).trim(); |
|
|
|
token.map = [ startLine, state.line ]; |
|
|
|
token.children = []; |
|
|
|
token.position = pos; |
|
|
|
token.size = max - pos; |
|
|
|
|
|
|
|
token = state.push('heading_close', 'h' + String(level), -1); |
|
|
|
token.markup = '########'.slice(0, level); |
|
|
|
token.position = max; |
|
|
|
token.size = originalMax - max; |
|
|
|
|
|
|
|
return true; |
|
|
|
}; |
|
|
|