diff --git a/entries/jinja2/entries/h-entry.html b/entries/jinja2/entries/h-entry.html index 0cf7a80..b9a05f6 100644 --- a/entries/jinja2/entries/h-entry.html +++ b/entries/jinja2/entries/h-entry.html @@ -10,7 +10,7 @@ {{i}}

{{ entry.name }}

{% endif %} {{i}}
- {{i}}{{ entry.content | indent(indent_width + 6) }} + {{i}}{{ entry.content | markdown }} {{i}}
{{i}} diff --git a/entries/templates/entries/entry.html b/entries/templates/entries/entry.html deleted file mode 100644 index a620f55..0000000 --- a/entries/templates/entries/entry.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends 'lemoncurry/layout.html' %} -{% load absolute_url static %} - -{% block head %} - - -{% endblock %} - -{% block styles %} - -{% endblock %} - -{% block main %} -
-{% include 'entries/h-entry.html' %} -
-{% endblock %} diff --git a/entries/templates/entries/h-entry.html b/entries/templates/entries/h-entry.html deleted file mode 100644 index a3740a9..0000000 --- a/entries/templates/entries/h-entry.html +++ /dev/null @@ -1,67 +0,0 @@ -{% load bleach friendly_url humanize jsonify markdown %}
- {% if entry.photo %}{% endif %} - - {% if entry.in_reply_to %}{% with reply=entry.reply_context %} -
- - {{ reply.author.name }} - -
- {% if reply.name %}

{{ reply.name }}

{% endif %} -
{{ reply.content | bleach }}
-
-
{% endwith %}{% endif %} - -
- {% if entry.name %}

{{ entry.name }}

{% endif %} -
{{ entry.content | markdown }}
-
- - - - {% if entry.cats.exists %} - - {% endif %} - - {% if entry.syndications.exists %} - - {% endif %} - - -
diff --git a/entries/templates/entries/index.html b/entries/templates/entries/index.html deleted file mode 100644 index d16f517..0000000 --- a/entries/templates/entries/index.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends 'lemoncurry/layout.html' %} -{% load static %} -{% block html_class %}h-feed{% endblock %} - -{% block styles %} - -{% endblock %} - -{% block main %} -
    - {% for entry in entries %} -
  1. - {% include 'entries/h-entry.html' %} -
  2. - {% endfor %} -
-{% endblock %} diff --git a/home/jinja2/home/index.html b/home/jinja2/home/index.html new file mode 100644 index 0000000..ff6d51a --- /dev/null +++ b/home/jinja2/home/index.html @@ -0,0 +1,102 @@ +{% extends 'lemoncurry/layout.html' %} + +{% block html_attr %} + class="h-feed"{{ super() }} +{%- endblock %} + +{% block styles %} + + +{% endblock %} + +{% block head %} + {% for key in user.keys.all() %} + + {% endfor %} +{% endblock %} + +{% block main %} + + + {% import 'entries/h-entry.html' as h %} +
    + {% for entry in entries %} +
  1. + {{ h.hEntry(entry, indent_width=10) }} +
  2. + {% endfor %} +
+{% endblock %} + +{% block foot %} + +{% endblock %} diff --git a/home/templates/home/index.html b/home/templates/home/index.html deleted file mode 100644 index d5b76f5..0000000 --- a/home/templates/home/index.html +++ /dev/null @@ -1,70 +0,0 @@ -{% extends 'lemoncurry/layout.html' %} -{% load jsonify markdown static %} -{% block html_class %}h-feed{% endblock %} -{% block styles %} - - -{% endblock %} - -{% block head %}{% for key in user.keys.all %}{% endfor %}{% endblock %} - -{% block main %} - -
    - {% for entry in entries %} -
  1. - {% include 'entries/h-entry.html' %} -
  2. - {% endfor %} -
