Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable parsing of translated paragraphs (WARNING: temporary!) #156

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down