Skip to content

markdown_it_pyrs

Class info

Classes

Name Children Inherits
MarkdownItPyrsParser
mkconvert.parsers.markdown_it_pyrs
markdown-it-pyrs: Rust port of markdown-it. Deprecated, removed in mkconvert 3.0.

    🛈 DocStrings

    Parser using markdown-it-pyrs (Rust).

    MarkdownItPyrsParser

    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