myst_parser.parsers.docutils_
#
MyST Markdown parser for docutils.
1. Module Contents#
1.1. Classes#
A sentinel class for unset settings. |
|
Docutils parser for Markedly Structured Text (MyST). |
|
1.2. Functions#
Convert an |
|
Return a list of Docutils setting for the docutils MyST section. |
|
Create a configuration instance from the given settings. |
|
Cmdline entrypoint for converting MyST to HTML. |
|
Cmdline entrypoint for converting MyST to HTML5. |
|
Cmdline entrypoint for converting MyST to simple HTML5 demonstrations. |
|
Convert a MyST string to HTML5. |
|
Cmdline entrypoint for converting MyST to LaTeX. |
|
Cmdline entrypoint for converting MyST to XML. |
|
Cmdline entrypoint for converting MyST to pseudo-XML. |
|
Override the default HTML visit method for rubric nodes. |
|
Override the default HTML visit method for rubric nodes. |
|
Override the default HTML visit method for container nodes. |
|
Override the default HTML depart method for container nodes. |
1.3. Data#
Sentinel for arguments not set through docutils.conf. |
1.4. API#
- myst_parser.parsers.docutils_.DOCUTILS_UNSET = 'Unset(...)'#
Sentinel for arguments not set through docutils.conf.
- myst_parser.parsers.docutils_.attr_to_optparse_option(attribute: dataclasses.Field, default: Any, prefix: str = 'myst_') tuple[str, list[str], dict[str, Any]] [源代码]#
Convert an
MdParserConfig
attribute into a Docutils setting tuple.- 返回:
A tuple of
(help string, option flags, optparse kwargs)
.
- myst_parser.parsers.docutils_.create_myst_settings_spec(config_cls=MdParserConfig, prefix: str = 'myst_')[源代码]#
Return a list of Docutils setting for the docutils MyST section.
- myst_parser.parsers.docutils_.create_myst_config(settings: docutils.frontend.Values, config_cls=MdParserConfig, prefix: str = 'myst_')[源代码]#
Create a configuration instance from the given settings.
- class myst_parser.parsers.docutils_.Parser(rfc2822=False, inliner=None)[源代码]#
Bases:
docutils.parsers.rst.Parser
Docutils parser for Markedly Structured Text (MyST).
Initialization
- settings_spec = ('MyST options', None)#
Runtime settings specification.
- config_section = 'myst parser'#
- config_section_dependencies = ('parsers',)#
- translate_section_name = None#
- class myst_parser.parsers.docutils_.SimpleTranslator(document)[源代码]#
Bases:
docutils.writers.html5_polyglot.HTMLTranslator
- class myst_parser.parsers.docutils_.SimpleWriter[源代码]#
Bases:
docutils.writers.html5_polyglot.Writer
- settings_spec = 'filter_settings_spec(...)'#
- myst_parser.parsers.docutils_.cli_html(argv: list[str] | None = None) None [源代码]#
Cmdline entrypoint for converting MyST to HTML.
- myst_parser.parsers.docutils_.cli_html5(argv: list[str] | None = None)[源代码]#
Cmdline entrypoint for converting MyST to HTML5.
- myst_parser.parsers.docutils_.cli_html5_demo(argv: list[str] | None = None)[源代码]#
Cmdline entrypoint for converting MyST to simple HTML5 demonstrations.
This is a special case of the HTML5 writer, that only outputs the body of the document.
- myst_parser.parsers.docutils_.to_html5_demo(inputstring: str, **kwargs) str [源代码]#
Convert a MyST string to HTML5.
- myst_parser.parsers.docutils_.cli_latex(argv: list[str] | None = None)[源代码]#
Cmdline entrypoint for converting MyST to LaTeX.
- myst_parser.parsers.docutils_.cli_xml(argv: list[str] | None = None)[源代码]#
Cmdline entrypoint for converting MyST to XML.
- myst_parser.parsers.docutils_.cli_pseudoxml(argv: list[str] | None = None)[源代码]#
Cmdline entrypoint for converting MyST to pseudo-XML.
- myst_parser.parsers.docutils_.visit_rubric_html(self, node)[源代码]#
Override the default HTML visit method for rubric nodes.
docutils structures a document, based on the headings, into nested sections:
# h1 ## h2 ### h3 <section> <title> h1 <section> <title> h2 <section> <title> h3
This means that it is not possible to have "standard" headings nested inside other components, such as blockquotes, because it would break the structure:
# h1 > ## h2 ### h3 <section> <title> h1 <blockquote> <section> <title> h2 <section> <title> h3
we work around this shortcoming, in DocutilsRenderer.render_heading, by identifying if a heading is inside another component and instead outputting it as a "non-structural" rubric node, and capture the level:
<section> <title> h1 <blockquote> <rubric level=2> h2 <section> <title> h3
However, docutils natively just outputs rubrics as <p> tags, and does not "honor" the heading level. So here we override the visit/depart methods to output the correct <h> element
- myst_parser.parsers.docutils_.depart_rubric_html(self, node)[源代码]#
Override the default HTML visit method for rubric nodes.
See explanation in visit_rubric_html