Skip to content
Browse files

Lxml by default writes out its tree as XML

By default lxml writes its parsetree out using XML rules, closing
empty tags. This is a problem when writing out HTML files.
  • Loading branch information...
1 parent 1618e66 commit af332e6c89a21d755ad1269b17c583b75c7933e1 @hpvb hpvb committed
Showing with 8 additions and 1 deletion.
  1. +8 −1 wok/contrib/hooks.py
View
9 wok/contrib/hooks.py
@@ -57,7 +57,14 @@ def __call__(self, page):
heading.set('id', name)
sio_destination = StringIO()
- tree.write(sio_destination)
+
+ # Use the extension of the template to determine the type of document
+ if page.template.filename.endswith(".html") or page.filename.endswith(".htm"):
+ logging.debug('[HeadingAnchors] outputting {0} as HTML'.format(page))
+ tree.write(sio_destination, method='html')
+ else:
+ logging.debug('[HeadingAnchors] outputting {0} as XML'.format(page))
+ tree.write(sio_destination)
page.rendered = sio_destination.getvalue()

0 comments on commit af332e6

Please sign in to comment.
Something went wrong with that request. Please try again.