summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Mangano-Tarumi <fmang@mg0.fr>2020-02-02 20:26:13 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2020-02-02 20:49:16 +0100
commite15d5c8180fab81d3e533cc521c1a98ff6f5b0a6 (patch)
tree745bc2ac15f718d6a91da3c55780380363773dd7
parent81faab9978a80e1608b99b5d45456548eaf01a62 (diff)
downloadaur-e15d5c8180fab81d3e533cc521c1a98ff6f5b0a6.tar.gz
aur-e15d5c8180fab81d3e533cc521c1a98ff6f5b0a6.tar.xz
rendercomment: use python-markdown's new registration API
First, this gets rid of the deprecation warnings Python displayed. Second, this fixes the case where a link contained a pair of underscores, which used to be interpreted as an emphasis because the linkify processor ran after the emphasis processor. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rwxr-xr-xaurweb/scripts/rendercomment.py10
-rwxr-xr-xtest/t2600-rendercomment.sh6
2 files changed, 10 insertions, 6 deletions
diff --git a/aurweb/scripts/rendercomment.py b/aurweb/scripts/rendercomment.py
index 22ed7b93..76865d27 100755
--- a/aurweb/scripts/rendercomment.py
+++ b/aurweb/scripts/rendercomment.py
@@ -26,7 +26,8 @@ class LinkifyExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
processor = markdown.inlinepatterns.AutolinkInlineProcessor(self._urlre, md)
- md.inlinePatterns.add('linkify', processor, '_end')
+ # Register it right after the default <>-link processor (priority 120).
+ md.inlinePatterns.register(processor, 'linkify', 119)
class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
@@ -47,7 +48,7 @@ class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
class FlysprayLinksExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
processor = FlysprayLinksInlineProcessor(r'\bFS#(\d+)\b',md)
- md.inlinePatterns.add('flyspray-links', processor, '_end')
+ md.inlinePatterns.register(processor, 'flyspray-links', 118)
class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
@@ -92,7 +93,7 @@ class GitCommitsExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
processor = GitCommitsInlineProcessor(md, self._head)
- md.inlinePatterns.add('git-commits', processor, '_end')
+ md.inlinePatterns.register(processor, 'git-commits', 117)
class HeadingTreeprocessor(markdown.treeprocessors.Treeprocessor):
@@ -106,7 +107,8 @@ class HeadingTreeprocessor(markdown.treeprocessors.Treeprocessor):
class HeadingExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
- md.treeprocessors.add('heading', HeadingTreeprocessor(md), '_end')
+ # Priority doesn't matter since we don't conflict with other processors.
+ md.treeprocessors.register(HeadingTreeprocessor(md), 'heading', 30)
def get_comment(conn, commentid):
diff --git a/test/t2600-rendercomment.sh b/test/t2600-rendercomment.sh
index 1ba560af..be408b80 100755
--- a/test/t2600-rendercomment.sh
+++ b/test/t2600-rendercomment.sh
@@ -52,7 +52,8 @@ test_expect_success 'Test HTML sanitizing.' '
test_expect_success 'Test link conversion.' '
cat <<-EOD | sqlite3 aur.db &&
INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (4, 1, "
- Visit https://www.archlinux.org/.
+ Visit https://www.archlinux.org/#_test_.
+ Visit *https://www.archlinux.org/*.
Visit <https://www.archlinux.org/>.
Visit \`https://www.archlinux.org/\`.
Visit [Arch Linux](https://www.archlinux.org/).
@@ -62,7 +63,8 @@ test_expect_success 'Test link conversion.' '
EOD
"$RENDERCOMMENT" 4 &&
cat <<-EOD >expected &&
- <p>Visit <a href="https://www.archlinux.org/">https://www.archlinux.org/</a>.
+ <p>Visit <a href="https://www.archlinux.org/#_test_">https://www.archlinux.org/#_test_</a>.
+ Visit <em><a href="https://www.archlinux.org/">https://www.archlinux.org/</a></em>.
Visit <a href="https://www.archlinux.org/">https://www.archlinux.org/</a>.
Visit <code>https://www.archlinux.org/</code>.
Visit <a href="https://www.archlinux.org/">Arch Linux</a>.