Merge pull request #102 from FireflyTeam/add-translate-section-name

Add section name translate support
This commit is contained in:
Eric Holscher 2018-05-30 15:59:43 -04:00 committed by GitHub
commit 956bf18b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,7 @@ class CommonMarkParser(parsers.Parser):
"""Docutils parser for CommonMark"""
supported = ('md', 'markdown')
translate_section_name = None
def __init__(self):
self._level_to_elem = {}
@ -93,7 +94,10 @@ class CommonMarkParser(parsers.Parser):
assert isinstance(self.current_node, nodes.title)
# The title node has a tree of text nodes, use the whole thing to
# determine the section id and names
name = nodes.fully_normalize_name(self.current_node.astext())
text = self.current_node.astext()
if self.translate_section_name:
text = self.translate_section_name(text)
name = nodes.fully_normalize_name(text)
section = self.current_node.parent
section['names'].append(name)
self.document.note_implicit_target(section, section)