mirror of https://github.com/zulip/zulip.git
markdown: Expand prepare_linkifier_pattern to make it more legible.
This commit is contained in:
parent
cc4c672773
commit
549dd8a4c4
|
@ -1812,7 +1812,24 @@ def prepare_linkifier_pattern(source: str) -> str:
|
||||||
whitespace, or opening delimiters, won't match if there are word
|
whitespace, or opening delimiters, won't match if there are word
|
||||||
characters directly after, and saves what was matched as
|
characters directly after, and saves what was matched as
|
||||||
OUTER_CAPTURE_GROUP."""
|
OUTER_CAPTURE_GROUP."""
|
||||||
return rf"""(?P<{BEFORE_CAPTURE_GROUP}>^|\s|['"\(,:<])(?P<{OUTER_CAPTURE_GROUP}>{source})(?P<{AFTER_CAPTURE_GROUP}>$|[^\pL\pN])"""
|
regex = rf"""
|
||||||
|
(?P<{BEFORE_CAPTURE_GROUP}>
|
||||||
|
^ |
|
||||||
|
\s |
|
||||||
|
['"\(,:<]
|
||||||
|
)
|
||||||
|
(?P<{OUTER_CAPTURE_GROUP}>
|
||||||
|
{source}
|
||||||
|
)
|
||||||
|
(?P<{AFTER_CAPTURE_GROUP}>
|
||||||
|
$ |
|
||||||
|
[^\pL\pN]
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
# Strip out the spaces and newlines added to make the above
|
||||||
|
# legible -- re2 does not have the equivalent of the /x modifier
|
||||||
|
# that does this automatically.
|
||||||
|
return regex.replace(" ", "").replace("\n", "")
|
||||||
|
|
||||||
|
|
||||||
# Given a regular expression pattern, linkifies groups that match it
|
# Given a regular expression pattern, linkifies groups that match it
|
||||||
|
|
Loading…
Reference in New Issue