summaryrefslogtreecommitdiff
path: root/packages/markdown-it-14.1.0/lib/rules_inline/text.mjs
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2024-05-12 12:14:02 +0700
committeraltaf-creator <dev@altafcreator.com>2024-05-12 12:14:02 +0700
commitd607ac12097afb5cb6f398a4e7b5cf4316efedc6 (patch)
tree6f4bc5b98a6ff3a1c3189f7ef9b570c0481e100d /packages/markdown-it-14.1.0/lib/rules_inline/text.mjs
parent7441f212967256ac4c9a93ba0b1f026308a8bfb6 (diff)
self host
Diffstat (limited to 'packages/markdown-it-14.1.0/lib/rules_inline/text.mjs')
-rw-r--r--packages/markdown-it-14.1.0/lib/rules_inline/text.mjs86
1 files changed, 86 insertions, 0 deletions
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;
+}; */