diff --git a/lib/parser_inline.js b/lib/parser_inline.js
index 58f8351..a19a5de 100644
--- a/lib/parser_inline.js
+++ b/lib/parser_inline.js
@@ -48,14 +48,15 @@ function ParserInline() {
// returns `true` if any rule reported success
//
ParserInline.prototype.skipToken = function (state) {
- var i, cached_pos, pos = state.pos,
+ var i, pos = state.pos,
rules = this.ruler.getRules(''),
len = rules.length,
- maxNesting = state.md.options.maxNesting;
+ maxNesting = state.md.options.maxNesting,
+ cache = state.cache;
- if ((cached_pos = state.cacheGet(pos)) > 0) {
- state.pos = cached_pos;
+ if (typeof cache[pos] !== 'undefined') {
+ state.pos = cache[pos];
return;
}
@@ -63,14 +64,14 @@ ParserInline.prototype.skipToken = function (state) {
if (state.level < maxNesting) {
for (i = 0; i < len; i++) {
if (rules[i](state, true)) {
- state.cacheSet(pos, state.pos);
+ cache[pos] = state.pos;
return;
}
}
}
state.pos++;
- state.cacheSet(pos, state.pos);
+ cache[pos] = state.pos;
};
diff --git a/lib/renderer.js b/lib/renderer.js
index 201d7a0..ff4c76e 100644
--- a/lib/renderer.js
+++ b/lib/renderer.js
@@ -18,6 +18,11 @@ var escapeHtml = require('./common/utils').escapeHtml;
var default_rules = {};
+default_rules.code_inline = function (tokens, idx /*, options, env */) {
+ return '' + escapeHtml(tokens[idx].content) + '
';
+};
+
+
default_rules.code_block = function (tokens, idx /*, options, env */) {
return '
' + escapeHtml(tokens[idx].content) + '
\n';
};
@@ -176,10 +181,12 @@ Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
result += (token.nesting === -1 ? '' : '<') + token.tag;
// Encode attributes, e.g. `
' + escapeHtml(token.content) + '' + token.tag;
- }
-
result += needLf ? '>\n' : '>';
return result;
diff --git a/lib/rules_block/heading.js b/lib/rules_block/heading.js
index 48bd6b9..1cf4723 100644
--- a/lib/rules_block/heading.js
+++ b/lib/rules_block/heading.js
@@ -35,7 +35,7 @@ module.exports = function heading(state, startLine, endLine, silent) {
state.line = startLine + 1;
token = state.push('heading_open', 'h' + String(level), 1);
- token.markup = Array(level + 1).join('#');
+ token.markup = '########'.slice(0, level);
token.map = [ startLine, state.line ];
token = state.push('inline', '', 0);
@@ -44,7 +44,7 @@ module.exports = function heading(state, startLine, endLine, silent) {
token.children = [];
token = state.push('heading_close', 'h' + String(level), -1);
- token.markup = Array(level + 1).join('#');
+ token.markup = '########'.slice(0, level);
return true;
};
diff --git a/lib/rules_core/linkify.js b/lib/rules_core/linkify.js
index 7c99a7c..d55c8e7 100644
--- a/lib/rules_core/linkify.js
+++ b/lib/rules_core/linkify.js
@@ -26,7 +26,10 @@ module.exports = function linkify(state) {
if (!state.md.options.linkify) { return; }
for (j = 0, l = blockTokens.length; j < l; j++) {
- if (blockTokens[j].type !== 'inline') { continue; }
+ if (blockTokens[j].type !== 'inline' ||
+ !state.md.linkify.test(blockTokens[j].content)) {
+ continue;
+ }
tokens = blockTokens[j].children;
diff --git a/lib/rules_core/smartquotes.js b/lib/rules_core/smartquotes.js
index c0a611b..2466e78 100644
--- a/lib/rules_core/smartquotes.js
+++ b/lib/rules_core/smartquotes.js
@@ -29,7 +29,10 @@ module.exports = function smartquotes(state) {
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {
- if (state.tokens[blkIdx].type !== 'inline') { continue; }
+ if (state.tokens[blkIdx].type !== 'inline' ||
+ !QUOTE_TEST_RE.test(state.tokens[blkIdx].content)) {
+ continue;
+ }
tokens = state.tokens[blkIdx].children;
stack.length = 0;
diff --git a/lib/rules_inline/autolink.js b/lib/rules_inline/autolink.js
index f3fa67b..186355f 100644
--- a/lib/rules_inline/autolink.js
+++ b/lib/rules_inline/autolink.js
@@ -21,9 +21,9 @@ module.exports = function autolink(state, silent) {
if (tail.indexOf('>') < 0) { return false; }
- linkMatch = tail.match(AUTOLINK_RE);
+ if (AUTOLINK_RE.test(tail)) {
+ linkMatch = tail.match(AUTOLINK_RE);
- if (linkMatch) {
if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) { return false; }
url = linkMatch[0].slice(1, -1);
@@ -44,9 +44,8 @@ module.exports = function autolink(state, silent) {
return true;
}
- emailMatch = tail.match(EMAIL_RE);
-
- if (emailMatch) {
+ if (EMAIL_RE.test(tail)) {
+ emailMatch = tail.match(EMAIL_RE);
url = emailMatch[0].slice(1, -1);
diff --git a/lib/rules_inline/state_inline.js b/lib/rules_inline/state_inline.js
index fdc26b4..2a7a05f 100644
--- a/lib/rules_inline/state_inline.js
+++ b/lib/rules_inline/state_inline.js
@@ -17,7 +17,7 @@ function StateInline(src, md, env, outTokens) {
this.pending = '';
this.pendingLevel = 0;
- this.cache = []; // Stores { start: end } pairs. Useful for backtrack
+ this.cache = {}; // Stores { start: end } pairs. Useful for backtrack
// optimization of pairs parse (emphasis, strikes).
}
@@ -54,24 +54,4 @@ StateInline.prototype.push = function (type, tag, nesting) {
};
-// Store value to cache.
-// !!! Implementation has parser-specific optimizations
-// !!! keys MUST be integer, >= 0; values MUST be integer, > 0
-//
-StateInline.prototype.cacheSet = function (key, val) {
- for (var i = this.cache.length; i <= key; i++) {
- this.cache.push(0);
- }
-
- this.cache[key] = val;
-};
-
-
-// Get cache value
-//
-StateInline.prototype.cacheGet = function (key) {
- return key < this.cache.length ? this.cache[key] : 0;
-};
-
-
module.exports = StateInline;
diff --git a/lib/token.js b/lib/token.js
index 3a8451d..0daa178 100644
--- a/lib/token.js
+++ b/lib/token.js
@@ -72,7 +72,7 @@ function Token(type, tag, nesting) {
* In a case of self-closing tag (code, html, fence, etc.),
* it has contents of this tag.
**/
- this.content = null;
+ this.content = '';
/**
* Token#markup -> String
@@ -86,7 +86,7 @@ function Token(type, tag, nesting) {
*
* fence infostring
**/
- this.info = null;
+ this.info = '';
/**
* Token#block -> Boolean