# HG changeset patch # User Jeff Hammel # Date 1285380067 25200 # Node ID 6b8ccf6ec8198ab7a656f252a466731c9369eb7c # Parent e6055bf127ebd52991cd91199929033222034d7a move restructured text string rendering to its own method diff -r e6055bf127eb -r 6b8ccf6ec819 bitsyblog/bitsyblog.py --- a/bitsyblog/bitsyblog.py Thu Jul 08 11:13:08 2010 -0700 +++ b/bitsyblog/bitsyblog.py Fri Sep 24 19:01:07 2010 -0700 @@ -10,7 +10,6 @@ import dateutil.parser -import cgi import datetime import docutils import docutils.core @@ -654,21 +653,8 @@ return buffer.getvalue() def restructuredText(self, string): - """renders a string with restructured text""" - - settings = { 'report_level': 5 } - string = string.strip() - try: - - parts = docutils.core.publish_parts(string, - writer_name='html', - settings_overrides=settings) - body = parts['body'] - except (SystemMessage, UnicodeError), e: - lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] - body = '
\n'.join(lines) - - + """renders a string with restructured text""" + body = utils.ReST2html(string) retval = '
%s
' % body return retval diff -r e6055bf127eb -r 6b8ccf6ec819 bitsyblog/utils.py --- a/bitsyblog/utils.py Thu Jul 08 11:13:08 2010 -0700 +++ b/bitsyblog/utils.py Fri Sep 24 19:01:07 2010 -0700 @@ -1,5 +1,6 @@ """utlity functions for bitsyblog""" +import cgi import datetime import os import urllib @@ -9,6 +10,22 @@ timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' ) timestamp = '%Y%m%d%H%M%S' # strftime representation +def ReST2html(string): + """renders a string with restructured text""" + + settings = { 'report_level': 5 } + string = string.strip() + try: + + parts = docutils.core.publish_parts(string, + writer_name='html', + settings_overrides=settings) + body = parts['body'] + except (SystemMessage, UnicodeError), e: + lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] + body = '
\n'.join(lines) + return body + def validate_css(css): """use a webservice to determine if the argument is valid css""" url = 'http://jigsaw.w3.org/css-validator/validator?text=%s'