mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactoring
This commit is contained in:
parent
fb770e9013
commit
6c48bc0d2f
@ -194,6 +194,28 @@ class Locale(Transform):
|
|||||||
Replace translatable nodes with their translated doctree.
|
Replace translatable nodes with their translated doctree.
|
||||||
"""
|
"""
|
||||||
default_priority = 0
|
default_priority = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _collect_nodes(cls, nodelist, node_types, custom_cond_func=None):
|
||||||
|
if custom_cond_func is None:
|
||||||
|
custom_cond_func = lambda x: True
|
||||||
|
|
||||||
|
collected = [node for node in nodelist
|
||||||
|
if isinstance(node, node_types)
|
||||||
|
and custom_cond_func(node)]
|
||||||
|
return collected
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _collect_footnote_ref_nodes(cls, nodelist):
|
||||||
|
return cls._collect_nodes(
|
||||||
|
nodelist,
|
||||||
|
nodes.footnote_reference,
|
||||||
|
lambda n: n.get('auto') == 1)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _collect_ref_nodes(cls, nodelist):
|
||||||
|
return cls._collect_nodes(nodelist, nodes.reference)
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
env = self.document.settings.env
|
env = self.document.settings.env
|
||||||
settings, source = self.document.settings, self.document['source']
|
settings, source = self.document.settings, self.document['source']
|
||||||
@ -226,10 +248,8 @@ class Locale(Transform):
|
|||||||
if not isinstance(patch, nodes.paragraph):
|
if not isinstance(patch, nodes.paragraph):
|
||||||
continue # skip for now
|
continue # skip for now
|
||||||
|
|
||||||
footnote_refs = [r for r in node.children
|
footnote_refs = self._collect_footnote_ref_nodes(node.children)
|
||||||
if isinstance(r, nodes.footnote_reference)
|
refs = self._collect_ref_nodes(node.children)
|
||||||
and r.get('auto') == 1]
|
|
||||||
refs = [r for r in node.children if isinstance(r, nodes.reference)]
|
|
||||||
|
|
||||||
for i, child in enumerate(patch.children): # update leaves
|
for i, child in enumerate(patch.children): # update leaves
|
||||||
if isinstance(child, nodes.footnote_reference) \
|
if isinstance(child, nodes.footnote_reference) \
|
||||||
|
Loading…
Reference in New Issue
Block a user