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.
86 lines
2.1 KiB
86 lines
2.1 KiB
// Skip text characters for text token, place those to pending buffer
|
|
// and increment current pos
|
|
|
|
// Rule to skip pure text
|
|
// '{}$%@~+=:' reserved for extentions
|
|
|
|
// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
|
|
|
|
// !!!! Don't confuse with "Markdown ASCII Punctuation" chars
|
|
// http://spec.commonmark.org/0.15/#ascii-punctuation-character
|
|
function isTerminatorChar(ch) {
|
|
switch (ch) {
|
|
case 0x0A/* \n */:
|
|
case 0x21/* ! */:
|
|
case 0x23/* # */:
|
|
case 0x24/* $ */:
|
|
case 0x25/* % */:
|
|
case 0x26/* & */:
|
|
case 0x2A/* * */:
|
|
case 0x2B/* + */:
|
|
case 0x2D/* - */:
|
|
case 0x3A/* : */:
|
|
case 0x3C/* < */:
|
|
case 0x3D/* = */:
|
|
case 0x3E/* > */:
|
|
case 0x40/* @ */:
|
|
case 0x5B/* [ */:
|
|
case 0x5C/* \ */:
|
|
case 0x5D/* ] */:
|
|
case 0x5E/* ^ */:
|
|
case 0x5F/* _ */:
|
|
case 0x60/* ` */:
|
|
case 0x7B/* { */:
|
|
case 0x7D/* } */:
|
|
case 0x7E/* ~ */:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export default function text(state, silent) {
|
|
var pos = state.pos;
|
|
|
|
while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) {
|
|
pos++;
|
|
}
|
|
|
|
if (pos === state.pos) { return false; }
|
|
|
|
if (!silent) { state.pending += state.src.slice(state.pos, pos); }
|
|
|
|
state.pos = pos;
|
|
|
|
return true;
|
|
}
|
|
|
|
// Alternative implementation, for memory.
|
|
//
|
|
// It costs 10% of performance, but allows extend terminators list, if place it
|
|
// to `ParcerInline` property. Probably, will switch to it sometime, such
|
|
// flexibility required.
|
|
|
|
/*
|
|
var TERMINATOR_RE = /[\n!#$%&*+\-:<=>@[\\\]^_`{}~]/;
|
|
|
|
module.exports = function text(state, silent) {
|
|
var pos = state.pos,
|
|
idx = state.src.slice(pos).search(TERMINATOR_RE);
|
|
|
|
// first char is terminator -> empty text
|
|
if (idx === 0) { return false; }
|
|
|
|
// no terminator -> text till end of string
|
|
if (idx < 0) {
|
|
if (!silent) { state.pending += state.src.slice(pos); }
|
|
state.pos = state.src.length;
|
|
return true;
|
|
}
|
|
|
|
if (!silent) { state.pending += state.src.slice(pos, pos + idx); }
|
|
|
|
state.pos += idx;
|
|
|
|
return true;
|
|
};*/
|
|
|