better ref error handling

This commit is contained in:
Christopher Jeffrey 2011-08-21 09:31:07 -05:00
parent 8d85d8352f
commit cfe1617862

View File

@ -323,22 +323,24 @@ inline.lexer = function(str) {
break;
case 'link':
case 'reflink':
if (cap[0][0] !== '!') {
if (key === 'reflink') {
link = links[cap[2]] || links[cap[1]];
if (!link) {
out += cap[0];
break;
}
//if (!link) throw new
// Error('Undefined Reference: ' + cap[2]);
} else {
text = /^\s*([^\s]*)(?:\s+"([^"]+)")?\s*$/.exec(cap[2]);
link = {
href: text[1],
title: text[2]
};
if (key === 'reflink') {
link = links[cap[2]] || links[cap[1]];
if (!link) {
// apparently markdown says you're
// supposed to do this ...?
out += cap[0];
break;
}
//if (!link) throw new
// Error('Undefined Reference: ' + cap[2]);
} else {
text = /^\s*([^\s]*)(?:\s+"([^"]+)")?\s*$/.exec(cap[2]);
link = {
href: text[1],
title: text[2]
};
}
if (cap[0][0] !== '!') {
out += '<a href="'
+ escape(link.href)
+ '"'
@ -351,17 +353,6 @@ inline.lexer = function(str) {
+ inline.lexer(cap[1])
+ '</a>';
} else {
if (key === 'reflink') {
link = links[cap[2]];
if (!link) throw new
Error('Undefined Reference: ' + cap[2]);
} else {
text = /^\s*([^\s]*)(?:\s+"([^"]+)")?\s*$/.exec(cap[2]);
link = {
href: text[1],
title: text[2]
};
}
out += '<img src="'
+ escape(link.href)
+ '" alt="'