MCPcopy
hub / github.com/sphinx-doc/sphinx / parse

Function parse

sphinx/testing/restructuredtext.py:14–46  ·  view source on GitHub ↗

Parse a string as reStructuredText with Sphinx.

(app: Sphinx, text: str, docname: str = 'index')

Source from the content-addressed store, hash-verified

12
13
14def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document:
15 """Parse a string as reStructuredText with Sphinx."""
16 config = app.config
17 env = app.env
18 registry = app.registry
19 srcdir = app.srcdir
20
21 # Get settings
22 settings_overrides = {
23 'env': env,
24 'gettext_compact': True,
25 'input_encoding': 'utf-8',
26 'output_encoding': 'unicode',
27 'traceback': True,
28 }
29
30 # Create parser
31 parser = RSTParser()
32 parser._config = config
33 parser._env = env
34
35 env.current_document.docname = docname
36 try:
37 return _parse_str_to_doctree(
38 text,
39 filename=srcdir / f'{docname}.rst',
40 default_settings=settings_overrides,
41 env=env,
42 parser=parser,
43 transforms=registry.get_transforms(),
44 )
45 finally:
46 env.current_document.docname = ''

Callers

nothing calls this directly

Calls 3

RSTParserClass · 0.90
_parse_str_to_doctreeFunction · 0.90
get_transformsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…