Python API#

Text to docutils AST#

rst_to_myst.parser.to_docutils_ast(text: str, uri: str = 'source', report_level=2, halt_level=4, warning_stream=None, language_code='en', use_sphinx=True, extensions=(), default_domain='py', conversions=None, front_matter=True) Tuple[docutils.nodes.document, _io.StringIO][source]#

docutils AST to Markdown-It Tokens#

class rst_to_myst.markdownit.RenderOutput(tokens, env)[source]#
property env#

Alias for field number 1

property tokens#

Alias for field number 0

class rst_to_myst.markdownit.MarkdownItRenderer(document: docutils.nodes.document, *, warning_stream: Optional[IO] = None, raise_on_warning: bool = False, cite_prefix: str = 'cite_', default_role: Optional[str] = None, colon_fences: bool = True, dollar_math: bool = True)[source]#

Render docutils AST to Markdown-It token stream.

add_token(ttype: str, tag: str, nesting: int, *, content: str = '', **kwargs: Any) markdown_it.token.Token[source]#

A markdown-it token to the stream, handling inline tokens and children.

default_departure(node)[source]#

Override for generic, uniform traversals.

default_visit(node)[source]#

Override for generic, uniform traversals.

parse_gfm_table(node) bool[source]#

Check whether an RST table can be converted to a GFM one.

RST tables can have e.g. cells spanning multiple columns/rows, which the GitHub Flavoured Markdown (GFM) table variant does not support.

to_tokens() rst_to_myst.markdownit.RenderOutput[source]#

Reset tokens and convert full document.

unknown_departure(node)[source]#

Called before exiting unknown Node types.

Raise exception unless overridden.

unknown_visit(node)[source]#

Called when entering unknown Node types.

Raise an exception unless overridden.

Markdown-It Tokens to Text#

rst_to_myst.mdformat_render.from_tokens(output: rst_to_myst.markdownit.RenderOutput, *, consecutive_numbering: bool = True, warning_stream: Optional[IO] = None) str[source]#

Convert markdown-it tokens to text.

Full Conversion#

class rst_to_myst.mdformat_render.ConvertedOutput(text: str, tokens: List[markdown_it.token.Token], env: Dict[str, Any], warning_stream: IO, extensions: Set[str])[source]#

Output from rst_to_myst.

property env#

Alias for field number 2

property extensions#

Alias for field number 4

property text#

Alias for field number 0

property tokens#

Alias for field number 1

property warning_stream#

Alias for field number 3

rst_to_myst.mdformat_render.rst_to_myst(text: str, *, warning_stream: Optional[IO] = None, language_code='en', use_sphinx: bool = True, extensions: Iterable[str] = (), conversions: Optional[Dict[str, str]] = None, default_domain: str = 'py', default_role: Optional[str] = None, raise_on_warning: bool = False, cite_prefix: str = 'cite_', consecutive_numbering: bool = True, colon_fences: bool = True, dollar_math: bool = True) rst_to_myst.mdformat_render.ConvertedOutput[source]#

Convert RST text to MyST Markdown text.

Parameters
  • text – The input RST text

  • warning_stream – The warning IO to write to

  • language_code – the language module to use, for directive/role name translation

  • use_sphinx – Whether to load sphinx roles, directives and extentions

  • extensions – Sphinx extension to load

  • conversions – Overrides for mapping of how to convert directives; directive module path -> conversion type

  • default_domain – name of the default sphinx domain

  • default_role – name of the default role, otherwise convert to a literal

  • cite_prefix – Prefix to add to citation references

  • raise_on_warning – Raise exception on parsing warning

  • consecutive_numbering – Apply consecutive numbering to ordered lists

  • colon_fences – Use colon fences for directives with parsed content

  • dollar_math – Convert math (where possible) to dollar-delimited math