diff options
author | JensDiemer <git@jensdiemer.de> | 2011-08-03 18:11:29 +0200 |
---|---|---|
committer | JensDiemer <git@jensdiemer.de> | 2011-08-03 18:11:29 +0200 |
commit | 44666cf83114f98199c701cb5fb849c9de379abe (patch) | |
tree | eaa4d02262278a3daa6a2cc05155227ac4388fda /creole/shared | |
parent | dfc2f500e772e9a5d042d110bd5fdfe5e2a7e182 (diff) | |
download | creole-44666cf83114f98199c701cb5fb849c9de379abe.tar.gz |
Some bugfixes around html2rest
Diffstat (limited to 'creole/shared')
-rw-r--r-- | creole/shared/base_emitter.py | 9 | ||||
-rw-r--r-- | creole/shared/rest.py | 112 |
2 files changed, 5 insertions, 116 deletions
diff --git a/creole/shared/base_emitter.py b/creole/shared/base_emitter.py index 6b7f6c8..f3fc5bb 100644 --- a/creole/shared/base_emitter.py +++ b/creole/shared/base_emitter.py @@ -222,10 +222,11 @@ class BaseEmitter(object): self.last = node return content - def emit(self): - """Emit the document represented by self.root DOM tree.""" - result = self.emit_node(self.root) - return result.strip() # FIXME +# def emit(self): +# """Emit the document represented by self.root DOM tree.""" +# result = self.emit_node(self.root) +## return result.strip() # FIXME +# return result.rstrip() # FIXME #------------------------------------------------------------------------- diff --git a/creole/shared/rest.py b/creole/shared/rest.py deleted file mode 100644 index 15c7d0b..0000000 --- a/creole/shared/rest.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -""" - Some code stolen from: - http://www.arnebrodowski.de/blog/write-your-own-restructuredtext-writer.html -""" - - -import warnings - - -try: - from docutils.core import publish_parts -except ImportError: - REST_INSTALLED = False - warnings.warn( - "Markup error: 'Python Documentation Utilities' isn't installed. Can't test reStructuredText." - " Download: http://pypi.python.org/pypi/docutils" - ) -else: - REST_INSTALLED = True - - -from docutils.writers import html4css1 - - -DEBUG = False -#DEBUG = True - -IGNORE_ATTR = ( - "class", -) - - -class CleanHTMLWriter(html4css1.Writer): - """ - This docutils writer will use the CleanHTMLTranslator class below. - """ - def __init__(self): - html4css1.Writer.__init__(self) - self.translator_class = CleanHTMLTranslator - -class CleanHTMLTranslator(html4css1.HTMLTranslator): - """ - This is a translator class for the docutils system. - It will produce a minimal set of html output. - (No extry divs, classes oder ids.) - """ - def starttag(self, node, tagname, suffix='\n', empty=0, **attributes): - if DEBUG: - print "ids: %r" % getattr(node, "ids", "-") - node.ids = [] - if DEBUG: - print "attributes: %r" % attributes - for attr in IGNORE_ATTR: - for attr2 in (attr, attr.lower(), attr.upper()): - if attr2 in attributes: - del(attributes[attr2]) - - return html4css1.HTMLTranslator.starttag(self, node, tagname, suffix, empty, **attributes) - - def visit_section(self, node): - self.section_level += 1 - - def depart_section(self, node): - self.section_level -= 1 - - #__________________________________________________________________________ - # Clean table: - - def do_nothing(self, node): - pass - visit_thead = do_nothing - depart_thead = do_nothing - visit_tbody = do_nothing - depart_tbody = do_nothing - - def visit_table(self, node): - self.body.append(self.starttag(node, 'table')) - - def visit_tgroup(self, node): - node.stubs = [] - -def rest2html(content): - """ - >>> rest2html(u"- bullet list") - u'<ul>\\n<li>bullet list</li>\\n</ul>\\n' - """ - parts = publish_parts( - source=content, -# writer_name="html4css1", - writer=CleanHTMLWriter(), - settings_overrides={ - "input_encoding": "unicode", - "doctitle_xform": False, - }, - ) - return parts["fragment"] - - -if __name__ == '__main__': - import doctest - print doctest.testmod() - - print rest2html(u""" -+------------+------------+ -| Headline 1 | Headline 2 | -+============+============+ -| cell one | cell two | -+------------+------------+ - """) |