Skip to content

Commit

Permalink
feature: WikiLink Style can be configured in compatibility mode
Browse files Browse the repository at this point in the history
In compatibility mode [[WikiLinks]] are parsed as [[PageName | Title]]
This is for imported content or matching the style users got used to.
This was brough up in #155.
  • Loading branch information
redimp committed Nov 17, 2024
1 parent e7d92be commit 067668f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions otterwiki/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def handle_app_preferences(form):
def handle_content_and_editing(form):
for name in [
"commit_message",
"wikilink_style",
]:
_update_preference(name.upper(), form.get(name, ""))
for checkbox in [
Expand Down
4 changes: 4 additions & 0 deletions otterwiki/renderer_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ class mistunePluginWikiLink:
def parse_wikilink(self, inline, m, state):
title, link = m.group(2), m.group(4) or ""

WIKILINK_STYLE = inline.env.get("config",{}).get("WIKILINK_STYLE","")
if WIKILINK_STYLE.upper().replace("_","").strip() in ["LINKTITLE", "PAGENAMETITLE"]:
title, link = link, title

if link == '':
link = title
if not link.startswith("/"):
Expand Down
1 change: 1 addition & 0 deletions otterwiki/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
GIT_WEB_SERVER=False,
SIDEBAR_SHORTCUTS="home pageindex createpage",
ROBOTS_TXT="allow",
WIKILINK_STYLE="",
)
app.config.from_envvar("OTTERWIKI_SETTINGS", silent=True)

Expand Down
14 changes: 13 additions & 1 deletion otterwiki/templates/admin/content_and_editing.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2 class="card-title">Content and Editing Preferences</h2>
<div class="form-group">
<label for="commit_message" class="required">Commit message</label>
<select class="form-control w-md-400" id="commit_message" name="commit_message">
{% for mode in [("REQUIRED", "Required"),("OPTIONAL","Optional (empty commit messages are allowed"),("DISABLED", "Disabled (Changes saved without a commit message)")] %}
{% for mode in [("REQUIRED", "Required"),("OPTIONAL","Optional (empty commit messages are allowed)"),("DISABLED", "Disabled (Changes saved without a commit message)")] %}
<option value="{{mode[0]}}"{%if config.COMMIT_MESSAGE == mode[0] %} selected="selected"{%endif%}>{{mode[1]}}</option>
{% endfor %}
</select>
Expand All @@ -36,6 +36,18 @@ <h2 class="card-title">Content and Editing Preferences</h2>
</div>
</div>
</div>
{##}
<div class="form-group">
<label for="sidebar_menutree_mode">WikiLink Style</label>
<select class="form-control w-md-600" id="wikilink_style" name="wikilink_style">
{% for mode in [("", "[[Title | PageName]] - like Markdown links [Title](/PageName)"),("LINKTITLE","[[PageName | Title]] - compatibility mode"),] %}
<option value="{{mode[0]}}"{%if config.WIKILINK_STYLE == mode[0] %} selected="selected"{%endif%}>{{mode[1]}}</option>
{% endfor %}
</select>
<div class="mt-5">
The WikiLink Style only changes the rendering of the <code>[[Wikilink]]</code>, no content will be changed. The compatibility mode is for imported content or matching the style users got used to.
</div>
</div>
{##}
<div class="form-text pt-0 mt-0 mb-20"></div>
{##}
Expand Down
7 changes: 7 additions & 0 deletions otterwiki/templates/snippets/syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ <h4>{{ name }}</h4>

<div class="row">
<div class="col-md-6 col-sm-12">
{% if config.WIKILINK_STYLE.upper() == "LINKTITLE" %}
<pre class="block-compact text-wrap">[[WikiPage|Text to display]]</pre>
{% else %}
<pre class="block-compact text-wrap">[[Text to display|WikiPage]]</pre>
{% endif %}
</div>
<div class="col-md-6 col-sm-12 pl-5">
<a href="#">Text to display</a>
Expand All @@ -121,6 +125,9 @@ <h4>{{ name }}</h4>
<a href="#">Link with text</a>
</div>
</div>
{% if config.WIKILINK_STYLE.upper() == "LINKTITLE" %}
<p><em>Note: WikiLink-Style is in compatibility mode.</em></p>
{% endif %}

{{ heading("Quotes") }}
<div class="row">
Expand Down
10 changes: 9 additions & 1 deletion tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from bs4 import BeautifulSoup
from otterwiki.renderer import render, clean_html
from otterwiki.renderer import render, clean_html, OtterwikiRenderer


def test_lastword():
Expand Down Expand Up @@ -124,6 +124,14 @@ def test_wiki_link_subspace(req_ctx):
assert '<a href="/people/Paul">Paul</a>' in html


def test_wiki_link_compatibilty_mode(req_ctx):
configured_renderer = OtterwikiRenderer(config={"WIKILINK_STYLE":"LinkTitle"})
text = "[[people/Paul|Paul]]"
html, _ = configured_renderer.markdown(text)
assert '<a href="/people/Paul">Paul</a>' in html



def test_wiki_link_in_table(req_ctx):
text = """| name | date | link |
| -------- | -------- | -------- |
Expand Down

0 comments on commit 067668f

Please sign in to comment.