|
|
@ -164,13 +164,19 @@ function parseLinkTitle(state, pos) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
function normalizeReference(str) { |
|
|
|
return str.trim().replace(/\s+/g, ' ').toLowerCase(); |
|
|
|
} |
|
|
|
|
|
|
|
function links(state) { |
|
|
|
var labelStart, |
|
|
|
labelEnd, |
|
|
|
label, |
|
|
|
href, |
|
|
|
title, |
|
|
|
pos, |
|
|
|
ref, |
|
|
|
code, |
|
|
|
isImage = false, |
|
|
|
max = state.posMax, |
|
|
|
start = state.pos, |
|
|
@ -235,7 +241,25 @@ function links(state) { |
|
|
|
//
|
|
|
|
// Link reference
|
|
|
|
//
|
|
|
|
ref = state.env.references[state.src.slice(labelStart, labelEnd).trim().replace(/\s+/g, ' ')]; |
|
|
|
|
|
|
|
// [foo] [bar]
|
|
|
|
// ^^ optional whitespace (can include newlines)
|
|
|
|
for (; pos < max; pos++) { |
|
|
|
code = state.src.charCodeAt(pos); |
|
|
|
if (code !== 0x20 && code !== 0x0A) { break; } |
|
|
|
} |
|
|
|
|
|
|
|
if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { |
|
|
|
start = pos + 1; |
|
|
|
pos = parseLinkLabel(state, pos); |
|
|
|
label = state.src.slice(start, pos); |
|
|
|
} |
|
|
|
|
|
|
|
// covers label === '' and label === undefined
|
|
|
|
// (collapsed reference link and shortcut reference link respectively)
|
|
|
|
if (!label) { label = state.src.slice(labelStart, labelEnd); } |
|
|
|
|
|
|
|
ref = state.env.references[normalizeReference(label)]; |
|
|
|
if (!ref) { return false; } |
|
|
|
href = ref.href; |
|
|
|
title = ref.title; |
|
|
@ -269,3 +293,4 @@ module.exports = links; |
|
|
|
module.exports.parseLinkLabel = parseLinkLabel; |
|
|
|
module.exports.parseLinkDestination = parseLinkDestination; |
|
|
|
module.exports.parseLinkTitle = parseLinkTitle; |
|
|
|
module.exports.normalizeReference = normalizeReference; |
|
|
|