From 4a0d4461e18dab5c7da3e9900dfbbc7b3e0a5ca7 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 7 May 2012 12:26:17 +0200 Subject: [PATCH 1/2] Apply typogrify on the title. As it is done when reading the file, we need to remove html tags for the permalink and the slug (this is done here for the notmyidea and simple themes). While modifying the themes I also replaced the `pagename` template tag with `article.url` (`pagename` was an empty variable, no more used ?). --- pelican/readers.py | 1 + .../themes/notmyidea/templates/article.html | 56 ++++++++++--------- pelican/themes/simple/templates/article.html | 36 ++++++------ pelican/utils.py | 2 + 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 868dc965..83565918 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -174,5 +174,6 @@ def read_file(filename, fmt=None, settings=None): if settings and settings['TYPOGRIFY']: from typogrify import Typogrify content = Typogrify.typogrify(content) + metadata['title'] = Typogrify.typogrify(metadata['title']) return content, metadata diff --git a/pelican/themes/notmyidea/templates/article.html b/pelican/themes/notmyidea/templates/article.html index 6615b63a..fc7e5893 100644 --- a/pelican/themes/notmyidea/templates/article.html +++ b/pelican/themes/notmyidea/templates/article.html @@ -1,30 +1,34 @@ {% extends "base.html" %} -{% block title %}{{ article.title }}{% endblock %} -{% block content %} -
-
-

{{ article.title - }}

{% include 'twitter.html' %}
-
- {% include 'article_infos.html' %} - {{ article.content }} -
- {% if DISQUS_SITENAME %} -
-

Comments !

-
- -
- {% endif %} +{% block title %}{{ article.title|striptags }}{% endblock %} +{% block content %} +
+ +
+ {% include 'article_infos.html' %} + {{ article.content }} +
+ {% if DISQUS_SITENAME %} +
+

Comments !

+
+ +
+ {% endif %} + +
{% endblock %} diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index d6c96a13..16c34266 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -1,19 +1,23 @@ {% extends "base.html" %} -{% block content %} -
-

{{ article.title }}

-
- - {{ article.locale_date }} - - {% if article.author %} -
- By {{ article.author }} -
- {% endif %} -
-
- {{ article.content }} -
+{% block content %} +
+
+

+ {{ article.title }}

+
+
+ + {{ article.locale_date }} + + {% if article.author %} +
+ By {{ article.author }} +
+ {% endif %} +
+
+ {{ article.content }} +
{% endblock %} diff --git a/pelican/utils.py b/pelican/utils.py index 18730e6c..d4e34842 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -8,6 +8,7 @@ import logging from codecs import open as _open from datetime import datetime from itertools import groupby +from jinja2 import Markup from operator import attrgetter logger = logging.getLogger(__name__) @@ -44,6 +45,7 @@ def slugify(value): Took from django sources. """ + value = Markup(value).striptags() if type(value) == unicode: import unicodedata value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') From e9996b5cc64e4c9dc7c295742e5d1d592ee32511 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 7 May 2012 13:05:33 +0200 Subject: [PATCH 2/2] strip tags for feed titles --- pelican/writers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pelican/writers.py b/pelican/writers.py index 593879e2..75971ee9 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -8,8 +8,8 @@ import logging from codecs import open from functools import partial - from feedgenerator import Atom1Feed, Rss201rev2Feed +from jinja2 import Markup from pelican.paginator import Paginator from pelican.utils import get_relative_path, set_date_tzinfo @@ -25,8 +25,9 @@ class Writer(object): def _create_new_feed(self, feed_type, context): feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed + sitename = Markup(context['SITENAME']).striptags() feed = feed_class( - title=context['SITENAME'], + title=sitename, link=(self.site_url + '/'), feed_url=self.feed_url, description=context.get('SITESUBTITLE', '')) @@ -34,8 +35,9 @@ class Writer(object): def _add_item_to_the_feed(self, feed, item): + title = Markup(item.title).striptags() feed.add_item( - title=item.title, + title=title, link='%s/%s' % (self.site_url, item.url), unique_id='tag:%s,%s:%s' % (self.site_url.replace('http://', ''), item.date.date(), item.url),