better links

This commit is contained in:
Christopher Jeffrey 2011-08-21 09:01:03 -05:00
parent a722edbf32
commit 1854c5e37c

View File

@ -92,10 +92,10 @@ block.lexer = function(str) {
// grab link definitons // grab link definitons
str = str.replace( str = str.replace(
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^"]+)")? *(?:\n|$)/gm, /^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^"]+)")? *(?:\n|$)/gm,
function(_, id, href, title) { function(__, id, href, title) {
links[id] = { links[id] = {
href: href, href: href,
title: unquote(title) title: title
}; };
return ''; return '';
} }
@ -241,8 +241,8 @@ var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!])/, escape: /^\\([\\`*{}\[\]()#+\-.!])/,
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
tag: /^<[^\n>]+>/, tag: /^<[^\n>]+>/,
link: /^!?\[([^\]]+)\]\(([^\)]+)\)/, link: /^!?\[([^\]]+)\] *\(([^\)]*)\)/,
reflink: /^!?\[([^\]]+)\]\[([^\]]+)\]/, reflink: /^!?\[([^\]]+)\] *\[([^\]]+)\]/,
strong: /^__([\s\S]+?)__|^\*\*([\s\S]+?)\*\*/, strong: /^__([\s\S]+?)__|^\*\*([\s\S]+?)\*\*/,
em: /^_([^_]+)_|^\*([^*]+)\*/, em: /^_([^_]+)_|^\*([^*]+)\*/,
code: /^`([^`]+)`|^``([\s\S]+?)``/ code: /^`([^`]+)`|^``([\s\S]+?)``/
@ -324,9 +324,10 @@ inline.lexer = function(str) {
if (!link) throw new if (!link) throw new
Error('Undefined Reference: ' + cap[2]); Error('Undefined Reference: ' + cap[2]);
} else { } else {
text = /^\s*([^\s]*)(?:\s+"([^"]+)")?\s*$/.exec(cap[2]);
link = { link = {
href: cap[2], href: text[1],
title: unquote(cap[3]) title: text[2]
}; };
} }
out += '<a href="' out += '<a href="'
@ -346,10 +347,10 @@ inline.lexer = function(str) {
if (!link) throw new if (!link) throw new
Error('Undefined Reference: ' + cap[2]); Error('Undefined Reference: ' + cap[2]);
} else { } else {
text = /^([^\s]+)\s*(.+)?$/.exec(cap[2]); text = /^\s*([^\s]*)(?:\s+"([^"]+)")?\s*$/.exec(cap[2]);
link = { link = {
href: text[1], href: text[1],
title: unquote(text[2]) title: text[2]
}; };
} }
out += '<img src="' out += '<img src="'
@ -529,9 +530,10 @@ var each = function(obj, func) {
var unquote = function(str) { var unquote = function(str) {
if (!str) return str; if (!str) return str;
var ch = str[0]; /*var ch = str[0];
return (ch === '"' || ch === '\'') return (ch === '"' || ch === '\'')
? str.slice(1, -1) : str; ? str.slice(1, -1) : str;*/
return str.replace(/^['"\s]+|['"\s]+$/g, '');
}; };
/** /**