Improved MD support.

Add some styling for images in MD

Add support for the bastardisation of the MD html for RML.
This commit is contained in:
Tom Price
2016-01-07 19:25:54 +00:00
parent b80c38756f
commit 088e23749d
7 changed files with 9239 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@@ -137,3 +137,9 @@ textarea {
};
}
}
.markdown {
img {
max-width: 100%;
}
}

View File

@@ -142,7 +142,7 @@
<dd>&nbsp;</dd>
<dt>Event Description</dt>
<dd>{{ event.description|markdown }}</dd>
<dd>{{ event.description|markdown:'rml' }}</dd>
<dd>&nbsp;</dd>

View File

@@ -1,3 +1,5 @@
{% load markdown_tags %}
<setNextFrame name="main"/>
<nextFrame/>
@@ -15,9 +17,7 @@
</para>
<keepInFrame>
<para style="style.event_description">
{{ object.description|default_if_none:""|linebreaksbr }}
</para>
{{ object.description|default_if_none:""|markdown:'rml' }}
</keepInFrame>
{% if invoice %}
@@ -173,9 +173,9 @@
<para>{{ item.name }}
{% if item.description %}
</para>
<para style="item_description">
<em>{{ item.description|linebreaksbr }}</em>
</para>
<indent left="1cm">
{{ item.description|markdown:"rml" }}
</indent>
<para>
{% endif %}
</para>
@@ -315,4 +315,4 @@
{% include "RIGS/event_print_signature.xml" %}
</keepTogether>
{% endif %}
<namedString id="lastPage"><pageNumber/></namedString>
<namedString id="lastPage"><pageNumber/></namedString>

View File

@@ -1,3 +1,4 @@
from bs4 import BeautifulSoup
from django import template
from django.utils.safestring import mark_safe
import markdown
@@ -7,5 +8,32 @@ __author__ = 'ghost'
register = template.Library()
@register.filter(name="markdown")
def markdown_filter(text):
return mark_safe(markdown.markdown(text))
def markdown_filter(text, format='html'):
html = markdown.markdown(text)
if format == 'html':
return mark_safe('<div class="markdown">' + html + '</div>')
elif format == 'rml':
# Convert format to RML
soup = BeautifulSoup(html, "html.parser")
# Image aren't supported so remove them
for img in soup('img'):
img.parent.extract()
# <code> should become <pre>
for c in soup('code'):
c.name = 'pre'
c.parent.replaceWithChildren()
# blockquotes don't exist but we can still do something to show
for bq in soup('blockquote'):
bq.name = 'pre'
bq.string = bq.text
# Paragraphs have a different tag
for p in soup('p'):
p.name = 'para'
# @todo: <ul> and <li> tags to not appear to be working
return mark_safe(soup)

Binary file not shown.

View File

@@ -1,3 +1,4 @@
beautifulsoup4==4.4.1
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.8.2