comparison bitsyblog/bitsyblog.py @ 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 c9bab68d00ac
children c690198a2625
comparison
equal deleted inserted replaced
73:e6055bf127eb 75:6b8ccf6ec819
8 8
9 ### imports 9 ### imports
10 10
11 import dateutil.parser 11 import dateutil.parser
12 12
13 import cgi
14 import datetime 13 import datetime
15 import docutils 14 import docutils
16 import docutils.core 15 import docutils.core
17 import inspect 16 import inspect
18 import os 17 import os
652 print >> buffer, '[ %s ]\n' % entry.date.strftime(self.date_format) 651 print >> buffer, '[ %s ]\n' % entry.date.strftime(self.date_format)
653 print >> buffer, entry.body.strip() + '\n' 652 print >> buffer, entry.body.strip() + '\n'
654 return buffer.getvalue() 653 return buffer.getvalue()
655 654
656 def restructuredText(self, string): 655 def restructuredText(self, string):
657 """renders a string with restructured text""" 656 """renders a string with restructured text"""
658 657 body = utils.ReST2html(string)
659 settings = { 'report_level': 5 }
660 string = string.strip()
661 try:
662
663 parts = docutils.core.publish_parts(string,
664 writer_name='html',
665 settings_overrides=settings)
666 body = parts['body']
667 except (SystemMessage, UnicodeError), e:
668 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ]
669 body = '<br/>\n'.join(lines)
670
671
672 retval = '<div class="blog-body">%s</div>' % body 658 retval = '<div class="blog-body">%s</div>' % body
673 return retval 659 return retval
674 660
675 # # XXX this should be reenabled if 'system-message's again appear in the markup 661 # # XXX this should be reenabled if 'system-message's again appear in the markup
676 # try: 662 # try: