|
@ -7,13 +7,14 @@ module.exports = function footnote_ref(state, silent) { |
|
|
var label, |
|
|
var label, |
|
|
pos, |
|
|
pos, |
|
|
footnoteId, |
|
|
footnoteId, |
|
|
|
|
|
footnoteSubId, |
|
|
max = state.posMax, |
|
|
max = state.posMax, |
|
|
start = state.pos; |
|
|
start = state.pos; |
|
|
|
|
|
|
|
|
// should be at least 4 chars - "[^x]"
|
|
|
// should be at least 4 chars - "[^x]"
|
|
|
if (start + 3 > max) { return false; } |
|
|
if (start + 3 > max) { return false; } |
|
|
|
|
|
|
|
|
if (!state.env.footnotes || !state.env.footnotes.available) { return false; } |
|
|
if (!state.env.footnotes || !state.env.footnotes.refs) { return false; } |
|
|
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } |
|
|
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } |
|
|
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } |
|
|
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } |
|
|
if (state.level >= state.options.maxNesting) { return false; } |
|
|
if (state.level >= state.options.maxNesting) { return false; } |
|
@ -31,19 +32,28 @@ module.exports = function footnote_ref(state, silent) { |
|
|
pos++; |
|
|
pos++; |
|
|
|
|
|
|
|
|
label = state.src.slice(start + 2, pos - 1); |
|
|
label = state.src.slice(start + 2, pos - 1); |
|
|
if (!state.env.footnotes.available[label]) { return false; } |
|
|
if (state.env.footnotes.refs[label] === undefined) { return false; } |
|
|
|
|
|
|
|
|
if (!silent) { |
|
|
if (!silent) { |
|
|
if (!state.env.footnotes.list) { state.env.footnotes.list = []; } |
|
|
if (!state.env.footnotes.list) { state.env.footnotes.list = []; } |
|
|
footnoteId = state.env.footnotes.list.length; |
|
|
|
|
|
|
|
|
if (state.env.footnotes.refs[label] < 0) { |
|
|
|
|
|
footnoteId = state.env.footnotes.list.length; |
|
|
|
|
|
state.env.footnotes.list[footnoteId] = { label: label, count: 0 }; |
|
|
|
|
|
state.env.footnotes.refs[label] = footnoteId; |
|
|
|
|
|
} else { |
|
|
|
|
|
footnoteId = state.env.footnotes.refs[label]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
footnoteSubId = state.env.footnotes.list[footnoteId].count; |
|
|
|
|
|
state.env.footnotes.list[footnoteId].count++; |
|
|
|
|
|
|
|
|
state.push({ |
|
|
state.push({ |
|
|
type: 'footnote_ref', |
|
|
type: 'footnote_ref', |
|
|
id: footnoteId, |
|
|
id: footnoteId, |
|
|
|
|
|
subId: footnoteSubId, |
|
|
level: state.level |
|
|
level: state.level |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
state.env.footnotes.list[footnoteId] = { label: label }; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.pos = pos; |
|
|
state.pos = pos; |
|
|