src/templates/modules/commit-message.html \
src/templates/modules/link-to-user.html \
src/templates/modules/packages-files-table.html \
- src/templates/modules/source-table.html \
- src/templates/modules/text.html
+ src/templates/modules/source-table.html
templates_modulesdir = $(templatesdir)/modules
AX_PYTHON_MODULE([boto3], [fatal])
AX_PYTHON_MODULE([kerberos], [fatal])
AX_PYTHON_MODULE([location], [fatal])
+AX_PYTHON_MODULE([markdown], [fatal])
AX_PYTHON_MODULE([pygments], [fatal])
AX_PYTHON_MODULE([systemd.journal], [fatal])
#!/usr/bin/python
import datetime
+import markdown
import pygments
import pygments.formatters
import pygments.lexers
class TextModule(UIModule):
- BUGZILLA_PATTERN = re.compile(r"(?:bug\s?|#)(\d+)")
- CVE_PATTERN = re.compile(r"(?:CVE)[\s\-](\d{4}\-\d{4})")
-
- LINK = """<a href="%s" target="_blank" rel="noopener">%s</a>"""
-
+ """
+ Renders the text through the Markdown processor
+ """
def render(self, text):
- # Handle empty messages
- if not text:
- return ""
+ return markdown.markdown(text,
+ extensions=[
+ PrettyLinksExtension(),
+ "codehilite",
+ "fenced_code",
+ "sane_lists",
+ ])
+
- # Search for bug ids that need to be linked to bugzilla
- text = re.sub(self.BUGZILLA_PATTERN, self._bugzilla_repl, text, re.I|re.U)
+class PrettyLinksExtension(markdown.extensions.Extension):
+ def extendMarkdown(self, md):
+ md.preprocessors.register(BugzillaLinksPreprocessor(md), "bugzilla", 10)
+ md.preprocessors.register(CVELinksPreprocessor(md), "cve", 10)
- # Search for CVE numbers and create hyperlinks.
- text = re.sub(self.CVE_PATTERN, self._cve_repl, text, re.I|re.U)
- return self.render_string("modules/text.html", paragraphs=text.split("\n\n"))
+class BugzillaLinksPreprocessor(markdown.preprocessors.Preprocessor):
+ regex = re.compile(r"(?:#(\d{5,}))", re.I)
- def _bugzilla_repl(self, m):
- bug_id = m.group(1)
+ def run(self, lines):
+ for line in lines:
+ yield self.regex.sub(
+ r"[#\1](https://bugzilla.ipfire.org/show_bug.cgi?id=\1)", line)
- # Get the URL
- bug_url = self.backend.bugzilla.bug_url(bug_id)
- return self.LINK % (bug_url, m.group(0))
+class CVELinksPreprocessor(markdown.preprocessors.Preprocessor):
+ regex = re.compile(r"(?:CVE)[\s\-](\d{4}\-\d+)")
- def _cve_repl(self, m):
- return self.LINK % ("http://cve.mitre.org/cgi-bin/cvename.cgi?name=%s" % m.group(1), m.group(0))
+ def run(self, lines):
+ for line in lines:
+ yield self.regex.sub(
+ r"[CVE-\1](https://cve.mitre.org/cgi-bin/cvename.cgi?name=\1)", line)
class HighlightModule(UIModule):