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.
58 lines
1.2 KiB
58 lines
1.2 KiB
// Process ^superscript^
|
|
|
|
'use strict';
|
|
|
|
// same as UNESCAPE_MD_RE plus a space
|
|
var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
|
|
|
|
module.exports = function sup(state, silent) {
|
|
var found,
|
|
content,
|
|
max = state.posMax,
|
|
start = state.pos;
|
|
|
|
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; }
|
|
if (silent) { return false; } // don't run any pairs in validation mode
|
|
if (start + 2 >= max) { return false; }
|
|
if (state.level >= state.options.maxNesting) { return false; }
|
|
|
|
state.pos = start + 1;
|
|
|
|
while (state.pos < max) {
|
|
if (state.src.charCodeAt(state.pos) === 0x5E/* ^ */) {
|
|
found = true;
|
|
break;
|
|
}
|
|
|
|
state.parser.skipToken(state);
|
|
}
|
|
|
|
if (!found || start + 1 === state.pos) {
|
|
state.pos = start;
|
|
return false;
|
|
}
|
|
|
|
content = state.src.slice(start + 1, state.pos);
|
|
|
|
// don't allow unescaped spaces/newlines inside
|
|
if (content.match(/(^|[^\\])(\\\\)*\s/)) {
|
|
state.pos = start;
|
|
return false;
|
|
}
|
|
|
|
// found!
|
|
state.posMax = state.pos;
|
|
state.pos = start + 1;
|
|
|
|
if (!silent) {
|
|
state.push({
|
|
type: 'sup',
|
|
level: state.level,
|
|
content: content.replace(UNESCAPE_RE, '$1')
|
|
});
|
|
}
|
|
|
|
state.pos = state.posMax + 1;
|
|
state.posMax = max;
|
|
return true;
|
|
};
|
|
|