From c6440df3bc73f9a3cbc9ee596d2d15100b68c02b Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 30 Dec 2013 01:09:04 -0500 Subject: [PATCH] Update to rst html5writer. --- content/config.yml | 1 + lib/html5writer.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ output | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lib/html5writer.py diff --git a/content/config.yml b/content/config.yml index 330da5f..8810cab 100644 --- a/content/config.yml +++ b/content/config.yml @@ -4,6 +4,7 @@ author: Eric A. Meyer canonical_url: http://susy.oddbird.com/ output_folder: ../output template_path: ../templates +rst_writer: html5writer modules: pygments: style: borland diff --git a/lib/html5writer.py b/lib/html5writer.py new file mode 100644 index 0000000..ba49b53 --- /dev/null +++ b/lib/html5writer.py @@ -0,0 +1,61 @@ +""" +A docutils HTML5 writer based on the built-in html4css1 writer. + +Work in progress. + +""" +from docutils.writers import html4css1 + + +class Writer(html4css1.Writer): + def __init__(self): + html4css1.Writer.__init__(self) + self.translator_class = HTML5Translator + + +class HTML5Translator(html4css1.HTMLTranslator): + def visit_section(self, node): + self.section_level += 1 + self.body.append( + self.starttag(node, 'section')) + + + def depart_section(self, node): + self.section_level -= 1 + self.body.append('\n') + + + def visit_topic(self, node): + self.body.append(self.starttag(node, 'section')) + self.topic_classes = node['classes'] + + + def depart_topic(self, node): + self.body.append('\n') + self.topic_classes = [] + + + def visit_list_item(self, node): + self.body.append(self.starttag(node, 'li', '')) + + + def visit_literal_block(self, node): + self.body.append(self.starttag(node, 'pre')) + + + def visit_literal(self, node): + self.body.append(self.starttag(node, 'code', suffix='')) + + + def depart_literal(self, node): + self.body.append('') + + + def visit_container(self, node): + elem_name = getattr(node, 'element_name', 'div') + self.body.append(self.starttag(node, elem_name)) + + + def depart_container(self, node): + elem_name = getattr(node, 'element_name', 'div') + self.body.append('\n' % elem_name) diff --git a/output b/output index 184d49b..4adacef 160000 --- a/output +++ b/output @@ -1 +1 @@ -Subproject commit 184d49b4988b35a6933eb5eacfa1938ca2a59755 +Subproject commit 4adacef89cb000a2ea8c5dafc3adcbee3a76c773