Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed https://markdown-it.github.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.3 KiB

// Process inline footnotes (^[...])
'use strict';
var parseLinkLabel = require('../helpers/parse_link_label');
module.exports = function footnote_inline(state, silent) {
var labelStart,
labelEnd,
footnoteId,
oldLength,
max = state.posMax,
start = state.pos;
if (start + 2 >= max) { return false; }
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x5B/* [ */) { return false; }
labelStart = start + 2;
labelEnd = parseLinkLabel(state, start + 1);
// parser failed to find ']', so it's not a valid note
if (labelEnd < 0) { return false; }
// We found the end of the link, and know for a fact it's a valid link;
// so all that's left to do is to call tokenizer.
//
if (!silent) {
if (!state.env.footnotes) { state.env.footnotes = {}; }
if (!state.env.footnotes.list) { state.env.footnotes.list = []; }
footnoteId = state.env.footnotes.list.length;
state.pos = labelStart;
state.posMax = labelEnd;
state.push({
type: 'footnote_ref',
id: footnoteId,
level: state.level
});
oldLength = state.tokens.length;
state.md.inline.tokenize(state);
state.env.footnotes.list[footnoteId] = { tokens: state.tokens.splice(oldLength) };
}
state.pos = labelEnd + 1;
state.posMax = max;
return true;
};