MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / handleMatch

Method handleMatch

markdown/inlinepatterns.py:859–1038  ·  view source on GitHub ↗

Parse delimiter pattern.

(  # type: ignore[override]
        self,
        m: re.Match[str],
        data: str
    )

Source from the content-addressed store, hash-verified

857 break
858
859 def handleMatch( # type: ignore[override]
860 self,
861 m: re.Match[str],
862 data: str
863 ) -> tuple[etree.Element | None, int | None, int | None]:
864 """Parse delimiter pattern."""
865
866 # Do we have entries we haven't returned yet?
867 if self.regions:
868 return self.get_cached_result(m.start(0), data)
869
870 # If token is not an opening, quit
871 m2 = self.get_match(data, m.start(0))
872 if m2 is None or m2.lastgroup[0] == 'e': # type: ignore[index]
873 if m2 is None:
874 delim = self.delimiters[m.group(0)]
875 m2 = delim.bad.match(data, m.start(0))
876 # Advance past the full length of the delimiter found
877 return None, m2.start(0), m2.end(0)
878
879 # Get the stack and regions
880 token = data[m.start(0)]
881 delim = self.delimiters[token]
882 stack = delim.stack
883
884 start = m2.start(0)
885 end = m2.end(0)
886 length = end - start
887
888 # Double needs at least a size of 2
889 if delim.double and length < 2:
890 return None, m.start(0), m.end(0)
891
892 is_ambiguous = m2.lastgroup[0] != 's' # type: ignore[index]
893 stack.append((start, start + length, is_ambiguous, length, length))
894
895 # Pair tokens until the stack is empty or we can no longer find tokens.
896 while any(d.stack for d in self.delimiters.values()):
897 m2 = self.search(data, end)
898 if m2 is None:
899 break
900
901 token = data[m2.start(0)]
902 delim = self.delimiters[token]
903 stack = delim.stack
904
905 start = m2.start(0)
906 end = m2.end(0)
907
908 # Get current and last delimiter size
909 current = len(m2.group(0))
910
911 # Some delimiters may be ambiguous and look like both a start or an end
912 is_start = m2.lastgroup[0] != 'e' # type: ignore[index]
913 is_end = not is_start or m2.lastgroup[0] != 's' # type: ignore[index]
914 is_ambiguous = is_start and is_end
915
916 last = stack[-1][-1] if stack else 0

Callers

nothing calls this directly

Calls 9

get_cached_resultMethod · 0.95
get_matchMethod · 0.95
searchMethod · 0.95
rule_of_3Method · 0.95
add_regionMethod · 0.95
_build_elementMethod · 0.95
resetMethod · 0.95
resetMethod · 0.45

Tested by

no test coverage detected