myst_parser.mocking
#
This module provides classes to Mock the core components of the docutils.RSTParser, the key difference being that nested parsing treats the text as Markdown not rST.
1. Module Contents#
1.1. Classes#
A mock version of docutils.parsers.rst.states.Inliner. |
|
A mock version of docutils.parsers.rst.states.RSTState. |
|
A mock version of docutils.parsers.rst.states.RSTStateMachine. |
|
This directive uses a lot of statemachine logic that is not yet mocked. Therefore, we treat it as a special case (at least for now). |
|
RSTParser which avoids a negative side effect. |
1.2. API#
- exception myst_parser.mocking.MockingError[源代码]#
Bases:
Exception
An exception to signal an error during mocking of docutils components.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- class myst_parser.mocking.MockInliner(renderer: myst_parser.mdit_to_docutils.base.DocutilsRenderer)[源代码]#
A mock version of docutils.parsers.rst.states.Inliner.
This is parsed to role functions.
Initialization
Initialize the mock inliner.
- class myst_parser.mocking.MockState(renderer: myst_parser.mdit_to_docutils.base.DocutilsRenderer, state_machine: myst_parser.mocking.MockStateMachine, lineno: int)[源代码]#
A mock version of docutils.parsers.rst.states.RSTState.
This is parsed to the Directives.run() method, so that they may run nested parses on their content that will be parsed as markdown, rather than RST.
Initialization
- parse_directive_block(content: docutils.statemachine.StringList, line_offset: int, directive: type[docutils.parsers.rst.Directive], option_presets: dict[str, Any]) tuple[list[str], dict[str, Any], docutils.statemachine.StringList, int] [源代码]#
Parse the full directive text
- 抛出:
MarkupError -- for errors in parsing the directive
- 返回:
(arguments, options, content, content_offset)
- nested_parse(block: docutils.statemachine.StringList, input_offset: int, node: docutils.nodes.Element, match_titles: bool = False, state_machine_class=None, state_machine_kwargs=None) None [源代码]#
Perform a nested parse of the input block, with
node
as the parent.- 参数:
block -- The block of lines to parse.
input_offset -- The offset of the first line of block, to the starting line of the state (i.e. directive).
node -- The parent node to attach the parsed content to.
match_titles -- Whether to to allow the parsing of headings (normally this is false, since nested heading would break the document structure)
- parse_target(block, block_text, lineno: int)[源代码]#
Taken from docutils-mirror/docutils
- inline_text(text: str, lineno: int) tuple[list[docutils.nodes.Element], list[docutils.nodes.Element]] [源代码]#
Parse text with only inline rules.
- 返回:
(list of nodes, list of messages)
- attribution_pattern = 'compile(...)'#
- class myst_parser.mocking.MockStateMachine(renderer: myst_parser.mdit_to_docutils.base.DocutilsRenderer, lineno: int)[源代码]#
A mock version of docutils.parsers.rst.states.RSTStateMachine.
This is parsed to the Directives.run() method.
Initialization
- class myst_parser.mocking.MockIncludeDirective(renderer: myst_parser.mdit_to_docutils.base.DocutilsRenderer, name: str, klass: type[docutils.parsers.rst.directives.misc.Include], arguments: list[str], options: dict[str, Any], body: list[str], lineno: int)[源代码]#
This directive uses a lot of statemachine logic that is not yet mocked. Therefore, we treat it as a special case (at least for now).
See: https://docutils.sourceforge.io/docs/ref/rst/directives.html#including-an-external-document-fragment
Initialization