-{% endblock %} -{% block foot %} - -{% endblock %} diff --git a/lemoncurry/jinja2.py b/lemoncurry/jinja2/__init__.py similarity index 88% rename from lemoncurry/jinja2.py rename to lemoncurry/jinja2/__init__.py index 57fcfdf..681f1d0 100644 --- a/lemoncurry/jinja2.py +++ b/lemoncurry/jinja2/__init__.py @@ -7,7 +7,8 @@ from compressor.contrib.jinja2ext import CompressorExtension from django_activeurl.ext.django_jinja import ActiveUrl from entries.kinds import all as entry_kinds -from .utils import friendly_url, load_package_json +from .markdown import markdown +from ..utils import friendly_url, load_package_json def environment(**options): @@ -19,6 +20,7 @@ def environment(**options): ) env.filters.update({ 'friendly_url': friendly_url, + 'markdown': markdown, 'naturaltime': naturaltime, }) env.globals.update({ diff --git a/lemoncurry/jinja2/bleach.py b/lemoncurry/jinja2/bleach.py new file mode 100644 index 0000000..de09c04 --- /dev/null +++ b/lemoncurry/jinja2/bleach.py @@ -0,0 +1,21 @@ +from bleach.sanitizer import Cleaner, ALLOWED_TAGS +from bleach.linkifier import LinkifyFilter +from jinja2 import evalcontextfilter, Markup + +TAGS = ['cite', 'code', 'p', 'pre', 'img', 'span'] +TAGS.extend(ALLOWED_TAGS) +ATTRIBUTES = { + 'a': ('href', 'title', 'class'), + 'img': ('alt', 'src', 'title'), + 'span': ('class',), +} + +cleaner = Cleaner(tags=TAGS, attributes=ATTRIBUTES, filters=(LinkifyFilter,)) + + +@evalcontextfilter +def bleach(ctx, html): + res = cleaner.clean(html) + if ctx.autoescape: + res = Markup(res) + return res diff --git a/lemoncurry/jinja2/lemoncurry/layout.html b/lemoncurry/jinja2/lemoncurry/layout.html index 1564b14..783879f 100644 --- a/lemoncurry/jinja2/lemoncurry/layout.html +++ b/lemoncurry/jinja2/lemoncurry/layout.html @@ -81,6 +81,41 @@ diff --git a/lemoncurry/jinja2/markdown.py b/lemoncurry/jinja2/markdown.py new file mode 100644 index 0000000..951b3b8 --- /dev/null +++ b/lemoncurry/jinja2/markdown.py @@ -0,0 +1,16 @@ +from jinja2 import evalcontextfilter +from markdown import Markdown + +from .bleach import bleach + +md = Markdown(extensions=( + 'markdown.extensions.extra', + 'markdown.extensions.headerid', + 'markdown.extensions.sane_lists', + 'markdown.extensions.smarty', +)) + + +@evalcontextfilter +def markdown(ctx, source): + return bleach(ctx, md.reset().convert(source)) diff --git a/lemoncurry/templates/lemoncurry/layout.html b/lemoncurry/templates/lemoncurry/layout.html deleted file mode 100644 index 1b31cf3..0000000 --- a/lemoncurry/templates/lemoncurry/layout.html +++ /dev/null @@ -1,134 +0,0 @@ -{% load analytical compress favicon lemoncurry_tags meta static theme_colour %} - - {% site_name as site_name %}{% request_uri request as uri %}{% request_origin request as origin %} - - - - - - {% if title %}{{ title }} ~ {% endif %}{{ site_name }} - - {% analytical_head_top %} - {% if atom %}{% endif %} - {% if rss %} {% endif %} - {% block head %}{% endblock %} - - - - - - - - - - - - - {% get_package_json as package %} - - - - - {% include 'meta/meta.html' %} - {% get_favicons 'favicon/' %} - - - - - - {% compress css %} - - {% block styles %}{% endblock %} - {% endcompress %} - - {% analytical_head_bottom %} - - - {% analytical_body_top %} -
- - {% if request.resolver_match.view_name %} - {% nav_crumbs request.resolver_match %} - {% endif %} -
- -
- {% block main %}{% endblock %} -
- - - - - - - - - - {% compress js %} - - {% block foot %}{% endblock %} - {% endcompress %} - {% analytical_body_bottom %} - - diff --git a/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html b/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html deleted file mode 100644 index 0b1ddb0..0000000 --- a/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html +++ /dev/null @@ -1,11 +0,0 @@ -{% load jsonify %}{% if crumbs %} - -{% endif %} diff --git a/lemoncurry/templates/lemoncurry/tags/nav.html b/lemoncurry/templates/lemoncurry/tags/nav.html deleted file mode 100644 index 8359cdc..0000000 --- a/lemoncurry/templates/lemoncurry/tags/nav.html +++ /dev/null @@ -1,8 +0,0 @@ -{% load activeurl %}{% activeurl %}{% endactiveurl %}