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 = {
|
var inline = {
|
||||||
escape: /^\\([\\`*{}\[\]()#+\-.!_])/,
|
escape: /^\\([\\`*{}\[\]()#+\-.!_])/,
|
||||||
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
||||||
|
gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/,
|
||||||
tag: /^<!--[^\0]*?-->|^<\/?\w+[^>]*>/,
|
tag: /^<!--[^\0]*?-->|^<\/?\w+[^>]*>/,
|
||||||
link: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\(([^\)]*)\)/,
|
link: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\(([^\)]*)\)/,
|
||||||
reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\s*\[([^\]]*)\]/,
|
reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]\s*\[([^\]]*)\]/,
|
||||||
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
||||||
strong: /^__([^\0]+?)__(?!_)|^\*\*([^\0]+?)\*\*(?!\*)/,
|
// strong: /^(__|\*\*)(?=\S)([^\0]*?\S)\1(?!\*|_)/,
|
||||||
em: /^_([^_]+)_|^\*([^*]+)\*/,
|
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]+?)``/,
|
code: /^`([^`]+)`|^``([^\0]+?)``/,
|
||||||
br: /^ {2,}\n(?!\s*$)/,
|
br: /^ {2,}\n(?!\s*$)/,
|
||||||
text: /^/
|
text: /^/
|
||||||
};
|
};
|
||||||
|
|
||||||
// hacky, but performant
|
|
||||||
inline.text = (function() {
|
inline.text = (function() {
|
||||||
var body = [];
|
var body = [];
|
||||||
|
|
||||||
@ -239,6 +242,7 @@ inline.text = (function() {
|
|||||||
return push;
|
return push;
|
||||||
})
|
})
|
||||||
('escape')
|
('escape')
|
||||||
|
('gfm_autolink')
|
||||||
('tag')
|
('tag')
|
||||||
('nolink')
|
('nolink')
|
||||||
('strong')
|
('strong')
|
||||||
@ -290,6 +294,19 @@ inline.lexer = function(str) {
|
|||||||
continue;
|
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
|
// tag
|
||||||
if (cap = inline.tag.exec(str)) {
|
if (cap = inline.tag.exec(str)) {
|
||||||
str = str.substring(cap[0].length);
|
str = str.substring(cap[0].length);
|
||||||
@ -427,7 +444,9 @@ var tok = function() {
|
|||||||
}
|
}
|
||||||
case 'code': {
|
case 'code': {
|
||||||
return '<pre><code>'
|
return '<pre><code>'
|
||||||
+ escape(token.text, true)
|
+ (token.escaped
|
||||||
|
? token.text
|
||||||
|
: escape(token.text, true))
|
||||||
+ '</code></pre>';
|
+ '</code></pre>';
|
||||||
}
|
}
|
||||||
case 'blockquote_start': {
|
case 'blockquote_start': {
|
||||||
|
@ -97,7 +97,12 @@ main:
|
|||||||
};
|
};
|
||||||
|
|
||||||
main.bench = function(name, func) {
|
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()
|
var start = Date.now()
|
||||||
, times = 1000
|
, times = 1000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user