2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 15:21:52 +00:00

[svn] Wiki_markup imporved to include paragraphs

wiki_to_html should be used when the field will include paragraphs
wiki_to_html_short should be used when the field will not include paragraphs
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8061 by julian @ 11/6/2008 11:24 PM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:18:26 +01:00
parent 13d44fe647
commit f5ddbafcb0
5 changed files with 27 additions and 13 deletions

View File

@ -34,6 +34,17 @@ def wiki_list(line, listdepth):
@register.filter() @register.filter()
@stringfilter @stringfilter
def wiki_to_html(value, autoescape=None): def wiki_to_html(value, autoescape=None):
#find paragraphs
outValue = ""
for paragraph in re.split("\n\s*?\n", value, re.DOTALL):
outValue += "<p>"
outValue += wiki_to_html_short(paragraph, autoescape)
outValue += "</p>\n"
return mark_safe(outValue)
@register.filter()
@stringfilter
def wiki_to_html_short(value, autoescape=None):
if autoescape: if autoescape:
value = conditional_escape(value) value = conditional_escape(value)
#deescape doubly escaped characters #deescape doubly escaped characters
@ -42,9 +53,11 @@ def wiki_to_html(value, autoescape=None):
value = re.sub("&#39;&#39;&#39;&#39;([^']+)&#39;&#39;&#39;&#39;", r"<b><i>\1</i></b>", value, re.DOTALL) value = re.sub("&#39;&#39;&#39;&#39;([^']+)&#39;&#39;&#39;&#39;", r"<b><i>\1</i></b>", value, re.DOTALL)
value = re.sub("&#39;&#39;&#39;([^']+)&#39;&#39;&#39;", r"<b>\1</b>", value, re.DOTALL) value = re.sub("&#39;&#39;&#39;([^']+)&#39;&#39;&#39;", r"<b>\1</b>", value, re.DOTALL)
value = re.sub("&#39;&#39;([^']+)&#39;&#39;", r"<i>\1</i>", value, re.DOTALL) value = re.sub("&#39;&#39;([^']+)&#39;&#39;", r"<i>\1</i>", value, re.DOTALL)
#make cave links
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="/troggle/cave/\1/">\1</a>', value, re.DOTALL)
#Make lists from lines starting with lists of [stars and hashes] #Make lists from lines starting with lists of [stars and hashes]
listdepth = []
outValue = "" outValue = ""
listdepth = []
for line in value.split("\n"): for line in value.split("\n"):
t, listdepth = wiki_list(line, listdepth) t, listdepth = wiki_list(line, listdepth)
outValue += t outValue += t

View File

@ -8,20 +8,20 @@
<tr> <tr>
<th id="kat_no"> <th id="kat_no">
{% if cave.kataster_number %} {% if cave.kataster_number %}
{{ cave.kataster_number|wiki_to_html }} {{ cave.kataster_number|wiki_to_html_short }}
{% if cave.entrancelist %} {% if cave.entrancelist %}
- {{ cave.entrancelist|wiki_to_html }} - {{ cave.entrancelist|wiki_to_html_short }}
{% endif %} {% endif %}
{% if cave.unofficial_number %} {% if cave.unofficial_number %}
<br />({{ cave.unofficial_number|wiki_to_html }}) <br />({{ cave.unofficial_number|wiki_to_html_short }})
{% endif %} {% endif %}
{% endif %} {% endif %}
</th> </th>
<th id="name"> <th id="name">
{{ cave.official_name|wiki_to_html }} {{ cave.official_name|wiki_to_html_short }}
</th> </th>
<th id="status"> <th id="status">
{{ cave.kataster_code|wiki_to_html }} {{ cave.kataster_code|wiki_to_html_short }}
</th> </th>
</tr> </tr>
</table> </table>
@ -29,9 +29,9 @@
{% if cave.entrances %} {% if cave.entrances %}
<h2>Entrances</h2> <h2>Entrances</h2>
{% for ent in cave.entrances %} {% for ent in cave.entrances %}
<a href = "./{{ ent.entrance_letter|wiki_to_html }}">{{ ent.entrance_letter|wiki_to_html }}</a> <a href = "./{{ ent.entrance_letter|wiki_to_html_short }}">{{ ent.entrance_letter|wiki_to_html_short }}</a>
{% if ent.entrance.marking %} {% if ent.entrance.marking %}
Marking: {{ ent.entrance.marking_val|wiki_to_html }} Marking: {{ ent.entrance.marking_val|wiki_to_html_short }}
{% endif %} {% endif %}
<br> <br>
{% endfor %} {% endfor %}

View File

@ -5,6 +5,6 @@
{% block content %} {% block content %}
{% for cave in caves %} {% for cave in caves %}
<p>{{ cave }} <a href="./{{ cave.kataster_number }}/">{{ cave.official_name|wiki_to_html }}</a> </p> <p>{{ cave }} <a href="./{{ cave.kataster_number }}/">{{ cave.official_name|wiki_to_html_short }}</a> </p>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

View File

@ -20,7 +20,6 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<em>[wiki_to_html doesn't do paragraphs. don't know where it is located]</em>
<div>{{logbookentry.text|wiki_to_html}}</div> <div>{{logbookentry.text|wiki_to_html}}</div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -1,10 +1,10 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load wiki_markup %} {% load wiki_markup %}
{% block title %}Person {{person.id}}{% endblock %} {% block title %}Person {{person|wiki_to_html_short}}{% endblock %}
{% block content %} {% block content %}
<div class="personblock"><a href="/person/{{person.id}}">{{person}}</a> <div class="personblock"><a href="/person/{{person.id}}">{{person|wiki_to_html_short}}</a>
<ul> <ul>
{% for personexpedition in person.personexpedition_set.all %} {% for personexpedition in person.personexpedition_set.all %}
<li> <li>
@ -14,7 +14,9 @@
<div> <div>
<ul> <ul>
{% for persontrip in personexpedition.persontrip_set.all %} {% for persontrip in personexpedition.persontrip_set.all %}
<li><a href="/logbookentry/{{persontrip.logbookentry.id}}">{{persontrip.date}}</a> ({{persontrip.logbookentry.place}}) - {{persontrip.logbookentry.title}}</li> <li><a href="/logbookentry/{{persontrip.logbookentry.id}}">{{persontrip.date}}</a>
({{persontrip.logbookentry.place|wiki_to_html_short}}) -
{{persontrip.logbookentry.title|wiki_to_html_short}}</li>
{% endfor %} {% endfor %}
<ul> <ul>
</div> </div>