Fix #3212: HTML Builders crashes with docutils-0.13

This commit is contained in:
Takeshi KOMIYA 2016-12-10 20:29:34 +09:00
parent e6ca4ee919
commit 3adc236114
3 changed files with 14 additions and 2 deletions

View File

@ -15,8 +15,8 @@ env:
- PYTHONFAULTHANDLER=x
- PYTHONWARNINGS=all
matrix:
- DOCUTILS=0.11
- DOCUTILS=0.12
- DOCUTILS=0.13.1
addons:
apt:
packages:

View File

@ -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)

View File

@ -16,6 +16,7 @@ import copy
import warnings
from six import string_types
import docutils
from docutils import nodes
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
@ -500,7 +501,7 @@ class HTMLTranslator(BaseTranslator):
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']
@ -532,6 +533,16 @@ class HTMLTranslator(BaseTranslator):
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