changeset 75:6b8ccf6ec819

move restructured text string rendering to its own method
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 24 Sep 2010 19:01:07 -0700
parents e6055bf127eb
children c690198a2625
files bitsyblog/bitsyblog.py bitsyblog/utils.py
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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 = '<br/>\n'.join(lines)
-            
-
+        """renders a string with restructured text"""            
+        body = utils.ReST2html(string)
         retval = '<div class="blog-body">%s</div>' % body
         return retval
 
--- 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 = '<br/>\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'