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.
78 lines
2.2 KiB
78 lines
2.2 KiB
// Process ~~deleted text~~
|
|
|
|
'use strict';
|
|
|
|
module.exports = function del(state, silent) {
|
|
var found,
|
|
pos,
|
|
max = state.posMax,
|
|
start = state.pos,
|
|
lastChar,
|
|
nextChar;
|
|
|
|
if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; }
|
|
if (start + 4 >= max) { return false; }
|
|
if (state.src.charCodeAt(start + 1) !== 0x7E/* ~ */) { return false; }
|
|
|
|
// make del lower a priority tag with respect to links, same as <em>;
|
|
// this code also prevents recursion
|
|
if (silent && state.isInLabel) { return false; }
|
|
|
|
if (state.level >= state.options.maxNesting) { return false; }
|
|
|
|
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
|
|
nextChar = state.src.charCodeAt(start + 2);
|
|
|
|
if (lastChar === 0x7E/* ~ */) { return false; }
|
|
if (nextChar === 0x7E/* ~ */) { return false; }
|
|
if (nextChar === 0x20 || nextChar === 0x0A) { return false; }
|
|
|
|
pos = start + 2;
|
|
while (pos < max && state.src.charCodeAt(pos) === 0x7E/* ~ */) { pos++; }
|
|
if (pos !== start + 2) {
|
|
// sequence of 3+ markers taking as literal, same as in a emphasis
|
|
state.pos += pos - start;
|
|
if (!silent) { state.pending += state.src.slice(start, pos); }
|
|
return true;
|
|
}
|
|
|
|
state.pos = start + 2;
|
|
|
|
while (state.pos + 1 < max) {
|
|
if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) {
|
|
if (state.src.charCodeAt(state.pos + 1) === 0x7E/* ~ */) {
|
|
lastChar = state.src.charCodeAt(state.pos - 1);
|
|
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
|
|
if (nextChar !== 0x7E/* ~ */ && lastChar !== 0x7E/* ~ */) {
|
|
if (lastChar !== 0x20 && lastChar !== 0x0A) {
|
|
// closing '~~'
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
state.parser.skipToken(state);
|
|
}
|
|
|
|
if (!found) {
|
|
// parser failed to find ending tag, so it's not valid emphasis
|
|
state.pos = start;
|
|
return false;
|
|
}
|
|
|
|
// found!
|
|
state.posMax = state.pos;
|
|
state.pos = start + 2;
|
|
|
|
if (!silent) {
|
|
state.push({ type: 'del_open', level: state.level++ });
|
|
state.parser.tokenize(state);
|
|
state.push({ type: 'del_close', level: --state.level });
|
|
}
|
|
|
|
state.pos = state.posMax + 2;
|
|
state.posMax = max;
|
|
return true;
|
|
};
|
|
|