From d607ac12097afb5cb6f398a4e7b5cf4316efedc6 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Sun, 12 May 2024 12:14:02 +0700 Subject: self host --- .../markdown-it-14.1.0/lib/rules_inline/text.mjs | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 packages/markdown-it-14.1.0/lib/rules_inline/text.mjs (limited to 'packages/markdown-it-14.1.0/lib/rules_inline/text.mjs') diff --git a/packages/markdown-it-14.1.0/lib/rules_inline/text.mjs b/packages/markdown-it-14.1.0/lib/rules_inline/text.mjs new file mode 100644 index 0000000..9be4227 --- /dev/null +++ b/packages/markdown-it-14.1.0/lib/rules_inline/text.mjs @@ -0,0 +1,86 @@ +// 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) { + let 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 `ParserInline` 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; +}; */ -- cgit v1.2.3