Browse Source

Deopts: fixed tables

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
5512f9cdcd
  1. 9
      benchmark/profile.js
  2. 1
      lib/rules_block/lheading.js
  3. 15
      lib/rules_block/table.js

9
benchmark/profile.js

@ -8,12 +8,13 @@ var Remarkable = require('../');
var md = new Remarkable({
html: true,
linkify: true,
typographer: true
linkify: false,
typographer: false
});
var data = fs.readFileSync(path.join(__dirname, '/samples/lorem1.txt'), 'utf8');
//var data = fs.readFileSync(path.join(__dirname, '/samples/lorem1.txt'), 'utf8');
var data = fs.readFileSync(path.join(__dirname, '../test/fixtures/stmd/spec.txt'), 'utf8');
for (var i = 0; i < 200; i++) {
for (var i = 0; i < 20; i++) {
md.render(data);
}

1
lib/rules_block/lheading.js

@ -12,6 +12,7 @@ module.exports = function lheading(state, startLine, endLine, silent) {
if (state.bqMarks[next] < state.bqLevel) { return false; }
// Scan next line
if (state.tShift[next] - state.blkIndent > 3) { return false; }
pos = state.bMarks[next] + state.tShift[next];

15
lib/rules_block/table.js

@ -12,18 +12,23 @@ function lineMatch(state, line, reg) {
module.exports = function table(state, startLine, endLine, silent) {
var ch, firstLineMatch, secondLineMatch, i, nextLine, m, rows,
var ch, firstLineMatch, secondLineMatch, pos, i, nextLine, m, rows,
aligns, t;
// should have at least three lines
if (startLine + 2 > endLine) { return false; }
if (state.tShift[startLine + 1] < state.blkIndent) { return false; }
if (state.bqMarks[startLine + 1] < state.bqLevel) { return false; }
nextLine = startLine + 1;
if (state.tShift[nextLine] < state.blkIndent) { return false; }
if (state.bqMarks[nextLine] < state.bqLevel) { return false; }
// first character of the second line should be '|' or '-'
ch = state.src.charCodeAt(state.bMarks[startLine + 1]
+ state.tShift[startLine + 1]);
pos = state.bMarks[nextLine] + state.tShift[nextLine];
if (pos >= state.eMarks[nextLine]) { return false; }
ch = state.src.charCodeAt(pos);
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */) { return false; }
secondLineMatch = lineMatch(state, startLine + 1,

Loading…
Cancel
Save