diff --git a/lib/helpers.js b/lib/helpers.js index 087ca64..e771f9e 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -38,13 +38,15 @@ function skipChars(state, pos, code) { return pos; } -// Skip char codes reverse from given position -/*function skipCharsBack(state, pos, code, min) { - for (; pos >= min; pos--) { - if (code !== state.src.charCodeAt(pos)) { break; } +// Skip char codes reverse from given position - 1 +function skipCharsBack(state, pos, code, min) { + if (pos <= min) { return pos; } + + while (pos > min) { + if (code !== state.src.charCodeAt(--pos)) { return pos + 1; } } return pos; -}*/ +} // cut lines range from source. function getLines(state, begin, end, keepLastLF) { @@ -65,3 +67,4 @@ exports.skipEmptyLines = skipEmptyLines; exports.skipSpaces = skipSpaces; exports.skipChars = skipChars; exports.getLines = getLines; +exports.skipCharsBack = skipCharsBack; diff --git a/lib/lexer_block/lheading.js b/lib/lexer_block/lheading.js index eccf81e..80f5b68 100644 --- a/lib/lexer_block/lheading.js +++ b/lib/lexer_block/lheading.js @@ -8,34 +8,34 @@ var skipChars = require('../helpers').skipChars; module.exports = function lheading(state, startLine, endLine, silent) { - var marker, pos, mem, max, + var marker, pos, max, next = startLine + 1; if (next >= state.lineMax) { return false; } // Scan next line + if (state.tShift[next] > 3) { return false; } + pos = state.bMarks[next] + state.tShift[next]; max = state.eMarks[next]; - if (pos + 3 > max) { return false; } - marker = state.src.charCodeAt(pos); if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; } - mem = pos; pos = skipChars(state, pos, marker); - if (pos - mem < 3) { return false; } - pos = skipSpaces(state, pos); if (pos < max) { return false; } if (silent) { return true; } + pos = state.bMarks[startLine] + state.tShift[startLine]; + max = skipChars(state, state.eMarks[startLine], 0x20/* space */, pos); + state.tokens.push({ type: 'heading_open', level: marker === 0x3D/* = */ ? 1 : 2 }); - state.lexerInline.tokenize(state, state.bMarks[startLine], state.eMarks[startLine]); + state.lexerInline.tokenize(state, pos, max); state.tokens.push({ type: 'heading_close', level: marker === 0x3D/* = */ ? 1 : 2 }); state.line = next + 1; diff --git a/lib/lexer_block/paragraph.js b/lib/lexer_block/paragraph.js index 9a9c486..79d717c 100644 --- a/lib/lexer_block/paragraph.js +++ b/lib/lexer_block/paragraph.js @@ -17,7 +17,8 @@ module.exports = function paragraph(state, startLine, endLine) { if (rules_named.hr(state, nextLine, endLine, true)) { break; } if (rules_named.list(state, nextLine, endLine, true)) { break; } if (rules_named.heading(state, nextLine, endLine, true)) { break; } - if (rules_named.lheading(state, nextLine, endLine, true)) { break; } + // setex header can't interrupt paragraph + // if (rules_named.lheading(state, nextLine, endLine, true)) { break; } if (rules_named.blockquote(state, nextLine, endLine, true)) { break; } if (rules_named.table(state, nextLine, endLine, true)) { break; } //if (rules_named.tag(state, nextLine, endLine, true)) { break; } diff --git a/lib/renderer.js b/lib/renderer.js index 4fcce4f..8ac9dea 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -22,7 +22,7 @@ var rules = {}; rules.blockquote_open = function (state /*, token*/) { - state.result += '
'; + state.result += '\n'; }; rules.blockquote_close = function (state /*, token*/) { state.result += '\n'; @@ -55,7 +55,7 @@ rules.heading_close = function (state, token) { rules.hr = function (state/*, token*/) { - state.result += '
\n'; + state.result += state.options.xhtml ? '
\n' : '
\n'; };