CVS: ht2html rst_html.py,1.1,1.2
David Goodger <[email protected]> Tue, 20 Jul 2004 16:16:46 -0700
| Newsgroups | gmane.comp.web.ht2html.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ht2html/ht2html
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27488
Modified Files:
rst_html.py
Log Message:
added support for "encoding" header
Index: rst_html.py
===================================================================
RCS file: /cvsroot/ht2html/ht2html/rst_html.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rst_html.py 26 Jul 2003 10:39:05 -0000 1.1
--- rst_html.py 20 Jul 2004 23:16:44 -0000 1.2
***************
*** 2,52 ****
# Code for translating ReST to HTML suitable for inclusion in a page.
#
! # Originally from AMK's unreleased weblogging software (visible in CVS
! # at www.sf.net/oedipus).
!
! import StringIO
! from docutils import core, io
! from docutils.writers import html4css1
!
!
! class WeblogWriter (html4css1.Writer):
! def __init__ (self):
! html4css1.Writer.__init__(self)
! self.translator_class = WeblogHTMLTranslator
! class WeblogHTMLTranslator (html4css1.HTMLTranslator):
! def __init__(self, document):
! html4css1.HTMLTranslator.__init__(self, document)
! self.head_prefix = []
! self.body_prefix = []
! self.stylesheet = []
! self.body_suffix = []
! self.section_level = 2
!
! def visit_system_message(self, node):
! pass
- def visit_document (self, node):
- pass
-
- def depart_document (self, node):
- pass
-
def process_rst (filename, body):
"Parse 'body' as RST and convert it to HTML"
! output_file = StringIO.StringIO()
! body = core.publish_string(
reader_name='standalone',
parser_name='restructuredtext',
- writer=WeblogWriter(),
writer_name='html',
! source_path=filename,
! source=body,
! destination_path=filename,
! settings=None)
!
! body = unicode(body, 'utf-8')
! body = body.encode('latin-1')
! return body
!
--- 2,30 ----
# Code for translating ReST to HTML suitable for inclusion in a page.
#
! # Originally from AMK's unreleased weblogging software (visible in CVS
! # at www.sf.net/oedipus).
! import docutils.core
def process_rst (filename, body):
"Parse 'body' as RST and convert it to HTML"
! settings = {
! # `body` text already decoded (already Unicode):
! 'input_encoding': 'unicode',
! # start section titles at <h3>:
! 'initial_header_level': 3,
! # document title given in .ht headers; don't take from section title:
! 'doctitle_xform': None}
! parts = docutils.core.publish_parts(
! source=body,
! source_path=filename,
! destination_path=filename,
reader_name='standalone',
parser_name='restructuredtext',
writer_name='html',
! settings_overrides=settings,
! # for Docutils config files:
! config_section='ht2html application')
! body = parts['fragment']
! return body.encode('latin-1', 'xmlcharrefreplace')
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click