Browse Source

Perf: fixed speed regression by linkifier

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
91454dcafa
  1. 10
      lib/rules_text/linkify.js

10
lib/rules_text/linkify.js

@ -8,6 +8,8 @@
var Autolinker = require('autolinker'); var Autolinker = require('autolinker');
var LINK_SCAN_RE = /www|\:\/\//;
var links = []; var links = [];
var autolinker = new Autolinker({ var autolinker = new Autolinker({
stripPrefix: false, stripPrefix: false,
@ -41,10 +43,9 @@ module.exports = function linkify(t, state) {
// Skip content of markdown links // Skip content of markdown links
if (token.type === 'link_close') { if (token.type === 'link_close') {
i--; i--;
while (tokens[i].type !== 'link_open' && tokens[i].level !== token.level) { while (tokens[i].level !== token.level && tokens[i].type !== 'link_open') {
i--; i--;
} }
i--;
continue; continue;
} }
@ -59,9 +60,8 @@ module.exports = function linkify(t, state) {
} }
if (htmlLinkLevel > 0) { continue; } if (htmlLinkLevel > 0) { continue; }
if (token.type === 'text' && if (token.type === 'text' && LINK_SCAN_RE.test(token.content)) {
(token.content.indexOf('://') ||
token.content.indexOf('www'))) {
text = token.content; text = token.content;
links = []; links = [];
autolinker.link(text); autolinker.link(text);

Loading…
Cancel
Save