Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix a problem with HeadingAnchors to not write out html as xml #92

Merged
merged 1 commit into from

2 participants

@hpvb

This code adds a trivial check on the extension of the template used to generate the file. If the template ends in html or htm it will instruct lxml to treat the stream as HTML.

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 '''
@mythmon Owner
mythmon added a note

This should be a comment instead of a string. This isn't a docstring, so the triple quote syntax shouldn't be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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"):
@mythmon Owner
mythmon added a note

This should probably check for .html instead of just html. (ie, include the .)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mythmon
Owner

The commit message should be structures as a short subject, followed by a blank line, followed by the body. The subject should be less than 50 characters.

Notices how the commit message you have now is truncated on the commits tab of this page.

@hpvb hpvb 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.
af332e6
@mythmon mythmon merged commit 50c9405 into mythmon:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 18, 2012
  1. @hpvb

    Lxml by default writes out its tree as XML

    hpvb authored
    By default lxml writes its parsetree out using XML rules, closing
    empty tags. This is a problem when writing out HTML files.
This page is out of date. Refresh to see the latest.
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()
Something went wrong with that request. Please try again.