Browse Source

Don't modify env in inline mode

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
0c26266918
  1. 19
      lib/index.js
  2. 11
      lib/parser_block.js
  3. 4
      lib/rules_core/abbr.js
  4. 12
      lib/rules_core/block.js
  5. 4
      lib/rules_core/references.js
  6. 7
      test/misc.js

19
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);
};

11
lib/parser_block.js

@ -114,16 +114,6 @@ 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,
@ -133,7 +123,6 @@ ParserBlock.prototype.parse = function (src, options, env, outTokens) {
);
this.tokenize(state, state.line, state.lineMax);
}
};

4
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' &&

12
lib/rules_core/block.js

@ -1,5 +1,17 @@
'use strict';
module.exports = function block(state) {
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);
}
};

4
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' &&

7
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'), '<p>123</p>\n');
});
it('plugin', function () {
@ -115,7 +115,6 @@ describe('API', function () {
assert.strictEqual(md.render('![]()'), '<p><img src="" alt=""></p>\n');
assert.strictEqual(md.render('a \\\nb'), '<p>a <br>\nb</p>\n');
});
});
@ -135,7 +134,7 @@ describe('Misc', function () {
});
it('Should parse inlines only', function () {
var md = new Remarkable();
var md = new Remarkable('full');
assert.strictEqual(md.renderInline('a *b* c'), 'a <em>b</em> c');
});

Loading…
Cancel
Save