Browse Source

Small bugfixes

pull/14/head
Alex Kocharin 10 years ago
parent
commit
7884adfda2
  1. 2
      lib/lexer_block/paragraph.js
  2. 1
      lib/lexer_inline.js
  3. 28
      lib/lexer_inline/links.js
  4. 2
      lib/renderer.js

2
lib/lexer_block/paragraph.js

@ -39,7 +39,7 @@ module.exports = function paragraph(state, startLine/*, endLine*/) {
while ((ref = state.lexer.inline.parse_reference(content, state.options, state.env))) { while ((ref = state.lexer.inline.parse_reference(content, state.options, state.env))) {
t = state.env.references; t = state.env.references;
t[ref.label] = t[ref.label] || { title: ref.title, href: ref.href }; t[ref.label] = t[ref.label] || { title: ref.title, href: ref.href };
content = ref.remaining; content = ref.remaining.trim();
} }
if (content) { if (content) {

1
lib/lexer_inline.js

@ -205,6 +205,7 @@ LexerInline.prototype.parse_reference = function (str, options) {
pos = state.pos; pos = state.pos;
} else { } else {
title = ''; title = '';
pos = start;
} }
// ensure that the end of the line is empty // ensure that the end of the line is empty

28
lib/lexer_inline/links.js

@ -77,7 +77,7 @@ function parseLinkDestination(state, pos) {
state.pos = pos + 1; state.pos = pos + 1;
return href; return href;
} }
if (code === 0x5C /* \ */) { if (code === 0x5C /* \ */ && pos + 1 < max) {
pos++; pos++;
href += state.src[pos++]; href += state.src[pos++];
continue; continue;
@ -99,9 +99,9 @@ function parseLinkDestination(state, pos) {
if (code === 0x20) { break; } if (code === 0x20) { break; }
// ascii control characters // ascii control characters
if (code < 0x20 || code === 0x7F) { return null; } if (code < 0x20 || code === 0x7F) { break; }
if (code === 0x5C /* \ */) { if (code === 0x5C /* \ */ && pos + 1 < max) {
pos++; pos++;
href += state.src[pos++]; href += state.src[pos++];
continue; continue;
@ -109,14 +109,12 @@ function parseLinkDestination(state, pos) {
if (code === 0x28 /* ( */) { if (code === 0x28 /* ( */) {
level++; level++;
if (level > 1) { return null; } if (level > 1) { break; }
} }
if (code === 0x29 /* ) */) { if (code === 0x29 /* ) */) {
level--; level--;
if (level < 0) { if (level < 0) { break; }
break;
}
} }
href += state.src[pos++]; href += state.src[pos++];
@ -152,7 +150,7 @@ function parseLinkTitle(state, pos) {
state.pos = pos + 1; state.pos = pos + 1;
return title; return title;
} }
if (code === 0x5C /* \ */) { if (code === 0x5C /* \ */ && pos + 1 < max) {
pos++; pos++;
title += state.src[pos++]; title += state.src[pos++];
continue; continue;
@ -237,6 +235,7 @@ function links(state) {
state.pos = labelStart - 1; state.pos = labelStart - 1;
return false; return false;
} }
pos++;
} else { } else {
// //
// Link reference // Link reference
@ -252,7 +251,11 @@ function links(state) {
if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) {
start = pos + 1; start = pos + 1;
pos = parseLinkLabel(state, pos); pos = parseLinkLabel(state, pos);
label = state.src.slice(start, pos); if (pos >= 0) {
label = state.src.slice(start, pos++);
} else {
pos = start - 1;
}
} }
// covers label === '' and label === undefined // covers label === '' and label === undefined
@ -260,7 +263,10 @@ function links(state) {
if (!label) { label = state.src.slice(labelStart, labelEnd); } if (!label) { label = state.src.slice(labelStart, labelEnd); }
ref = state.env.references[normalizeReference(label)]; ref = state.env.references[normalizeReference(label)];
if (!ref) { return false; } if (!ref) {
state.pos = labelStart - 1;
return false;
}
href = ref.href; href = ref.href;
title = ref.title; title = ref.title;
} }
@ -284,7 +290,7 @@ function links(state) {
state.push({ type: 'link_close' }); state.push({ type: 'link_close' });
} }
state.pos = pos + 1; state.pos = pos;
state.posMax = max; state.posMax = max;
return true; return true;
} }

2
lib/renderer.js

@ -111,7 +111,7 @@ rules.link_close = function (/*tokens, idx, options*/) {
rules.image = function (tokens, idx, options) { rules.image = function (tokens, idx, options) {
var src = ' src="' + escapeHtmlKeepEntities(tokens[idx].src) + '"'; var src = ' src="' + escapeHtmlKeepEntities(tokens[idx].src) + '"';
var title = tokens[idx].title ? (' title="' + escapeHtmlKeepEntities(tokens[idx].title) + '"') : ''; var title = tokens[idx].title ? (' title="' + escapeHtmlKeepEntities(tokens[idx].title) + '"') : '';
var alt = tokens[idx].alt ? (' alt="' + escapeHtmlKeepEntities(tokens[idx].alt) + '"') : ''; var alt = ' alt="' + (tokens[idx].alt ? escapeHtmlKeepEntities(tokens[idx].alt) : '') + '"';
var suffix = options.xhtml ? ' /' : ''; var suffix = options.xhtml ? ' /' : '';
return '<img' + src + alt + title + suffix + '>'; return '<img' + src + alt + title + suffix + '>';
}; };

Loading…
Cancel
Save