Browse Source

Minor assorted fixes to better match spec

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
8286880878
  1. 13
      lib/helpers.js
  2. 14
      lib/lexer_block/lheading.js
  3. 3
      lib/lexer_block/paragraph.js
  4. 4
      lib/renderer.js

13
lib/helpers.js

@ -38,13 +38,15 @@ function skipChars(state, pos, code) {
return pos; return pos;
} }
// Skip char codes reverse from given position // Skip char codes reverse from given position - 1
/*function skipCharsBack(state, pos, code, min) { function skipCharsBack(state, pos, code, min) {
for (; pos >= min; pos--) { if (pos <= min) { return pos; }
if (code !== state.src.charCodeAt(pos)) { break; }
while (pos > min) {
if (code !== state.src.charCodeAt(--pos)) { return pos + 1; }
} }
return pos; return pos;
}*/ }
// cut lines range from source. // cut lines range from source.
function getLines(state, begin, end, keepLastLF) { function getLines(state, begin, end, keepLastLF) {
@ -65,3 +67,4 @@ exports.skipEmptyLines = skipEmptyLines;
exports.skipSpaces = skipSpaces; exports.skipSpaces = skipSpaces;
exports.skipChars = skipChars; exports.skipChars = skipChars;
exports.getLines = getLines; exports.getLines = getLines;
exports.skipCharsBack = skipCharsBack;

14
lib/lexer_block/lheading.js

@ -8,34 +8,34 @@ var skipChars = require('../helpers').skipChars;
module.exports = function lheading(state, startLine, endLine, silent) { module.exports = function lheading(state, startLine, endLine, silent) {
var marker, pos, mem, max, var marker, pos, max,
next = startLine + 1; next = startLine + 1;
if (next >= state.lineMax) { return false; } if (next >= state.lineMax) { return false; }
// Scan next line // Scan next line
if (state.tShift[next] > 3) { return false; }
pos = state.bMarks[next] + state.tShift[next]; pos = state.bMarks[next] + state.tShift[next];
max = state.eMarks[next]; max = state.eMarks[next];
if (pos + 3 > max) { return false; }
marker = state.src.charCodeAt(pos); marker = state.src.charCodeAt(pos);
if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; } if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; }
mem = pos;
pos = skipChars(state, pos, marker); pos = skipChars(state, pos, marker);
if (pos - mem < 3) { return false; }
pos = skipSpaces(state, pos); pos = skipSpaces(state, pos);
if (pos < max) { return false; } if (pos < max) { return false; }
if (silent) { return true; } 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.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.tokens.push({ type: 'heading_close', level: marker === 0x3D/* = */ ? 1 : 2 });
state.line = next + 1; state.line = next + 1;

3
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.hr(state, nextLine, endLine, true)) { break; }
if (rules_named.list(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.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.blockquote(state, nextLine, endLine, true)) { break; }
if (rules_named.table(state, nextLine, endLine, true)) { break; } if (rules_named.table(state, nextLine, endLine, true)) { break; }
//if (rules_named.tag(state, nextLine, endLine, true)) { break; } //if (rules_named.tag(state, nextLine, endLine, true)) { break; }

4
lib/renderer.js

@ -22,7 +22,7 @@ var rules = {};
rules.blockquote_open = function (state /*, token*/) { rules.blockquote_open = function (state /*, token*/) {
state.result += '<blockquote>'; state.result += '<blockquote>\n';
}; };
rules.blockquote_close = function (state /*, token*/) { rules.blockquote_close = function (state /*, token*/) {
state.result += '</blockquote>\n'; state.result += '</blockquote>\n';
@ -55,7 +55,7 @@ rules.heading_close = function (state, token) {
rules.hr = function (state/*, token*/) { rules.hr = function (state/*, token*/) {
state.result += '<hr>\n'; state.result += state.options.xhtml ? '<hr />\n' : '<hr>\n';
}; };

Loading…
Cancel
Save