diff --git a/rophako/model/wiki.py b/rophako/model/wiki.py
index 5e43237..e75d628 100644
--- a/rophako/model/wiki.py
+++ b/rophako/model/wiki.py
@@ -2,13 +2,45 @@
"""Wiki models."""
+from flask import url_for
import time
import re
import hashlib
import rophako.jsondb as JsonDB
+from rophako.utils import render_markdown
from rophako.log import logger
+def render_page(content):
+ """Render the Markdown content of a Wiki page, and support inter-page
+ linking with [[double braces]].
+
+ For simple links, just use the [[Page Name]]. To have a different link text
+ than the page name, use [[Link Text|Page Name]]."""
+ html = render_markdown(content)
+
+ # Look for [[double brackets]]
+ links = re.findall(r'\[\[(.+?)\]\]', html)
+ for match in links:
+ label = page = match
+ if "|" in match:
+ label, page = match.split("|", 2)
+
+ # Does the page exist?
+ output = '''{label}'''
+ if not JsonDB.exists("wiki/pages/{}".format(page)):
+ output = '''{label}'''
+
+ html = html.replace("[[{}]]".format(match),
+ output.format(
+ url=url_for("wiki.view_page", name=name_to_url(page)),
+ label=label,
+ )
+ )
+
+ return html
+
+
def get_page(name):
"""Get a Wiki page. Returns `None` if the page isn't found."""
name = name.strip("/") # Remove any surrounding slashes.
diff --git a/rophako/modules/wiki/__init__.py b/rophako/modules/wiki/__init__.py
index 85aab63..6092a47 100644
--- a/rophako/modules/wiki/__init__.py
+++ b/rophako/modules/wiki/__init__.py
@@ -7,8 +7,7 @@ from flask import Blueprint, g, request, redirect, url_for, flash
import rophako.model.user as User
import rophako.model.wiki as Wiki
import rophako.model.emoticons as Emoticons
-from rophako.utils import (template, render_markdown, pretty_time,
- login_required)
+from rophako.utils import template, pretty_time, render_markdown, login_required
from rophako.settings import Config
mod = Blueprint("wiki", __name__, url_prefix="/wiki")
@@ -33,8 +32,12 @@ def list_pages():
@mod.route("/")
def view_page(name):
"""Show a specific wiki page."""
+ link = name
name = Wiki.url_to_name(name)
+ g.info["link"] = link
+ g.info["title"] = name
+
# Look up the page.
page = Wiki.get_page(name)
if not page:
@@ -59,10 +62,19 @@ def view_page(name):
# Show the latest one.
rev = page["revisions"][0]
+ # Getting the plain text source?
+ if request.args.get("source", None):
+ g.info["markdown"] = render_markdown("\n".join([
+ "# Source: {}".format(name),
+ "",
+ "```markdown",
+ rev["body"],
+ "```"
+ ]))
+ return template("markdown.inc.html")
+
# Render it!
- g.info["link"] = Wiki.name_to_url(name)
- g.info["title"] = name
- g.info["rendered_body"] = render_markdown(rev["body"])
+ g.info["rendered_body"] = Wiki.render_page(rev["body"])
g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"])
g.info["pretty_time"] = pretty_time(Config.wiki.time_format, rev["time"])
@@ -131,7 +143,7 @@ def edit():
g.info["preview"] = True
# Render markdown
- g.info["rendered_body"] = render_markdown(body)
+ g.info["rendered_body"] = Wiki.render_page(body)
# Render emoticons.
g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"])
diff --git a/rophako/modules/wiki/templates/wiki/page.html b/rophako/modules/wiki/templates/wiki/page.html
index 4d9216d..16a5049 100644
--- a/rophako/modules/wiki/templates/wiki/page.html
+++ b/rophako/modules/wiki/templates/wiki/page.html
@@ -7,6 +7,7 @@
[ History
| Index
+ | Source
{% if session["login"] %}
| Edit
| New Page
@@ -16,6 +17,8 @@
{{ title }}
+
+
{{ rendered_body|safe }}
{% endblock %}
diff --git a/rophako/www/smoke/style.css b/rophako/www/smoke/style.css
index 12ae1c6..b7e8fab 100644
--- a/rophako/www/smoke/style.css
+++ b/rophako/www/smoke/style.css
@@ -314,6 +314,11 @@ ul.blog-categories li:last-child:after {
font-size: 9pt;
}
+/* Wiki styles */
+a.wiki-broken {
+ text-decoration: line-through;
+}
+
/* Visitor history page */
.visitor-graph {
height: 16px;