Skip to content

MarkdownItPyrsParser

Base classes

Name Children Inherits
MarkdownParser
mkconvert.parsers.base
Base class for Markdown -> HTML parsers.

⋔ Inheritance diagram

graph TD
  2777390937["markdown_it_pyrs.MarkdownItPyrsParser"]
  2536207506["base.MarkdownParser"]
  1836221132["_core.Backend"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  3481597255["typing.Generic"]
  2536207506 --> 2777390937
  1836221132 --> 2536207506
  925645236 --> 1836221132
  2751680898 --> 925645236
  3481597255 --> 1836221132
  2751680898 --> 3481597255

🛈 DocStrings

Bases: MarkdownParser

markdown-it-pyrs: Rust port of markdown-it. Deprecated, removed in mkconvert 3.0.

Use comrak / pyromark (Rust) or markdown-it-py instead. Not supported: alerts, math, hard_breaks.

Source code in src/mkconvert/parsers/markdown_it_pyrs.py
class MarkdownItPyrsParser(MarkdownParser):
    """markdown-it-pyrs: Rust port of markdown-it. Deprecated, removed in mkconvert 3.0.

    Use `comrak` / `pyromark` (Rust) or `markdown-it-py` instead.
    Not supported: `alerts`, `math`, `hard_breaks`.
    """

    name = "markdown-it-pyrs"
    requires = ("markdown_it_pyrs",)
    extra = "markdown_it_pyrs"
    supported_options: ClassVar[frozenset[str]] = frozenset({
        "tables",
        "strikethrough",
        "autolinks",
        "task_lists",
        "footnotes",
        "heading_ids",
        "definition_lists",
        "smart_punctuation",
        "raw_html",
        "front_matter",
    })

    def __init__(
        self,
        options: MarkdownOptions | None = None,
        *,
        on_unsupported: OnUnsupported = "warn",
        xhtml: bool = True,
        sourcepos: bool = False,
        plugins: list[_PLUGIN_NAME] | None = None,
    ) -> None:
        """Create a markdown-it-pyrs parser.

        Args:
            options: Common options.
            on_unsupported: See `Backend`.
            xhtml: Self-closing tags with a trailing slash (`<br />`).
            sourcepos: Add `data-sourcepos` attributes.
            plugins: Further plugins / rules to enable.
        """
        warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2)
        super().__init__(options, on_unsupported=on_unsupported)
        from markdown_it_pyrs import MarkdownIt

        o = self.options
        rules = list(_COMMONMARK_RULES)
        if o.raw_html:
            rules += ["html_block", "html_inline"]
        selected: dict[_PLUGIN_NAME, bool] = {
            "table": o.tables,
            "strikethrough": o.strikethrough,
            "autolink_ext": o.autolinks,
            "tasklist": o.task_lists,
            "footnote": o.footnotes,
            "heading_anchors": o.heading_ids,
            "deflist": o.definition_lists,
            "smartquotes": o.smart_punctuation,
            "replacements": o.smart_punctuation,
            "sourcepos": sourcepos,
        }
        rules += [rule for rule, enabled in selected.items() if enabled]
        rules += plugins or []
        self._md = MarkdownIt("zero").enable_many(rules)
        self._xhtml = xhtml

    def _render(self, text: str) -> str:
        return self._md.render(text, xhtml=self._xhtml)

__init__

__init__(
    options: MarkdownOptions | None = None,
    *,
    on_unsupported: OnUnsupported = "warn",
    xhtml: bool = True,
    sourcepos: bool = False,
    plugins: list[_PLUGIN_NAME] | None = None,
) -> None

Create a markdown-it-pyrs parser.

Parameters:

Name Type Description Default
options MarkdownOptions | None

Common options.

None
on_unsupported OnUnsupported

See Backend.

'warn'
xhtml bool

Self-closing tags with a trailing slash (<br />).

True
sourcepos bool

Add data-sourcepos attributes.

False
plugins list[_PLUGIN_NAME] | None

Further plugins / rules to enable.

None
Source code in src/mkconvert/parsers/markdown_it_pyrs.py
def __init__(
    self,
    options: MarkdownOptions | None = None,
    *,
    on_unsupported: OnUnsupported = "warn",
    xhtml: bool = True,
    sourcepos: bool = False,
    plugins: list[_PLUGIN_NAME] | None = None,
) -> None:
    """Create a markdown-it-pyrs parser.

    Args:
        options: Common options.
        on_unsupported: See `Backend`.
        xhtml: Self-closing tags with a trailing slash (`<br />`).
        sourcepos: Add `data-sourcepos` attributes.
        plugins: Further plugins / rules to enable.
    """
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2)
    super().__init__(options, on_unsupported=on_unsupported)
    from markdown_it_pyrs import MarkdownIt

    o = self.options
    rules = list(_COMMONMARK_RULES)
    if o.raw_html:
        rules += ["html_block", "html_inline"]
    selected: dict[_PLUGIN_NAME, bool] = {
        "table": o.tables,
        "strikethrough": o.strikethrough,
        "autolink_ext": o.autolinks,
        "tasklist": o.task_lists,
        "footnote": o.footnotes,
        "heading_anchors": o.heading_ids,
        "deflist": o.definition_lists,
        "smartquotes": o.smart_punctuation,
        "replacements": o.smart_punctuation,
        "sourcepos": sourcepos,
    }
    rules += [rule for rule, enabled in selected.items() if enabled]
    rules += plugins or []
    self._md = MarkdownIt("zero").enable_many(rules)
    self._xhtml = xhtml

:fa-brands-github: Show source on GitHub