aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/__init__.py4
-rw-r--r--apioforum/mdrender.py17
-rw-r--r--apioforum/templates/common.html6
-rw-r--r--apioforum/templates/view_forum.html2
-rw-r--r--apioforum/templates/view_user.html2
5 files changed, 23 insertions, 8 deletions
diff --git a/apioforum/__init__.py b/apioforum/__init__.py
index 8163e45..673bb0b 100644
--- a/apioforum/__init__.py
+++ b/apioforum/__init__.py
@@ -70,8 +70,8 @@ def create_app():
from .mdrender import render
@app.template_filter('md')
- def md_render(s):
- return render(s)
+ def md_render(s, forum_id):
+ return render(s, forum_id)
@app.errorhandler(404)
def not_found(e):
diff --git a/apioforum/mdrender.py b/apioforum/mdrender.py
index 2d58f5c..0d75b2f 100644
--- a/apioforum/mdrender.py
+++ b/apioforum/mdrender.py
@@ -1,6 +1,8 @@
import bleach
from bleach._vendor.html5lib.filters.base import Filter
from .csscolors import csscolors
+from .wiki import normalize_page_name
+from flask import url_for
allowed_tags = [
'p',
@@ -86,7 +88,17 @@ cleaner = bleach.sanitizer.Cleaner(
css_sanitizer=IFrameCSS(),
filters=[IFrameSandboxFilter])
+g_forum_id = None
+def wikilink_url(label, base, end):
+ if g_forum_id is None:
+ return "#"
+ else:
+ normalized = normalize_page_name(label)
+ return url_for('forum.view_wiki_page', forum_id=g_forum_id, path=normalized)
+
+
import markdown
+from markdown.extensions.wikilinks import WikiLinkExtension
md = markdown.Markdown(extensions=[
'pymdownx.tilde',
'pymdownx.caret',
@@ -94,9 +106,12 @@ md = markdown.Markdown(extensions=[
'tables',
'pymdownx.details',
'pymdownx.fancylists',
+ WikiLinkExtension(build_url=wikilink_url),
])
-def render(text):
+def render(text, forum_id):
+ global g_forum_id #blegh
+ g_forum_id = forum_id
text = md.reset().convert(text)
text = cleaner.clean(text)
return text
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index ee31507..b64630b 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -63,9 +63,9 @@
</div>
<div class="post-content md">
{% if not preview %}
- {{ post.content|md|safe }}
+ {{ post.content|md(forum)|safe }}
{% else %}
- {{ post.content[:2500]|md|safe }}
+ {{ post.content[:2500]|md(forum)|safe }}
{% endif %}
</div>
{% if footer %}
@@ -90,7 +90,7 @@
</span>
</div>
<div class="post-content md">
- {{ message|md|safe }}
+ {{ message|md(None)|safe }}
</div>
</div>
{% endmacro %}
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index bc2aa44..2e1fb0d 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -8,7 +8,7 @@
{%endblock%}
{%block content%}
-{{forum.description|md|safe}}
+{{forum.description|md(forum.id)|safe}}
<hr/>
<div class="forum-info">
diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html
index efaea6b..fa0d194 100644
--- a/apioforum/templates/view_user.html
+++ b/apioforum/templates/view_user.html
@@ -17,7 +17,7 @@
</div>
<div class="user_info">
<div class="user_bio_quote">
- <div class="user_bio">{{(user.bio or "hail GEORGE")|md|safe}}</div>
+ <div class="user_bio">{{(user.bio or "hail GEORGE")|md(None)|safe}}</div>
<p class="user_bio_attribution">— {{user.username|e}}</p>
</div>
<dl>