|
|
@ -1,10 +1,10 @@ |
|
|
|
// Block lexer
|
|
|
|
// Block parser
|
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var State = require('./lexer_block/state_block'); |
|
|
|
var State = require('./rules_block/state_block'); |
|
|
|
var skipEmptyLines = require('./helpers').skipEmptyLines; |
|
|
|
var isEmpty = require('./helpers').isEmpty; |
|
|
|
|
|
|
@ -12,16 +12,16 @@ var isEmpty = require('./helpers').isEmpty; |
|
|
|
var rules = []; |
|
|
|
|
|
|
|
// `list` should be after `hr`, but before `heading`
|
|
|
|
rules.push(require('./lexer_block/code')); |
|
|
|
rules.push(require('./lexer_block/fences')); |
|
|
|
rules.push(require('./lexer_block/blockquote')); |
|
|
|
rules.push(require('./lexer_block/hr')); |
|
|
|
rules.push(require('./lexer_block/list')); |
|
|
|
rules.push(require('./lexer_block/heading')); |
|
|
|
rules.push(require('./lexer_block/lheading')); |
|
|
|
rules.push(require('./lexer_block/htmlblock')); |
|
|
|
rules.push(require('./lexer_block/table')); |
|
|
|
rules.push(require('./lexer_block/paragraph')); |
|
|
|
rules.push(require('./rules_block/code')); |
|
|
|
rules.push(require('./rules_block/fences')); |
|
|
|
rules.push(require('./rules_block/blockquote')); |
|
|
|
rules.push(require('./rules_block/hr')); |
|
|
|
rules.push(require('./rules_block/list')); |
|
|
|
rules.push(require('./rules_block/heading')); |
|
|
|
rules.push(require('./rules_block/lheading')); |
|
|
|
rules.push(require('./rules_block/htmlblock')); |
|
|
|
rules.push(require('./rules_block/table')); |
|
|
|
rules.push(require('./rules_block/paragraph')); |
|
|
|
|
|
|
|
|
|
|
|
function functionName(fn) { |
|
|
@ -41,9 +41,9 @@ function findByName(self, name) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Block Lexer class
|
|
|
|
// Block Parser class
|
|
|
|
//
|
|
|
|
function LexerBlock() { |
|
|
|
function ParserBlock() { |
|
|
|
this.rules = []; |
|
|
|
this.rules_named = {}; |
|
|
|
|
|
|
@ -53,12 +53,12 @@ function LexerBlock() { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Replace/delete lexer function
|
|
|
|
// Replace/delete parser function
|
|
|
|
//
|
|
|
|
LexerBlock.prototype.at = function (name, fn) { |
|
|
|
ParserBlock.prototype.at = function (name, fn) { |
|
|
|
var index = findByName(name); |
|
|
|
if (index === -1) { |
|
|
|
throw new Error('Lexer rule not found: ' + name); |
|
|
|
throw new Error('Parser rule not found: ' + name); |
|
|
|
} |
|
|
|
|
|
|
|
if (fn) { |
|
|
@ -71,10 +71,10 @@ LexerBlock.prototype.at = function (name, fn) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Add function to lexer chain before one with given name.
|
|
|
|
// Add function to parser chain before one with given name.
|
|
|
|
// Or add to start, if name not defined
|
|
|
|
//
|
|
|
|
LexerBlock.prototype.before = function (name, fn) { |
|
|
|
ParserBlock.prototype.before = function (name, fn) { |
|
|
|
if (!name) { |
|
|
|
this.rules.unshift(fn); |
|
|
|
this.rules_named[functionName(fn)] = fn; |
|
|
@ -83,7 +83,7 @@ LexerBlock.prototype.before = function (name, fn) { |
|
|
|
|
|
|
|
var index = findByName(name); |
|
|
|
if (index === -1) { |
|
|
|
throw new Error('Lexer rule not found: ' + name); |
|
|
|
throw new Error('Parser rule not found: ' + name); |
|
|
|
} |
|
|
|
|
|
|
|
this.rules.splice(index, 0, fn); |
|
|
@ -91,10 +91,10 @@ LexerBlock.prototype.before = function (name, fn) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Add function to lexer chain after one with given name.
|
|
|
|
// Add function to parser chain after one with given name.
|
|
|
|
// Or add to end, if name not defined
|
|
|
|
//
|
|
|
|
LexerBlock.prototype.after = function (name, fn) { |
|
|
|
ParserBlock.prototype.after = function (name, fn) { |
|
|
|
if (!name) { |
|
|
|
this.rules.push(fn); |
|
|
|
this.rules_named[functionName(fn)] = fn; |
|
|
@ -103,7 +103,7 @@ LexerBlock.prototype.after = function (name, fn) { |
|
|
|
|
|
|
|
var index = findByName(name); |
|
|
|
if (index === -1) { |
|
|
|
throw new Error('Lexer rule not found: ' + name); |
|
|
|
throw new Error('Parser rule not found: ' + name); |
|
|
|
} |
|
|
|
|
|
|
|
this.rules.splice(index + 1, 0, fn); |
|
|
@ -113,7 +113,7 @@ LexerBlock.prototype.after = function (name, fn) { |
|
|
|
|
|
|
|
// Generate tokens for input range
|
|
|
|
//
|
|
|
|
LexerBlock.prototype.tokenize = function (state, startLine, endLine) { |
|
|
|
ParserBlock.prototype.tokenize = function (state, startLine, endLine) { |
|
|
|
var ok, i, |
|
|
|
rules = this.rules, |
|
|
|
len = this.rules.length, |
|
|
@ -168,7 +168,7 @@ LexerBlock.prototype.tokenize = function (state, startLine, endLine) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
LexerBlock.prototype.parse = function (src, options, env) { |
|
|
|
ParserBlock.prototype.parse = function (src, options, env) { |
|
|
|
var state, lineStart = 0, lastTabPos = 0; |
|
|
|
|
|
|
|
if (!src) { return ''; } |
|
|
@ -217,4 +217,4 @@ LexerBlock.prototype.parse = function (src, options, env) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = LexerBlock; |
|
|
|
module.exports = ParserBlock; |