Created
January 10, 2019 13:17
-
-
Save tk0miya/65a1d012d91ed1c8f010dd808f4edfe3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from docutils import languages, nodes | |
from docutils.parsers.rst.states import Struct | |
from sphinx.writers.latex import LaTeXTranslator | |
def quote_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): | |
language = languages.get_language(inliner.document.settings.language_code, | |
inliner.document.reporter) | |
memo = Struct(document=inliner.document, | |
reporter=inliner.document.reporter, | |
language=language) | |
inline = nodes.inline(rawtext, '', classes=['quoted']) | |
inodes, messages = inliner.parse(text, lineno, memo, inline) | |
inline += inodes | |
return [inline], inodes | |
class QuoteLaTeXTranslator(LaTeXTranslator): | |
def visit_inline(self, node): | |
classes = node.get('classes', []) | |
if 'quoted' in classes: | |
self.body.append('``') | |
self.context.append("''") | |
else: | |
super().visit_inline(node) | |
def setup(app): | |
app.add_role('quote', quote_role) | |
app.set_translator('latex', QuoteLaTeXTranslator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment