import feedparser
import html2text
import markdown
-import markdown.extensions
-import markdown.preprocessors
import re
import textile
import unicodedata
from . import misc
+from . import wiki
from .decorators import *
class Blog(misc.Object):
if lang == "markdown":
return markdown.markdown(text,
extensions=[
- PrettyLinksExtension(),
+ wiki.PrettyLinksExtension(),
"codehilite",
"fenced_code",
"footnotes",
elif lang == "textile":
return textile.textile(text)
- return text
+ else:
+ return text
def refresh(self):
"""
# Mark this post as announced
self.db.execute("UPDATE blog SET announced_at = CURRENT_TIMESTAMP \
WHERE id = %s", self.id)
-
-
-class PrettyLinksExtension(markdown.extensions.Extension):
- def extendMarkdown(self, md):
- md.preprocessors.register(BugzillaLinksPreprocessor(md), "bugzilla", 10)
- md.preprocessors.register(CVELinksPreprocessor(md), "cve", 10)
-
-
-class BugzillaLinksPreprocessor(markdown.preprocessors.Preprocessor):
- regex = re.compile(r"(?:#(\d{5,}))", re.I)
-
- def run(self, lines):
- for line in lines:
- yield self.regex.sub(r"[#\1](https://bugzilla.ipfire.org/show_bug.cgi?id=\1)", line)
-
-
-class CVELinksPreprocessor(markdown.preprocessors.Preprocessor):
- regex = re.compile(r"(?:CVE)[\s\-](\d{4}\-\d+)")
-
- 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)
import difflib
import hashlib
import logging
+import markdown
+import markdown.extensions
+import markdown.preprocessors
import os.path
import re
import urllib.parse
return thumbnail
+class PrettyLinksExtension(markdown.extensions.Extension):
+ def extendMarkdown(self, md):
+ # Create links to Bugzilla
+ md.preprocessors.register(BugzillaLinksPreprocessor(md), "bugzilla", 10)
+
+ # Create links to CVE
+ md.preprocessors.register(CVELinksPreprocessor(md), "cve", 10)
+
+
+class BugzillaLinksPreprocessor(markdown.preprocessors.Preprocessor):
+ regex = re.compile(r"(?:#(\d{5,}))", re.I)
+
+ def run(self, lines):
+ for line in lines:
+ yield self.regex.sub(r"[#\1](https://bugzilla.ipfire.org/show_bug.cgi?id=\1)", line)
+
+
+class CVELinksPreprocessor(markdown.preprocessors.Preprocessor):
+ regex = re.compile(r"(?:CVE)[\s\-](\d{4}\-\d+)")
+
+ 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 WikiRenderer(misc.Object):
schemas = (
"ftp://",
# Images
images = re.compile(r"<img alt(?:=\"(.*?)\")? src=\"(.*?)\" (?:title=\"(.*?)\" )?/>")
+ # Markdown Renderer
+ renderer = markdown.Markdown(
+ extensions=[
+ PrettyLinksExtension(),
+ "codehilite",
+ "fenced_code",
+ "footnotes",
+ "nl2br",
+ "sane_lists",
+ "tables",
+ "toc",
+ ],
+ )
+
def init(self, path):
self.path = path
def render(self, text):
logging.debug("Rendering %s" % self.path)
- # Borrow this from the blog
- text = self.backend.blog._render_text(text, lang="markdown")
+ # Render...
+ text = self.renderer.convert(text)
# Postprocess links
text = self.links.sub(self._render_link, text)