From 013444722e3f67281d8764c4cc333c9fde3825ec Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 8 Jan 2018 13:19:02 +0100 Subject: [PATCH] Enable parsing of translated paragraphs (WARNING: temporary!) Fixes #154. --- src/nbsphinx.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nbsphinx.py b/src/nbsphinx.py index f1f0d3c6..f83e7f0d 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -619,8 +619,27 @@ def get_transforms(self): ProcessLocalLinks, ReplaceAlertDivs] def parse(self, inputstring, document): - """Parse `inputstring`, write results to `document`.""" - nb = nbformat.reads(inputstring, as_version=_ipynbversion) + """Parse *inputstring*, write results to *document*. + + *inputstring* is either the JSON representation of a notebook, + or a paragraph of text coming from the Sphinx translation + machinery. + + Note: For now, the translation strings use reST formatting, + because the NotebookParser uses reST as intermediate + representation. + However, there are plans to remove this intermediate step + (https://github.com/spatialaudio/nbsphinx/issues/36), and after + that, the translated strings will most likely be parsed as + CommonMark. + + """ + try: + nb = nbformat.reads(inputstring, as_version=_ipynbversion) + except Exception: + # NB: The use of the RST parser is temporary! + rst.Parser.parse(self, inputstring, document) + return env = document.settings.env srcdir = os.path.dirname(env.doc2path(env.docname)) auxdir = os.path.join(env.doctreedir, 'nbsphinx')