Skip to content

Commit

Permalink
Fix sphinx-doc#3212: HTML Builders crashes with docutils-0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Dec 10, 2016
1 parent e6ca4ee commit 3adc236
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ env:
- PYTHONFAULTHANDLER=x
- PYTHONWARNINGS=all
matrix:
- DOCUTILS=0.11
- DOCUTILS=0.12
- DOCUTILS=0.13.1
addons:
apt:
packages:
Expand Down
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bugs fixed
* #3198: AttributeError is raised when toctree has 'self'
* #3211: Remove untranslated sphinx locale catalogs (it was covered by
untranslated it_IT)
* #3212: HTML Builders crashes with docutils-0.13


Release 1.5 (released Dec 5, 2016)
Expand Down
13 changes: 12 additions & 1 deletion sphinx/writers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import warnings

from six import string_types
import docutils
from docutils import nodes
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator

Expand Down Expand Up @@ -500,7 +501,7 @@ def visit_image(self, node):
self.builder.images[olduri])

uri = node['uri']
if uri.lower().endswith('svg') or uri.lower().endswith('svgz'):
if uri.lower().endswith(('svg', 'svgz')):
atts = {'src': uri}
if 'width' in node:
atts['width'] = node['width']
Expand Down Expand Up @@ -532,6 +533,16 @@ def visit_image(self, node):
node['height'] = str(size[1])
BaseTranslator.visit_image(self, node)

# overwritten
def depart_image(self, node):
if docutils.__version__ >= "0.13":
# since docutils-0.13, HTMLWriter does not push context data on visit_image()
if node['uri'].lower().endswith(('svg', 'svgz')):
self.body.append(self.context.pop())
else:
# docutils-0.12 or below, HTML Writer always push context data on visit_image()
self.body.append(self.context.pop())

def visit_toctree(self, node):
# this only happens when formatting a toc from env.tocs -- in this
# case we don't want to include the subtree
Expand Down

0 comments on commit 3adc236

Please sign in to comment.