gfm autolinks and em underscores. more compliant strong and em.
This commit is contained in:
parent
a6a3239df8
commit
c94db866bf
@ -218,18 +218,21 @@ block.token = function(str, tokens) {
|
||||
var inline = {
|
||||
escape: /^\\([\\`*{}\[\]()#+\-.!_])/,
|
||||
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
||||
gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/,
|
||||
tag: /^<!--[^\0]*?-->|^<\/?\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 += '<a href="'
|
||||
+ href
|
||||
+ '">'
|
||||
+ text
|
||||
+ '</a>';
|
||||
continue;
|
||||
}
|
||||
|
||||
// tag
|
||||
if (cap = inline.tag.exec(str)) {
|
||||
str = str.substring(cap[0].length);
|
||||
@ -427,7 +444,9 @@ var tok = function() {
|
||||
}
|
||||
case 'code': {
|
||||
return '<pre><code>'
|
||||
+ escape(token.text, true)
|
||||
+ (token.escaped
|
||||
? token.text
|
||||
: escape(token.text, true))
|
||||
+ '</code></pre>';
|
||||
}
|
||||
case 'blockquote_start': {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user