summaryrefslogtreecommitdiffstats
path: root/contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.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/helpers/parse_link_label.py
parent136471c8b2f3ab8cd7993200c0de0456b7018118 (diff)
Add python/textual to YDB
commit_hash:eda16a869229724fec5479fa27fa5cdbccbe0395
Diffstat (limited to 'contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.py')
-rw-r--r--contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.py b/contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.py
new file mode 100644
index 00000000000..c80da5a7ec5
--- /dev/null
+++ b/contrib/python/markdown-it-py/markdown_it/helpers/parse_link_label.py
@@ -0,0 +1,44 @@
+"""
+Parse link label
+
+this function assumes that first character ("[") already matches
+returns the end of the label
+
+"""
+
+from markdown_it.rules_inline import StateInline
+
+
+def parseLinkLabel(state: StateInline, start: int, disableNested: bool = False) -> int:
+ labelEnd = -1
+ oldPos = state.pos
+ found = False
+
+ state.pos = start + 1
+ level = 1
+
+ while state.pos < state.posMax:
+ marker = state.src[state.pos]
+ if marker == "]":
+ level -= 1
+ if level == 0:
+ found = True
+ break
+
+ prevPos = state.pos
+ state.md.inline.skipToken(state)
+ if marker == "[":
+ if prevPos == state.pos - 1:
+ # increase level if we find text `[`,
+ # which is not a part of any token
+ level += 1
+ elif disableNested:
+ state.pos = oldPos
+ return -1
+ if found:
+ labelEnd = state.pos
+
+ # restore old state
+ state.pos = oldPos
+
+ return labelEnd