Skip to content

Commit

Permalink
Update to rst html5writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Dec 30, 2013
1 parent cc998cc commit c6440df
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions content/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions lib/html5writer.py
Original file line number Diff line number Diff line change
@@ -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('</section>\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('</section>\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('</code>')


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('</%s>\n' % elem_name)
2 changes: 1 addition & 1 deletion output

0 comments on commit c6440df

Please sign in to comment.