|
@ -164,13 +164,19 @@ function parseLinkTitle(state, pos) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function normalizeReference(str) { |
|
|
|
|
|
return str.trim().replace(/\s+/g, ' ').toLowerCase(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function links(state) { |
|
|
function links(state) { |
|
|
var labelStart, |
|
|
var labelStart, |
|
|
labelEnd, |
|
|
labelEnd, |
|
|
|
|
|
label, |
|
|
href, |
|
|
href, |
|
|
title, |
|
|
title, |
|
|
pos, |
|
|
pos, |
|
|
ref, |
|
|
ref, |
|
|
|
|
|
code, |
|
|
isImage = false, |
|
|
isImage = false, |
|
|
max = state.posMax, |
|
|
max = state.posMax, |
|
|
start = state.pos, |
|
|
start = state.pos, |
|
@ -235,7 +241,25 @@ function links(state) { |
|
|
//
|
|
|
//
|
|
|
// Link reference
|
|
|
// 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; } |
|
|
if (!ref) { return false; } |
|
|
href = ref.href; |
|
|
href = ref.href; |
|
|
title = ref.title; |
|
|
title = ref.title; |
|
@ -269,3 +293,4 @@ module.exports = links; |
|
|
module.exports.parseLinkLabel = parseLinkLabel; |
|
|
module.exports.parseLinkLabel = parseLinkLabel; |
|
|
module.exports.parseLinkDestination = parseLinkDestination; |
|
|
module.exports.parseLinkDestination = parseLinkDestination; |
|
|
module.exports.parseLinkTitle = parseLinkTitle; |
|
|
module.exports.parseLinkTitle = parseLinkTitle; |
|
|
|
|
|
module.exports.normalizeReference = normalizeReference; |
|
|