mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
dependencies: Upgrade markdown from 2.6.11 -> 3.0.1.
This is a major upgrade, and requires some significant compatibility work: * Migrating the pattern-removal logic to use the Registry feature. * Handling the removal of positional arguments in markdown extensions. * Handling the removal of safe mode.
This commit is contained in:
committed by
Tim Abbott
parent
73eed42b3c
commit
b7c5ae7bca
@@ -12,7 +12,7 @@ mypy_extensions==0.4.1
|
|||||||
Jinja2==2.10
|
Jinja2==2.10
|
||||||
|
|
||||||
# Needed for markdown processing
|
# Needed for markdown processing
|
||||||
Markdown==2.6.11
|
Markdown==3.0.1
|
||||||
MarkupSafe==1.1.0
|
MarkupSafe==1.1.0
|
||||||
Pygments==2.3.1
|
Pygments==2.3.1
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ jsondiff==1.1.1 # via moto
|
|||||||
jsonpickle==1.0 # via aws-xray-sdk, python-digitalocean
|
jsonpickle==1.0 # via aws-xray-sdk, python-digitalocean
|
||||||
lxml==4.3.0
|
lxml==4.3.0
|
||||||
markdown-include==0.5.1
|
markdown-include==0.5.1
|
||||||
markdown==2.6.11
|
markdown==3.0.1
|
||||||
markupsafe==1.1.0
|
markupsafe==1.1.0
|
||||||
matrix-client==0.3.2
|
matrix-client==0.3.2
|
||||||
mock==2.0.0
|
mock==2.0.0
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ jedi==0.13.2 # via ipython
|
|||||||
jinja2==2.10
|
jinja2==2.10
|
||||||
lxml==4.3.0
|
lxml==4.3.0
|
||||||
markdown-include==0.5.1
|
markdown-include==0.5.1
|
||||||
markdown==2.6.11
|
markdown==3.0.1
|
||||||
markupsafe==1.1.0
|
markupsafe==1.1.0
|
||||||
matrix-client==0.3.2
|
matrix-client==0.3.2
|
||||||
mock==2.0.0
|
mock==2.0.0
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ LATEST_RELEASE_ANNOUNCEMENT = "https://blog.zulip.org/2018/11/07/zulip-1-9-relea
|
|||||||
# Typically, adding a dependency only requires a minor version bump, and
|
# Typically, adding a dependency only requires a minor version bump, and
|
||||||
# removing a dependency requires a major version bump.
|
# removing a dependency requires a major version bump.
|
||||||
|
|
||||||
PROVISION_VERSION = '26.22'
|
PROVISION_VERSION = '27.0'
|
||||||
|
|||||||
@@ -1436,6 +1436,25 @@ class LinkPattern(markdown.inlinepatterns.Pattern):
|
|||||||
fixup_link(el, target_blank=(href[:1] != '#'))
|
fixup_link(el, target_blank=(href[:1] != '#'))
|
||||||
return el
|
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.
|
||||||
|
def get_link_re() -> str:
|
||||||
|
NOBRACKET = r'[^\]\[]*'
|
||||||
|
BRK = (
|
||||||
|
r'\[(' +
|
||||||
|
(NOBRACKET + r'(\[')*6 +
|
||||||
|
(NOBRACKET + r'\])*')*6 +
|
||||||
|
NOBRACKET + r')\]'
|
||||||
|
)
|
||||||
|
NOIMG = r'(?<!\!)'
|
||||||
|
|
||||||
|
# [text](url) or [text](<url>) or [text](url "title")
|
||||||
|
LINK_RE = NOIMG + BRK + \
|
||||||
|
r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\12\s*)?\)'''
|
||||||
|
return LINK_RE
|
||||||
|
|
||||||
def prepare_realm_pattern(source: str) -> str:
|
def prepare_realm_pattern(source: str) -> str:
|
||||||
""" Augment a realm filter so it only matches after start-of-string,
|
""" Augment a realm filter so it only matches after start-of-string,
|
||||||
whitespace, or opening delimiters, won't match if there are word
|
whitespace, or opening delimiters, won't match if there are word
|
||||||
@@ -1595,6 +1614,15 @@ class AtomicLinkPattern(LinkPattern):
|
|||||||
ret.text = markdown.util.AtomicString(ret.text)
|
ret.text = markdown.util.AtomicString(ret.text)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def get_sub_registry(r: markdown.util.Registry, keys: List[str]) -> markdown.util.Registry:
|
||||||
|
# Registry is a new class added by py-markdown to replace Ordered List.
|
||||||
|
# Since Registry doesn't support .keys(), it is easier to make a new
|
||||||
|
# object instead of removing keys from the existing object.
|
||||||
|
new_r = markdown.util.Registry()
|
||||||
|
for k in keys:
|
||||||
|
new_r.register(r[k], k, r.get_index_for_name(k))
|
||||||
|
return new_r
|
||||||
|
|
||||||
# These are used as keys ("realm_filters_keys") to md_engines and the respective
|
# These are used as keys ("realm_filters_keys") to md_engines and the respective
|
||||||
# realm filter caches
|
# realm filter caches
|
||||||
DEFAULT_BUGDOWN_KEY = -1
|
DEFAULT_BUGDOWN_KEY = -1
|
||||||
@@ -1622,8 +1650,10 @@ class Bugdown(markdown.Extension):
|
|||||||
for k in ('image_link', 'image_reference', 'automail',
|
for k in ('image_link', 'image_reference', 'automail',
|
||||||
'autolink', 'link', 'reference', 'short_reference',
|
'autolink', 'link', 'reference', 'short_reference',
|
||||||
'escape', 'strong_em', 'emphasis', 'emphasis2',
|
'escape', 'strong_em', 'emphasis', 'emphasis2',
|
||||||
'linebreak', 'strong', 'backtick'):
|
'linebreak', 'strong', 'backtick', 'em_strong',
|
||||||
del md.inlinePatterns[k]
|
'strong2'):
|
||||||
|
md.inlinePatterns.deregister(k)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# linebreak2 was removed upstream in version 3.2.1, so
|
# linebreak2 was removed upstream in version 3.2.1, so
|
||||||
# don't throw an error if it is not there
|
# don't throw an error if it is not there
|
||||||
@@ -1719,7 +1749,7 @@ class Bugdown(markdown.Extension):
|
|||||||
md.inlinePatterns.add('unicodeemoji', UnicodeEmoji(unicode_emoji_regex), '_end')
|
md.inlinePatterns.add('unicodeemoji', UnicodeEmoji(unicode_emoji_regex), '_end')
|
||||||
|
|
||||||
def extend_misc(self, md: markdown.Markdown) -> None:
|
def extend_misc(self, md: markdown.Markdown) -> None:
|
||||||
md.inlinePatterns.add('link', AtomicLinkPattern(markdown.inlinepatterns.LINK_RE, md), '>avatar')
|
md.inlinePatterns.add('link', AtomicLinkPattern(get_link_re(), md), '>avatar')
|
||||||
|
|
||||||
for (pattern, format_string, id) in self.getConfig("realm_filters"):
|
for (pattern, format_string, id) in self.getConfig("realm_filters"):
|
||||||
md.inlinePatterns.add('realm_filters/%s' % (pattern,),
|
md.inlinePatterns.add('realm_filters/%s' % (pattern,),
|
||||||
@@ -1745,18 +1775,17 @@ class Bugdown(markdown.Extension):
|
|||||||
# users' traffic that is mirrored. Note that
|
# users' traffic that is mirrored. Note that
|
||||||
# inline_interesting_links is a treeprocessor and thus is
|
# inline_interesting_links is a treeprocessor and thus is
|
||||||
# not removed
|
# not removed
|
||||||
for k in list(md.inlinePatterns.keys()):
|
md.inlinePatterns = get_sub_registry(md.inlinePatterns, ['autolink'])
|
||||||
if k not in ["autolink"]:
|
md.treeprocessors = get_sub_registry(md.treeprocessors,
|
||||||
del md.inlinePatterns[k]
|
['inline_interesting_links',
|
||||||
for k in list(md.treeprocessors.keys()):
|
'rewrite_to_https'])
|
||||||
if k not in ["inline_interesting_links", "inline", "rewrite_to_https"]:
|
# insert new 'inline' processor because we have changed md.inlinePatterns
|
||||||
del md.treeprocessors[k]
|
# but InlineProcessor copies md as self.md in __init__.
|
||||||
for k in list(md.preprocessors.keys()):
|
md.treeprocessors.add('inline',
|
||||||
if k not in ["custom_text_notifications"]:
|
markdown.treeprocessors.InlineProcessor(md),
|
||||||
del md.preprocessors[k]
|
'>inline_interesting_links')
|
||||||
for k in list(md.parser.blockprocessors.keys()):
|
md.preprocessors = get_sub_registry(md.preprocessors, ['custom_text_notifications'])
|
||||||
if k not in ["paragraph"]:
|
md.parser.blockprocessors = get_sub_registry(md.parser.blockprocessors, ['paragraph'])
|
||||||
del md.parser.blockprocessors[k]
|
|
||||||
|
|
||||||
md_engines = {} # type: Dict[Tuple[int, bool], markdown.Markdown]
|
md_engines = {} # type: Dict[Tuple[int, bool], markdown.Markdown]
|
||||||
realm_filter_data = {} # type: Dict[int, List[Tuple[str, str, int]]]
|
realm_filter_data = {} # type: Dict[int, List[Tuple[str, str, int]]]
|
||||||
|
|||||||
@@ -158,4 +158,4 @@ class APICodeExamplesPreprocessor(Preprocessor):
|
|||||||
return fixture
|
return fixture
|
||||||
|
|
||||||
def makeExtension(*args: Any, **kwargs: str) -> APICodeExamplesGenerator:
|
def makeExtension(*args: Any, **kwargs: str) -> APICodeExamplesGenerator:
|
||||||
return APICodeExamplesGenerator(kwargs)
|
return APICodeExamplesGenerator(**kwargs)
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
|
|||||||
return "\n\n".join(tex_paragraphs)
|
return "\n\n".join(tex_paragraphs)
|
||||||
|
|
||||||
def placeholder(self, code: str) -> str:
|
def placeholder(self, code: str) -> str:
|
||||||
return self.markdown.htmlStash.store(code, safe=True)
|
return self.markdown.htmlStash.store(code)
|
||||||
|
|
||||||
def _escape(self, txt: str) -> str:
|
def _escape(self, txt: str) -> str:
|
||||||
""" basic html escaping """
|
""" basic html escaping """
|
||||||
|
|||||||
@@ -72,4 +72,4 @@ class NestedCodeBlocksRendererTreeProcessor(markdown.treeprocessors.Treeprocesso
|
|||||||
parent.remove(element_to_replace)
|
parent.remove(element_to_replace)
|
||||||
|
|
||||||
def makeExtension(*args: Any, **kwargs: str) -> NestedCodeBlocksRenderer:
|
def makeExtension(*args: Any, **kwargs: str) -> NestedCodeBlocksRenderer:
|
||||||
return NestedCodeBlocksRenderer(kwargs)
|
return NestedCodeBlocksRenderer(**kwargs)
|
||||||
|
|||||||
@@ -127,4 +127,4 @@ class TabbedSectionsPreprocessor(Preprocessor):
|
|||||||
return block
|
return block
|
||||||
|
|
||||||
def makeExtension(*args: Any, **kwargs: str) -> TabbedSectionsGenerator:
|
def makeExtension(*args: Any, **kwargs: str) -> TabbedSectionsGenerator:
|
||||||
return TabbedSectionsGenerator(kwargs)
|
return TabbedSectionsGenerator(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user