summaryrefslogtreecommitdiffstats
path: root/contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.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/html_inline.py
parent136471c8b2f3ab8cd7993200c0de0456b7018118 (diff)
Add python/textual to YDB
commit_hash:eda16a869229724fec5479fa27fa5cdbccbe0395
Diffstat (limited to 'contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.py')
-rw-r--r--contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.py b/contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.py
new file mode 100644
index 00000000000..9065e1d034d
--- /dev/null
+++ b/contrib/python/markdown-it-py/markdown_it/rules_inline/html_inline.py
@@ -0,0 +1,43 @@
+# Process html tags
+from ..common.html_re import HTML_TAG_RE
+from ..common.utils import isLinkClose, isLinkOpen
+from .state_inline import StateInline
+
+
+def isLetter(ch: int) -> bool:
+ lc = ch | 0x20 # to lower case
+ # /* a */ and /* z */
+ return (lc >= 0x61) and (lc <= 0x7A)
+
+
+def html_inline(state: StateInline, silent: bool) -> bool:
+ pos = state.pos
+
+ if not state.md.options.get("html", None):
+ return False
+
+ # Check start
+ maximum = state.posMax
+ if state.src[pos] != "<" or pos + 2 >= maximum:
+ return False
+
+ # Quick fail on second char
+ ch = state.src[pos + 1]
+ if ch not in ("!", "?", "/") and not isLetter(ord(ch)): # /* / */
+ return False
+
+ match = HTML_TAG_RE.search(state.src[pos:])
+ if not match:
+ return False
+
+ if not silent:
+ token = state.push("html_inline", "", 0)
+ token.content = state.src[pos : pos + len(match.group(0))]
+
+ if isLinkOpen(token.content):
+ state.linkLevel += 1
+ if isLinkClose(token.content):
+ state.linkLevel -= 1
+
+ state.pos += len(match.group(0))
+ return True