diff --git a/lib/marked.js b/lib/marked.js index 4ab7728f..25109860 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -218,18 +218,21 @@ block.token = function(str, tokens) { var inline = { escape: /^\\([\\`*{}\[\]()#+\-.!_])/, autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, + gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/, tag: /^|^<\/?\w+[^>]*>/, link: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\(([^\)]*)\)/, reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, - strong: /^__([^\0]+?)__(?!_)|^\*\*([^\0]+?)\*\*(?!\*)/, - em: /^_([^_]+)_|^\*([^*]+)\*/, + // strong: /^(__|\*\*)(?=\S)([^\0]*?\S)\1(?!\*|_)/, + strong: /^__(?=\S)([^\0]*?\S)__(?!_)|^\*\*(?=\S)([^\0]*?\S)\*\*(?!\*)/, + // em: /^(_|\*)(?=\S)([^\0]*?\S)\1/, + em: /^\b_(?=\S)([^\0]*?\S)_\b|^\*(?=\S)([^\0]*?\S)\*/, + // code: /^(``?)([^\0]+?)\1/, code: /^`([^`]+)`|^``([^\0]+?)``/, br: /^ {2,}\n(?!\s*$)/, text: /^/ }; -// hacky, but performant inline.text = (function() { var body = []; @@ -239,6 +242,7 @@ inline.text = (function() { return push; }) ('escape') + ('gfm_autolink') ('tag') ('nolink') ('strong') @@ -290,6 +294,19 @@ inline.lexer = function(str) { continue; } + // gfm_autolink + if (cap = inline.gfm_autolink.exec(str)) { + str = str.substring(cap[0].length); + text = escape(cap[1]); + href = text; + out += '' + + text + + ''; + continue; + } + // tag if (cap = inline.tag.exec(str)) { str = str.substring(cap[0].length); @@ -427,7 +444,9 @@ var tok = function() { } case 'code': { return '
'
- + escape(token.text, true)
+ + (token.escaped
+ ? token.text
+ : escape(token.text, true))
+ '
';
}
case 'blockquote_start': {
diff --git a/test/index.js b/test/index.js
index d5ed9145..b529c01d 100644
--- a/test/index.js
+++ b/test/index.js
@@ -97,7 +97,12 @@ main:
};
main.bench = function(name, func) {
- if (!files) load();
+ if (!files) {
+ load();
+ Object.keys(files).forEach(function(name) {
+ if (name.indexOf('gfm') === 0) delete files[name];
+ });
+ }
var start = Date.now()
, times = 1000