summaryrefslogtreecommitdiffstats
path: root/contrib/python/markdown-it-py/markdown_it/rules_inline/text.py
diff options
context:
space:
mode:
authoreivanov89 <[email protected]>2025-08-29 10:12:02 +0300
committereivanov89 <[email protected]>2025-08-29 10:27:27 +0300
commit140ced4d34c422c9f3cbe096f8dd35243b67d6e4 (patch)
treeb7373341f64151c0ab9839ee692dc919366590d5 /contrib/python/markdown-it-py/markdown_it/rules_inline/text.py
parent136471c8b2f3ab8cd7993200c0de0456b7018118 (diff)
Add python/textual to YDB
commit_hash:eda16a869229724fec5479fa27fa5cdbccbe0395
Diffstat (limited to 'contrib/python/markdown-it-py/markdown_it/rules_inline/text.py')
-rw-r--r--contrib/python/markdown-it-py/markdown_it/rules_inline/text.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/python/markdown-it-py/markdown_it/rules_inline/text.py b/contrib/python/markdown-it-py/markdown_it/rules_inline/text.py
new file mode 100644
index 00000000000..18b2fcc7a8f
--- /dev/null
+++ b/contrib/python/markdown-it-py/markdown_it/rules_inline/text.py
@@ -0,0 +1,62 @@
+import functools
+import re
+
+# Skip text characters for text token, place those to pending buffer
+# and increment current pos
+from .state_inline import StateInline
+
+# Rule to skip pure text
+# '{}$%@~+=:' reserved for extensions
+
+# !!!! Don't confuse with "Markdown ASCII Punctuation" chars
+# http://spec.commonmark.org/0.15/#ascii-punctuation-character
+
+
+_TerminatorChars = {
+ "\n",
+ "!",
+ "#",
+ "$",
+ "%",
+ "&",
+ "*",
+ "+",
+ "-",
+ ":",
+ "<",
+ "=",
+ ">",
+ "@",
+ "[",
+ "\\",
+ "]",
+ "^",
+ "_",
+ "`",
+ "{",
+ "}",
+ "~",
+}
+
+
+def _terminator_char_regex() -> re.Pattern[str]:
+ return re.compile("[" + re.escape("".join(_TerminatorChars)) + "]")
+
+
+def text(state: StateInline, silent: bool) -> bool:
+ pos = state.pos
+ posMax = state.posMax
+
+ terminator_char = _terminator_char_regex().search(state.src, pos)
+ pos = terminator_char.start() if terminator_char else posMax
+
+ if pos == state.pos:
+ return False
+
+ if not silent:
+ state.pending += state.src[state.pos : pos]
+
+ state.pos = pos
+
+ return True