forked from sphinx-doc/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sphinx.testing.restructuredtext.parse()
- Loading branch information
Showing
3 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
sphinx.testing.restructuredtext | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
from docutils.core import publish_doctree | ||
|
||
from sphinx.io import SphinxStandaloneReader | ||
from sphinx.parsers import RSTParser | ||
from sphinx.util.docutils import sphinx_domains | ||
|
||
|
||
if False: | ||
# For type annotation | ||
from docutils import nodes # NOQA | ||
from sphinx.application import Sphinx # NOQA | ||
|
||
|
||
def parse(app, text, docname='index'): | ||
# type: (Sphinx, str, str) -> nodes.document | ||
"""Parse a string as reStructuredText with Sphinx application.""" | ||
try: | ||
app.env.temp_data['docname'] = docname | ||
parser = RSTParser() | ||
parser.set_application(app) | ||
with sphinx_domains(app.env): | ||
return publish_doctree(text, app.srcdir / docname + '.rst', | ||
reader=SphinxStandaloneReader(app), | ||
parser=parser, | ||
settings_overrides={'env': app.env, | ||
'gettext_compact': True}) | ||
finally: | ||
app.env.temp_data.pop('docname', None) |
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