markdown: Expand prepare_linkifier_pattern to make it more legible.

This commit is contained in:
Alex Vandiver 2023-11-14 19:09:09 +00:00 committed by Tim Abbott
parent cc4c672773
commit 549dd8a4c4
1 changed files with 18 additions and 1 deletions

View File

@ -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