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.
53 lines
1.0 KiB
53 lines
1.0 KiB
// Parse link label
|
|
//
|
|
// this function assumes that first character ("[") already matches;
|
|
// returns the end of the label
|
|
//
|
|
'use strict';
|
|
|
|
module.exports = function parseLinkLabel(state, start) {
|
|
var level, found, marker,
|
|
labelEnd = -1,
|
|
max = state.posMax,
|
|
oldPos = state.pos,
|
|
oldFlag = state.isInLabel;
|
|
|
|
if (state.isInLabel) { return -1; }
|
|
|
|
if (state.labelUnmatchedScopes) {
|
|
state.labelUnmatchedScopes--;
|
|
return -1;
|
|
}
|
|
|
|
state.pos = start + 1;
|
|
state.isInLabel = true;
|
|
level = 1;
|
|
|
|
while (state.pos < max) {
|
|
marker = state.src.charCodeAt(state.pos);
|
|
if (marker === 0x5B /* [ */) {
|
|
level++;
|
|
} else if (marker === 0x5D /* ] */) {
|
|
level--;
|
|
if (level === 0) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
state.parser.skipToken(state);
|
|
}
|
|
|
|
if (found) {
|
|
labelEnd = state.pos;
|
|
state.labelUnmatchedScopes = 0;
|
|
} else {
|
|
state.labelUnmatchedScopes = level - 1;
|
|
}
|
|
|
|
// restore old state
|
|
state.pos = oldPos;
|
|
state.isInLabel = oldFlag;
|
|
|
|
return labelEnd;
|
|
};
|
|
|