parsers
Class info¶
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| CmarkgfmParser | mkconvert.parsers.cmarkgfm | cmarkgfm: bindings to cmark-gfm, the reference GFM implementation. |
| ComrakParser | mkconvert.parsers.comrak | Comrak: fast, CommonMark / GFM compliant, supports every common option. |
| Markdown2Parser | mkconvert.parsers.markdown2 | markdown2: pure-Python Markdown (not CommonMark compliant), many "extras". |
| MarkdownItPyParser | mkconvert.parsers.markdown_it_py | markdown-it-py + mdit-py-plugins: pure Python, CommonMark compliant, pluggable. |
| MarkdownItPyrsParser | mkconvert.parsers.markdown_it_pyrs | markdown-it-pyrs: Rust port of markdown-it. Deprecated, removed in mkconvert 3.0. |
| MarkdownOptions | mkconvert.parsers.base | Common Markdown -> HTML options, mapped onto every parser. |
| MarkdownParser | mkconvert.parsers.base | Base class for Markdown -> HTML parsers. |
| MarkoParser | mkconvert.parsers.marko | Marko: pure-Python CommonMark parser, extensible. |
| MistuneParser | mkconvert.parsers.mistune | Mistune: fast pure-Python parser (not fully CommonMark compliant). |
| PyromarkParser | mkconvert.parsers.pyromark | Pyromark: bindings to pulldown-cmark, very fast. |
| PythonMarkdownParser | mkconvert.parsers.python_markdown | Python-Markdown with pymdown-extensions (not CommonMark compliant). |
| Registry | mkconvert._core | Name -> backend class mapping, in order of preference. |
🛈 DocStrings¶
Markdown -> HTML parsers.
Importing this package does not import any parser library: each parser imports its library when instantiated.
registry
module-attribute
¶
registry: Registry[MarkdownParser] = Registry('Markdown parser')
Parsers by name. Order is the preference when no parser is named.
CmarkgfmParser
¶
Bases: MarkdownParser
cmarkgfm: bindings to cmark-gfm, the reference GFM implementation.
Not supported: heading_ids, alerts, math, definition_lists.
With raw_html=False, raw HTML is replaced by <!-- raw HTML omitted -->.
Source code in src/mkconvert/parsers/cmarkgfm.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
tagfilter: bool = False,
github_pre_lang: bool = False,
sourcepos: bool = False,
) -> None
Create a cmarkgfm parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
tagfilter
|
bool
|
GFM tag filter: escape |
False
|
github_pre_lang
|
bool
|
GitHub-style |
False
|
sourcepos
|
bool
|
Add |
False
|
Source code in src/mkconvert/parsers/cmarkgfm.py
ComrakParser
¶
Bases: MarkdownParser
Comrak: fast, CommonMark / GFM compliant, supports every common option.
Source code in src/mkconvert/parsers/comrak.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
header_id_prefix: str = "",
tagfilter: bool = False,
superscript: bool = False,
subscript: bool = False,
underline: bool = False,
spoiler: bool = False,
greentext: bool = False,
wikilinks: bool = False,
multiline_block_quotes: bool = False,
math_code: bool = False,
relaxed_autolinks: bool = False,
relaxed_tasklist_matching: bool = False,
default_info_string: str | None = None,
github_pre_lang: bool = False,
full_info_string: bool = False,
sourcepos: bool = False,
) -> None
Create a comrak parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
header_id_prefix
|
str
|
Prefix for heading ids (with |
''
|
tagfilter
|
bool
|
GFM tag filter: escape |
False
|
superscript
|
bool
|
|
False
|
subscript
|
bool
|
|
False
|
underline
|
bool
|
|
False
|
spoiler
|
bool
|
|
False
|
greentext
|
bool
|
|
False
|
wikilinks
|
bool
|
|
False
|
multiline_block_quotes
|
bool
|
|
False
|
math_code
|
bool
|
|
False
|
relaxed_autolinks
|
bool
|
Looser autolink detection (with |
False
|
relaxed_tasklist_matching
|
bool
|
Any character as task list checkmark. |
False
|
default_info_string
|
str | None
|
Language for fenced code blocks without one. |
None
|
github_pre_lang
|
bool
|
GitHub-style |
False
|
full_info_string
|
bool
|
Keep the full info string as |
False
|
sourcepos
|
bool
|
Add |
False
|
Source code in src/mkconvert/parsers/comrak.py
Markdown2Parser
¶
Bases: MarkdownParser
markdown2: pure-Python Markdown (not CommonMark compliant), many "extras".
Not supported: autolinks, math, definition_lists.
Source code in src/mkconvert/parsers/markdown2.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
extras: Mapping[str, Any] | None = None,
highlight: bool = False,
html4tags: bool = False,
) -> None
Create a markdown2 parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
extras
|
Mapping[str, Any] | None
|
Further markdown2 extras with their settings ( |
None
|
highlight
|
bool
|
Highlight fenced code blocks with Pygments (if installed). |
False
|
html4tags
|
bool
|
HTML4-style tags ( |
False
|
Source code in src/mkconvert/parsers/markdown2.py
MarkdownItPyParser
¶
Bases: MarkdownParser
markdown-it-py + mdit-py-plugins: pure Python, CommonMark compliant, pluggable.
Supports every common option. Further syntax (MkDocs-style !!! admonitions, MyST
directives, attributes, ...) comes from mdit-py-plugins via plugins.
Source code in src/mkconvert/parsers/markdown_it_py.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
plugins: Sequence[Callable[..., None] | tuple[Callable[..., None], dict[str, Any]]] = (),
xhtml: bool = True,
heading_levels: tuple[int, int] = (1, 6),
) -> None
Create a markdown-it-py parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
plugins
|
Sequence[Callable[..., None] | tuple[Callable[..., None], dict[str, Any]]]
|
Further plugins, each a plugin function or a |
()
|
xhtml
|
bool
|
Self-closing tags with a trailing slash ( |
True
|
heading_levels
|
tuple[int, int]
|
Lowest and highest heading level that get ids
(with |
(1, 6)
|
Source code in src/mkconvert/parsers/markdown_it_py.py
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
__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 |
'warn'
|
xhtml
|
bool
|
Self-closing tags with a trailing slash ( |
True
|
sourcepos
|
bool
|
Add |
False
|
plugins
|
list[_PLUGIN_NAME] | None
|
Further plugins / rules to enable. |
None
|
Source code in src/mkconvert/parsers/markdown_it_pyrs.py
MarkdownOptions
¶
Bases: Options
Common Markdown -> HTML options, mapped onto every parser.
The defaults are plain CommonMark (every extension off, raw HTML passed through),
except that a leading front matter block is dropped.
Check MarkdownParser.supported_options for what a parser can enable.
Source code in src/mkconvert/parsers/base.py
alerts
class-attribute
instance-attribute
¶
GitHub alerts: > [!NOTE], > [!WARNING], ...
autolinks
class-attribute
instance-attribute
¶
Link bare URLs (https://..., www.) like GFM's autolink extension.
definition_lists
class-attribute
instance-attribute
¶
Term followed by : definition lines -> <dl>.
footnotes
class-attribute
instance-attribute
¶
text[^1] references and [^1]: ... definitions.
front_matter
class-attribute
instance-attribute
¶
Drop a leading ----delimited front matter block instead of rendering it.
On by default: almost every Markdown file with a leading --- block means front
matter, not a horizontal rule followed by a heading.
hard_breaks
class-attribute
instance-attribute
¶
Render every newline inside a paragraph as <br>.
heading_ids
class-attribute
instance-attribute
¶
Add slug id attributes to headings.
math
class-attribute
instance-attribute
¶
$inline$ and $$display$$ math, rendered as markup for MathJax / KaTeX.
raw_html
class-attribute
instance-attribute
¶
Pass raw HTML through. False escapes or omits it (parser-dependent).
This is not a sanitizer: use mkconvert.sanitize for untrusted input.
smart_punctuation
class-attribute
instance-attribute
¶
Typographic quotes, dashes and ellipses.
strikethrough
class-attribute
instance-attribute
¶
~~text~~ -> <del> (or <s>).
task_lists
class-attribute
instance-attribute
¶
- [x] item -> list items with checkboxes.
gfm
classmethod
¶
GitHub Flavored Markdown: tables, strikethrough, autolinks and task lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
changes
|
Any
|
Further options to set, e.g. |
{}
|
Source code in src/mkconvert/parsers/base.py
MarkdownParser
¶
Bases: Backend[MarkdownOptions]
Base class for Markdown -> HTML parsers.
Subclasses take MarkdownOptions plus their own keyword-only options, map them onto
the wrapped library once in __init__ and implement _render.
Source code in src/mkconvert/parsers/base.py
MarkoParser
¶
Bases: MarkdownParser
Marko: pure-Python CommonMark parser, extensible.
Not supported: math, definition_lists, smart_punctuation.
Source code in src/mkconvert/parsers/marko.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
extensions: Sequence[str | MarkoExtension] = (),
) -> None
Create a Marko parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
extensions
|
Sequence[str | MarkoExtension]
|
Further Marko extensions, e.g. |
()
|
Source code in src/mkconvert/parsers/marko.py
MistuneParser
¶
Bases: MarkdownParser
Mistune: fast pure-Python parser (not fully CommonMark compliant).
Not supported: alerts, smart_punctuation. autolinks links bare https://
URLs only, not www. ones.
Source code in src/mkconvert/parsers/mistune.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
plugins: Sequence[str | Callable[..., None]] = (),
) -> None
Create a mistune parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
plugins
|
Sequence[str | Callable[..., None]]
|
Further mistune plugins: names (e.g. |
()
|
Source code in src/mkconvert/parsers/mistune.py
PyromarkParser
¶
Bases: MarkdownParser
Pyromark: bindings to pulldown-cmark, very fast.
Not supported: autolinks, heading_ids (only explicit # Title {#id} via
heading_attributes), hard_breaks and raw_html=False.
Source code in src/mkconvert/parsers/pyromark.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
heading_attributes: bool = False,
superscript: bool = False,
subscript: bool = False,
wikilinks: bool = False,
old_footnotes: bool = False,
highlight: Theme | None = None,
) -> None
Create a pyromark parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
heading_attributes
|
bool
|
|
False
|
superscript
|
bool
|
|
False
|
subscript
|
bool
|
|
False
|
wikilinks
|
bool
|
|
False
|
old_footnotes
|
bool
|
Footnotes with the older, looser pulldown-cmark syntax. |
False
|
highlight
|
Theme | None
|
Syntax-highlight code blocks with this theme. |
None
|
Source code in src/mkconvert/parsers/pyromark.py
PythonMarkdownParser
¶
Bases: MarkdownParser
Python-Markdown with pymdown-extensions (not CommonMark compliant).
Fenced code blocks are always on. Strikethrough, task lists, autolinks and math
come from pymdown-extensions. Not supported: alerts.
Source code in src/mkconvert/parsers/python_markdown.py
__init__
¶
__init__(
options: MarkdownOptions | None = None,
*,
on_unsupported: OnUnsupported = "warn",
extensions: Sequence[str | Extension] = (),
extension_configs: Mapping[str, Mapping[str, Any]] | None = None,
output_format: Literal["html", "xhtml"] = "html",
) -> None
Create a Python-Markdown parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
MarkdownOptions | None
|
Common options. |
None
|
on_unsupported
|
OnUnsupported
|
See |
'warn'
|
extensions
|
Sequence[str | Extension]
|
Further extensions, e.g. |
()
|
extension_configs
|
Mapping[str, Mapping[str, Any]] | None
|
Settings per extension name; merged over the ones mkconvert uses for the common options. |
None
|
output_format
|
Literal['html', 'xhtml']
|
|
'html'
|