summaryrefslogtreecommitdiffstats
path: root/aurweb
diff options
context:
space:
mode:
authorFrédéric Mangano-Tarumi <fmang@mg0.fr>2020-02-02 20:25:08 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2020-02-02 20:49:16 +0100
commit127bb4c84cf8584dd4ee9f544333782d386224ac (patch)
tree253e8e713fa0461f0a9e2c6b74ace911e7182eff /aurweb
parent199f34e42e78ca97f154a4880b77b3f1d01fa9da (diff)
downloadaur-127bb4c84cf8584dd4ee9f544333782d386224ac.tar.gz
aur-127bb4c84cf8584dd4ee9f544333782d386224ac.tar.xz
rendercomment: safer Flyspray task linkification
When an FS#123 is part of a code block, it must not be converted into a link. FS#123 may also appear inside an URL, in which case regular linkifaction of URLs must take precedence. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'aurweb')
-rwxr-xr-xaurweb/scripts/rendercomment.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/aurweb/scripts/rendercomment.py b/aurweb/scripts/rendercomment.py
index 346ccff1..22ed7b93 100755
--- a/aurweb/scripts/rendercomment.py
+++ b/aurweb/scripts/rendercomment.py
@@ -29,18 +29,25 @@ class LinkifyExtension(markdown.extensions.Extension):
md.inlinePatterns.add('linkify', processor, '_end')
-class FlysprayLinksPreprocessor(markdown.preprocessors.Preprocessor):
- _fsre = re.compile(r'\b(FS#(\d+))\b')
- _sub = r'[\1](https://bugs.archlinux.org/task/\2)'
+class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
+ """
+ Turn Flyspray task references like FS#1234 into links to bugs.archlinux.org.
+
+ The pattern's capture group 0 is the text of the link and group 1 is the
+ Flyspray task ID.
+ """
- def run(self, lines):
- return [self._fsre.sub(self._sub, line) for line in lines]
+ def handleMatch(self, m, data):
+ el = markdown.util.etree.Element('a')
+ el.set('href', f'https://bugs.archlinux.org/task/{m.group(1)}')
+ el.text = markdown.util.AtomicString(m.group(0))
+ return el, m.start(0), m.end(0)
class FlysprayLinksExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
- preprocessor = FlysprayLinksPreprocessor(md)
- md.preprocessors.add('flyspray-links', preprocessor, '_end')
+ processor = FlysprayLinksInlineProcessor(r'\bFS#(\d+)\b',md)
+ md.inlinePatterns.add('flyspray-links', processor, '_end')
class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):