def apply(self):
ExtractImages._external_data = set()
- for image in self.document.traverse(docutils.nodes.image):
+ for image in self.document.findall(docutils.nodes.image):
# Skip absolute URLs
if urllib.parse.urlparse(image['uri']).netloc: continue
# Extract metadata from the page
metadata = {}
- for docinfo in pub.document.traverse(docutils.nodes.docinfo):
+ for docinfo in pub.document.findall(docutils.nodes.docinfo):
for element in docinfo.children:
if element.tagname == 'field':
name_elem, body_elem = element.children
'embed_stylesheet': False
}
+# findall() is new in docutils 0.18, replacing traverse() because that one was
+# attempted to be changed to return an iterator instead of a list, which broke
+# Sphinx, so it instead got deprecated in favor of findall() which is the same
+# as traverse() returning an iterator was. To retain compatibility with earlier
+# versions, add an alias.
+if not hasattr(docutils.nodes.Node, 'findall'):
+ setattr(docutils.nodes.Node, 'findall', docutils.nodes.Node.traverse)
+
words_re = re.compile(r'\w+', re.UNICODE|re.X)
def extract_document_language(document):
language = document.settings.language_code
# Then try to find the :lang: metadata option
- for field in document.traverse(nodes.field):
+ for field in document.findall(nodes.field):
assert isinstance(field[0], nodes.field_name)
assert isinstance(field[1], nodes.field_body)
# field_body -> paragraph -> text
# "Educate" quotes in normal text. Handle each block of text
# (TextElement node) as a unit to keep context around inline nodes:
- for node in self.document.traverse(nodes.TextElement):
+ for node in self.document.findall(nodes.TextElement):
# skip preformatted text blocks and special elements:
if isinstance(node, (nodes.FixedTextElement, nodes.Special)):
continue
# list of text nodes in the "text block":
# Patched here to exclude more stuff.
txtnodes = []
- for txtnode in node.traverse(nodes.Text):
+ for txtnode in node.findall(nodes.Text):
if not can_apply_typography(txtnode): continue
# Don't convert -- in option strings
if isinstance(txtnode.parent, nodes.option_string): continue
pyphen_for_lang = {}
# Go through all text words and hyphenate them
- for node in self.document.traverse(nodes.TextElement):
+ for node in self.document.findall(nodes.TextElement):
# Skip preformatted text blocks and special elements
if isinstance(node, (nodes.FixedTextElement, nodes.Special)):
continue
- for txtnode in node.traverse(nodes.Text):
+ for txtnode in node.findall(nodes.Text):
if not can_apply_typography(txtnode): continue
# Don't hyphenate document title. Not part of