diff --git a/lib/index.js b/lib/index.js index 5470e80..504ea27 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,9 +20,10 @@ var config = { function StateCore(self, src, env) { this.src = src; - this.env = env; + this.env = env || {}; this.options = self.options; this.tokens = []; + this.inlineMode = false; this.inline = self.inline; this.block = self.block; @@ -97,12 +98,7 @@ Remarkable.prototype.use = function (plugin, opts) { // definitions data. // Remarkable.prototype.parse = function (src, env) { - var state; - - env = env || {}; - env.inlineMode = false; - - state = new StateCore(this, src, env); + var state = new StateCore(this, src, env); this.core.process(state); @@ -121,13 +117,9 @@ Remarkable.prototype.render = function (src, env) { // Parse content as single string // Remarkable.prototype.parseInline = function (src, env) { - var state; - - env = env || {}; - env.inlineMode = true; - - state = new StateCore(this, src, env); + var state = new StateCore(this, src, env); + state.inlineMode = true; this.core.process(state); return state.tokens; @@ -137,7 +129,6 @@ Remarkable.prototype.parseInline = function (src, env) { // Remarkable.prototype.renderInline = function (src, env) { env = env || {}; - env.inlineMode = true; return this.renderer.render(this.parseInline(src, env), this.options, env); }; diff --git a/lib/parser_block.js b/lib/parser_block.js index 2c58849..87001f6 100644 --- a/lib/parser_block.js +++ b/lib/parser_block.js @@ -114,26 +114,15 @@ ParserBlock.prototype.parse = function (src, options, env, outTokens) { }); } - if (env.inlineMode) { - outTokens.push({ - type: 'inline', - content: src.replace(/\n/g, ' ').trim(), - level: 0, - lines: [ 0, 1 ], - children: [] - }); - - } else { - state = new StateBlock( - src, - this, - options, - env, - outTokens - ); - - this.tokenize(state, state.line, state.lineMax); - } + state = new StateBlock( + src, + this, + options, + env, + outTokens + ); + + this.tokenize(state, state.line, state.lineMax); }; diff --git a/lib/rules_core/abbr.js b/lib/rules_core/abbr.js index 9ec9467..838c184 100644 --- a/lib/rules_core/abbr.js +++ b/lib/rules_core/abbr.js @@ -40,6 +40,10 @@ function parseAbbr(str, parserInline, options, env) { module.exports = function abbr(state) { var tokens = state.tokens, i, l, content, pos; + if (state.inlineMode) { + return; + } + // Parse inlines for (i = 1, l = tokens.length - 1; i < l; i++) { if (tokens[i - 1].type === 'paragraph_open' && diff --git a/lib/rules_core/block.js b/lib/rules_core/block.js index 78134eb..f3bbb6d 100644 --- a/lib/rules_core/block.js +++ b/lib/rules_core/block.js @@ -1,5 +1,17 @@ 'use strict'; module.exports = function block(state) { - state.block.parse(state.src, state.options, state.env, state.tokens); + + if (state.inlineMode) { + state.tokens.push({ + type: 'inline', + content: state.src.replace(/\n/g, ' ').trim(), + level: 0, + lines: [ 0, 1 ], + children: [] + }); + + } else { + state.block.parse(state.src, state.options, state.env, state.tokens); + } }; diff --git a/lib/rules_core/references.js b/lib/rules_core/references.js index a01336e..e393892 100644 --- a/lib/rules_core/references.js +++ b/lib/rules_core/references.js @@ -69,6 +69,10 @@ module.exports = function references(state) { state.env.references = state.env.references || {}; + if (state.inlineMode) { + return; + } + // Scan definitions in paragraph inlines for (i = 1, l = tokens.length - 1; i < l; i++) { if (tokens[i].type === 'inline' && diff --git a/test/misc.js b/test/misc.js index a66d6e9..fb0598f 100644 --- a/test/misc.js +++ b/test/misc.js @@ -51,12 +51,12 @@ describe('API', function () { }); it('configure coverage', function () { - var md = new Remarkable(); + var md = new Remarkable('full'); // conditions coverage md.configure({}); - md.render('123'); + assert.strictEqual(md.render('123'), '
123
\n'); }); it('plugin', function () { @@ -115,7 +115,6 @@ describe('API', function () { assert.strictEqual(md.render('![]()'), '\n'); assert.strictEqual(md.render('a \\\nb'), 'a
\nb