You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2022/02/11 17:36:42 UTC

[allura] 05/12: [#8408] start Markdown upgrade, simple cleanups

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit bd547f9770d19e3c02a4b9c119ad7db9069fb503
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Fri Jan 14 13:21:30 2022 -0500

    [#8408] start Markdown upgrade, simple cleanups
---
 Allura/allura/lib/app_globals.py         |  6 +++---
 Allura/allura/lib/markdown_extensions.py | 22 +++++-----------------
 Allura/allura/lib/search.py              |  2 +-
 Allura/allura/tests/test_globals.py      | 17 +++++++++++++++++
 Allura/allura/tests/test_markdown.py     |  2 +-
 requirements.in                          |  2 +-
 requirements.txt                         |  2 +-
 7 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 84c32fa..e6f703a 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -85,7 +85,7 @@ class ForgeMarkdown(markdown.Markdown):
             escaped = cgi.escape(h.really_unicode(source))
             return Markup('<pre>%s</pre>' % escaped)
         try:
-            return markdown.Markdown.convert(self, source)
+            return super().convert(source)
         except Exception:
             log.info('Invalid markdown: %s  Upwards trace is %s', source,
                      ''.join(traceback.format_stack()), exc_info=True)
@@ -451,7 +451,7 @@ class Globals(object):
                         ForgeExtension(**kwargs), EmojiExtension(), UserMentionExtension(),
                         'markdown.extensions.tables', 'markdown.extensions.toc', 'markdown.extensions.nl2br',
                         'markdown_checklist.extension'],
-            output_format='html4')
+            output_format='html')
 
     @property
     def markdown(self):
@@ -473,7 +473,7 @@ class Globals(object):
         """
         app = getattr(c, 'app', None)
         return ForgeMarkdown(extensions=[CommitMessageExtension(app), EmojiExtension(), 'markdown.extensions.nl2br'],
-                             output_format='html4')
+                             output_format='html')
 
     @property
     def production_mode(self):
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index ba36796..074ac48 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -247,7 +247,7 @@ class ForgeExtension(markdown.Extension):
         self._is_email = email
         self._macro_context = macro_context
 
-    def extendMarkdown(self, md, md_globals):
+    def extendMarkdown(self, md):
         md.registerExtension(self)
         md.preprocessors.add('macro_include', ForgeMacroIncludePreprocessor(md), '_end')
         # this has to be before the 'escape' processor, otherwise weird
@@ -277,20 +277,14 @@ class ForgeExtension(markdown.Extension):
 
 class EmojiExtension(markdown.Extension):
 
-    EMOJI_RE = '(%s[a-zA-Z0-9\+\-_&.ô’Åéãíç()!#*]+%s)' % (':', ':')
-
-    def __init__(self, **kwargs):
-        markdown.Extension.__init__(self)
+    EMOJI_RE = r'(:[a-zA-Z0-9\+\-_&.ô’Åéãíç()!#\*]+:)'
 
-    def extendMarkdown(self, md, md_globals):
+    def extendMarkdown(self, md):
         md.inlinePatterns["emoji"] = EmojiInlinePattern(self.EMOJI_RE)
 
 
 class EmojiInlinePattern(markdown.inlinepatterns.Pattern):
-    
-    def __init__(self, pattern):
-        markdown.inlinepatterns.Pattern.__init__(self, pattern)
-        
+
     def handleMatch(self, m):
         emoji_code = m.group(2)
         return emoji.emojize(emoji_code, use_aliases=True)
@@ -300,18 +294,12 @@ class UserMentionExtension(markdown.Extension):
 
     UM_RE = r'\B(@(?![0-9]+$)(?!-)[a-z0-9_-]{2,14}[a-z0-9_])'
 
-    def __init__(self, **kwargs):
-        markdown.Extension.__init__(self)
-
-    def extendMarkdown(self, md, md_globals):
+    def extendMarkdown(self, md):
         md.inlinePatterns["user_mentions"] = UserMentionInlinePattern(self.UM_RE)
 
 
 class UserMentionInlinePattern(markdown.inlinepatterns.Pattern):
 
-    def __init__(self, pattern):
-        markdown.inlinepatterns.Pattern.__init__(self, pattern)
-
     def handleMatch(self, m):
         user_name = m.group(2).replace("@", "")
         user = M.User.by_username(user_name)
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index 6d820cf..a8597f2 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -375,7 +375,7 @@ def find_shortlinks(text):
 
     md = markdown.Markdown(
         extensions=['markdown.extensions.codehilite', ForgeExtension(), 'markdown.extensions.tables'],
-        output_format='html4')
+        output_format='html')
     md.convert(text)
     link_index = md.treeprocessors['links'].alinks
     return [link for link in link_index if link is not None]
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 3a3ecd0..b27fecb 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -506,6 +506,23 @@ def foo(): pass
     )
 
 
+def test_markdown_list_without_break():
+    # this is not a valid way to make a list in original Markdown or python-markdown
+    #   https://github.com/Python-Markdown/markdown/issues/874
+    # it is valid in the CommonMark spec https://spec.commonmark.org/0.30/#lists
+    # TODO: try https://github.com/adamb70/mdx-breakless-lists
+    #       or https://gitlab.com/ayblaq/prependnewline
+    assert_equal(
+        g.markdown.convert('''\
+Regular text
+* first item
+* second item'''),
+        '<div class="markdown_content"><p>Regular text<br/>\n'
+        '<em> first item<br/>\n'
+        '</em> second item</p></div>'
+    )
+
+
 def test_markdown_autolink():
     tgt = 'http://everything2.com/?node=nate+oostendorp'
     s = g.markdown.convert('This is %s' % tgt)
diff --git a/Allura/allura/tests/test_markdown.py b/Allura/allura/tests/test_markdown.py
index a276b67..3a7f3c4 100644
--- a/Allura/allura/tests/test_markdown.py
+++ b/Allura/allura/tests/test_markdown.py
@@ -146,5 +146,5 @@ Not *strong* or _underlined_."""
 
         md = ForgeMarkdown(
             extensions=[mde.CommitMessageExtension(app), 'markdown.extensions.nl2br'],
-            output_format='html4')
+            output_format='html')
         self.assertEqual(md.convert(text), expected_html)
diff --git a/requirements.in b/requirements.in
index 0226d27..f62f95a 100644
--- a/requirements.in
+++ b/requirements.in
@@ -15,7 +15,7 @@ FormEncode
 GitPython<=3.1.23
 html5lib
 Jinja2
-Markdown<3
+Markdown
 markdown-checklist
 MarkupSafe
 Ming
diff --git a/requirements.txt b/requirements.txt
index 287fc9f..8f0ec4f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -73,7 +73,7 @@ iso8601==0.1.16
     # via colander
 jinja2==3.0.2
     # via -r requirements.in
-markdown==2.6.11
+markdown==3.0.1
     # via
     #   -r requirements.in
     #   markdown-checklist