Browse Source

Remove stopOnTwoNewlines argument in block parser

Replaced with block.listMode (boolean)
pull/14/head
Alex Kocharin 11 years ago
parent
commit
1449ac720a
  1. 6
      lib/lexer_block.js
  2. 5
      lib/lexer_block/blockquote.js
  3. 4
      lib/lexer_block/list.js
  4. 1
      lib/lexer_block/state_block.js

6
lib/lexer_block.js

@ -113,7 +113,7 @@ LexerBlock.prototype.after = function (name, fn) {
// Generate tokens for input range // Generate tokens for input range
// //
LexerBlock.prototype.tokenize = function (state, startLine, endLine, stopOnTwoNewlines) { LexerBlock.prototype.tokenize = function (state, startLine, endLine) {
var ok, i, var ok, i,
rules = this.rules, rules = this.rules,
len = this.rules.length, len = this.rules.length,
@ -153,8 +153,8 @@ LexerBlock.prototype.tokenize = function (state, startLine, endLine, stopOnTwoNe
hasEmptyLines = true; hasEmptyLines = true;
line++; line++;
// two empty lines should stop the parser // two empty lines should stop the parser in list mode
if (line < endLine && stopOnTwoNewlines && isEmpty(state, line)) { break; } if (line < endLine && state.listMode && isEmpty(state, line)) { break; }
state.line = line; state.line = line;
} }
} }

5
lib/lexer_block/blockquote.js

@ -7,7 +7,7 @@ var skipSpaces = require('../helpers').skipSpaces;
module.exports = function blockquote(state, startLine, endLine, silent) { module.exports = function blockquote(state, startLine, endLine, silent) {
var nextLine, lastLineEmpty, oldTShift, oldBMarks, i, oldIndent, var nextLine, lastLineEmpty, oldTShift, oldBMarks, i, oldIndent, oldListMode,
rules_named = state.lexer.rules_named, rules_named = state.lexer.rules_named,
pos = state.bMarks[startLine] + state.tShift[startLine], pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine]; max = state.eMarks[startLine];
@ -103,9 +103,12 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
oldTShift.push(state.tShift[nextLine]); oldTShift.push(state.tShift[nextLine]);
} }
oldListMode = state.listMode;
state.listMode = false;
state.tokens.push({ type: 'blockquote_open' }); state.tokens.push({ type: 'blockquote_open' });
state.lexer.tokenize(state, startLine, nextLine); state.lexer.tokenize(state, startLine, nextLine);
state.tokens.push({ type: 'blockquote_close' }); state.tokens.push({ type: 'blockquote_close' });
state.listMode = oldListMode;
// Restore original tShift; this might not be necessary since the parser // Restore original tShift; this might not be necessary since the parser
// has already been here, but just to make sure we can do that. // has already been here, but just to make sure we can do that.

4
lib/lexer_block/list.js

@ -79,6 +79,7 @@ module.exports = function list(state, startLine, endLine, silent) {
oldTShift, oldTShift,
oldIndent, oldIndent,
oldTight, oldTight,
oldListMode,
start, start,
posAfterMarker, posAfterMarker,
max, max,
@ -163,9 +164,11 @@ module.exports = function list(state, startLine, endLine, silent) {
oldIndent = state.blkIndent; oldIndent = state.blkIndent;
oldTight = state.tight; oldTight = state.tight;
oldTShift = state.tShift[startLine]; oldTShift = state.tShift[startLine];
oldListMode = state.listMode;
state.tShift[startLine] = contentStart - state.bMarks[startLine]; state.tShift[startLine] = contentStart - state.bMarks[startLine];
state.blkIndent = indent; state.blkIndent = indent;
state.tight = true; state.tight = true;
state.listMode = true;
state.lexer.tokenize(state, startLine, endLine, true); state.lexer.tokenize(state, startLine, endLine, true);
@ -180,6 +183,7 @@ module.exports = function list(state, startLine, endLine, silent) {
state.blkIndent = oldIndent; state.blkIndent = oldIndent;
state.tShift[startLine] = oldTShift; state.tShift[startLine] = oldTShift;
state.tight = oldTight; state.tight = oldTight;
state.listMode = oldListMode;
state.tokens.push({ type: 'list_item_close' }); state.tokens.push({ type: 'list_item_close' });

1
lib/lexer_block/state_block.js

@ -83,6 +83,7 @@ function State(src, lexer, tokens, options) {
this.line = 0; // line index in src this.line = 0; // line index in src
this.lineMax = this.bMarks.length - 1; // don't count last fake line this.lineMax = this.bMarks.length - 1; // don't count last fake line
this.tight = false; // loose/tight mode for lists this.tight = false; // loose/tight mode for lists
this.listMode = false; // if true, block parser stops on two newlines
// Stuff for blockquotes // Stuff for blockquotes
this.bqLevel = 0; this.bqLevel = 0;

Loading…
Cancel
Save