mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
bugdown: Eliminate LinkPattern class.
The only code that used LinkPattern was AtomicLinkPattern. We just move the helper method into AtomicLinkPattern.
This commit is contained in:
@@ -1431,31 +1431,6 @@ class AutoNumberOListPreprocessor(markdown.preprocessors.Preprocessor):
|
||||
|
||||
return lines
|
||||
|
||||
# Based on markdown.inlinepatterns.LinkPattern
|
||||
class LinkPattern(markdown.inlinepatterns.Pattern):
|
||||
""" Return a link element from the given match. """
|
||||
|
||||
def handleMatch(self, m: Match[str]) -> Optional[Element]:
|
||||
href = m.group(9)
|
||||
if not href:
|
||||
return None
|
||||
|
||||
if href[0] == "<":
|
||||
href = href[1:-1]
|
||||
href = sanitize_url(self.unescape(href.strip()))
|
||||
if href is None:
|
||||
return None
|
||||
|
||||
db_data = self.markdown.zulip_db_data
|
||||
href = rewrite_local_links_to_relative(db_data, href)
|
||||
|
||||
el = markdown.util.etree.Element('a')
|
||||
el.text = m.group(2)
|
||||
el.set('href', href)
|
||||
fixup_link(el, target_blank=(href[:1] != '#'))
|
||||
return el
|
||||
|
||||
|
||||
# We need the following since upgrade from py-markdown 2.6.11 to 3.0.1
|
||||
# modifies the link handling significantly. The following is taken from
|
||||
# py-markdown 2.6.11 markdown/inlinepatterns.py.
|
||||
@@ -1629,9 +1604,29 @@ class AlertWordsNotificationProcessor(markdown.preprocessors.Preprocessor):
|
||||
# This prevents realm_filters from running on the content of a
|
||||
# Markdown link, breaking up the link. This is a monkey-patch, but it
|
||||
# might be worth sending a version of this change upstream.
|
||||
class AtomicLinkPattern(LinkPattern):
|
||||
class AtomicLinkPattern(markdown.inlinepatterns.Pattern):
|
||||
def get_element(self, m: Match[str]) -> Optional[Element]:
|
||||
href = m.group(9)
|
||||
if not href:
|
||||
return None
|
||||
|
||||
if href[0] == "<":
|
||||
href = href[1:-1]
|
||||
href = sanitize_url(self.unescape(href.strip()))
|
||||
if href is None:
|
||||
return None
|
||||
|
||||
db_data = self.markdown.zulip_db_data
|
||||
href = rewrite_local_links_to_relative(db_data, href)
|
||||
|
||||
el = markdown.util.etree.Element('a')
|
||||
el.text = m.group(2)
|
||||
el.set('href', href)
|
||||
fixup_link(el, target_blank=(href[:1] != '#'))
|
||||
return el
|
||||
|
||||
def handleMatch(self, m: Match[str]) -> Optional[Element]:
|
||||
ret = LinkPattern.handleMatch(self, m)
|
||||
ret = self.get_element(m)
|
||||
if ret is None:
|
||||
return None
|
||||
if not isinstance(ret, str):
|
||||
|
||||
Reference in New Issue
Block a user