commit f4dd8adb6abd79fa8af2322007621752d8e4a45f
parent aa2d3330182c00f91518c0567da78e39a7a7ebd8
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 20 Sep 2008 19:47:59 +1000
fixed namespaces in atom, rearranged use of Markdown
Diffstat:
4 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/blog.py b/blog.py
@@ -1,6 +1,5 @@
import os, re, uuid, email
from datetime import datetime
-from markdown2 import Markdown
import genshi
import yaml
@@ -93,9 +92,7 @@ class BlogEntry(object):
# not really a MIME document, but parse it like one
msg = email.message_from_file(open(os.path.join(self.dir, 'content.txt'), 'r'))
self.metadata = cleanup_metadata(msg.items())
- self.raw_body = msg.get_payload().decode('utf8') # XXX encoding
- md = Markdown(extras=['code-friendly'])
- self.body = genshi.Markup(md.convert(self.raw_body))
+ self.body = msg.get_payload().decode('utf8') # XXX encoding
self.title = self.metadata['title']
raw_tags = self.metadata.get('tags', '').strip()
@@ -170,9 +167,7 @@ class Comment(object):
self.id = id
msg = email.message_from_file(open(path, 'r'))
self.metadata = cleanup_metadata(msg.items())
- self.raw_body = msg.get_payload().decode('utf8') # XXX encoding
- md = Markdown(extras=['code-friendly'], safe_mode='escape')
- self.body = genshi.Markup(md.convert(self.raw_body))
+ self.body = msg.get_payload().decode('utf8') # XXX encoding
self.author = self.metadata.get('from', None)
self.author_url = self.metadata.get('author-url', None)
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -8,7 +8,7 @@
<?python
import blog
-from viewutils import mini_markdown, tag_list
+from viewutils import markdown, mini_markdown, tag_list
from recaptcha.client import captcha
?>
@@ -26,7 +26,7 @@ from recaptcha.client import captcha
</div>
<div class="entrybody">
- ${entry.body}
+ ${markdown(entry.body)}
</div>
<div class="entrycommentslink" py:if="not show_comments and entry.has_comments()">
@@ -45,7 +45,7 @@ from recaptcha.client import captcha
<py:otherwise>${len(entry.comments())} comments</py:otherwise>
</h4>
<div py:for="n, comment in enumerate(comments)" id="comment-${comment.id}">
- ${comment.body}
+ ${markdown(comment.body, safe_mode='escape')}
<p class="commentmeta">
― <a py:strip="not comment.author_url" href="${comment.author_url}">${comment.author_name()}</a>
<span class="commentdatetime">${comment.date.strftime(str('%-1d %b %Y %H:%M'))}</span>
diff --git a/templates/multiple_atom.xml b/templates/multiple_atom.xml
@@ -1,5 +1,4 @@
<feed xmlns="http://www.w3.org/2005/Atom"
- xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
@@ -7,7 +6,7 @@
<?python
import blog
-from viewutils import tag_list
+from viewutils import markdown, tag_list
ATOM_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
?>
@@ -30,19 +29,23 @@ ATOM_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
<py:if test="isinstance(entry, blog.BlogEntry)">
<link rel="alternate" href="${abs_uri(entry.id)}" />
<title type="text">${entry.title}</title>
- <content type="xhtml" xml:base="${abs_uri(entry.id)}"><xhtml:div>
- <p py:if="entry.tags">Tagged: ${tag_list(environ.get('SCRIPT_NAME', ''), entry.tags)}</p>
- ${entry.body}
- </xhtml:div></content>
+ <content type="xhtml" xml:base="${abs_uri(entry.id)}">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <p py:if="entry.tags">Tagged: ${tag_list(environ.get('SCRIPT_NAME', ''), entry.tags)}</p>
+ ${markdown(entry.body)}
+ </div>
+ </content>
</py:if>
<py:if test="isinstance(entry, blog.ReadingLogEntry)">
<link rel="alternate" href="${abs_uri('+reading', '')}#entry-${entry.id}" />
<title type="text">${entry.title} by ${entry.author}</title>
<summary py:if="entry.rating" type="text">${entry.rating} stars</summary>
- <content type="xhtml"><xhtml:div>
- <p><a href="${entry.url}">${entry.title}</a> by ${entry.author}</p>
- <p py:if="entry.rating">${entry.rating} stars</p>
- </xhtml:div></content>
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <p><a href="${entry.url}">${entry.title}</a> by ${entry.author}</p>
+ <p py:if="entry.rating">${entry.rating} stars</p>
+ </div>
+ </content>
</py:if>
</entry>
diff --git a/viewutils.py b/viewutils.py
@@ -2,7 +2,11 @@ import re, urllib
from markdown2 import Markdown
import genshi
-def mini_markdown(s):
+def markdown(s, safe_mode=None):
+ m = Markdown(extras=['code_friendly'], safe_mode=safe_mode).convert(s)
+ return genshi.Markup(m)
+
+def mini_markdown(s, safe_mode=None):
# XXX find a more efficient way to do this?
m = Markdown(extras=['code_friendly']).convert(s)
match = re.match(u'<p>(.*)</p>', m)