Skip to content

MarkdownOptions

Base classes

Name Children Inherits
Options
mkconvert._core
Base class for the common option models.

⋔ Inheritance diagram

graph TD
  125874654["base.MarkdownOptions"]
  849523002["_core.Options"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  849523002 --> 125874654
  3879467795 --> 849523002
  2751680898 --> 3879467795

🛈 DocStrings

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
class MarkdownOptions(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.
    """

    tables: bool = False
    """GFM pipe tables."""
    strikethrough: bool = False
    """`~~text~~` -> `<del>` (or `<s>`)."""
    autolinks: bool = False
    """Link bare URLs (`https://...`, `www.`) like GFM's autolink extension."""
    task_lists: bool = False
    """`- [x] item` -> list items with checkboxes."""
    footnotes: bool = False
    """`text[^1]` references and `[^1]: ...` definitions."""
    heading_ids: bool = False
    """Add slug `id` attributes to headings."""
    alerts: bool = False
    """GitHub alerts: `> [!NOTE]`, `> [!WARNING]`, ..."""
    math: bool = False
    """`$inline$` and `$$display$$` math, rendered as markup for MathJax / KaTeX."""
    definition_lists: bool = False
    """`Term` followed by `: definition` lines -> `<dl>`."""
    hard_breaks: bool = False
    """Render every newline inside a paragraph as `<br>`."""
    smart_punctuation: bool = False
    """Typographic quotes, dashes and ellipses."""
    raw_html: bool = True
    """Pass raw HTML through. `False` escapes or omits it (parser-dependent).

    This is not a sanitizer: use `mkconvert.sanitize` for untrusted input.
    """
    front_matter: bool = True
    """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.
    """

    @classmethod
    def gfm(cls, **changes: Any) -> Self:
        """GitHub Flavored Markdown: tables, strikethrough, autolinks and task lists.

        Args:
            changes: Further options to set, e.g. `footnotes=True`.
        """
        values: dict[str, Any] = dict(
            tables=True, strikethrough=True, autolinks=True, task_lists=True
        )
        return cls(**(values | changes))

alerts class-attribute instance-attribute

alerts: bool = False

GitHub alerts: > [!NOTE], > [!WARNING], ...

autolinks: bool = False

Link bare URLs (https://..., www.) like GFM's autolink extension.

definition_lists class-attribute instance-attribute

definition_lists: bool = False

Term followed by : definition lines -> <dl>.

footnotes class-attribute instance-attribute

footnotes: bool = False

text[^1] references and [^1]: ... definitions.

front_matter class-attribute instance-attribute

front_matter: bool = True

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

hard_breaks: bool = False

Render every newline inside a paragraph as <br>.

heading_ids class-attribute instance-attribute

heading_ids: bool = False

Add slug id attributes to headings.

math class-attribute instance-attribute

math: bool = False

$inline$ and $$display$$ math, rendered as markup for MathJax / KaTeX.

raw_html class-attribute instance-attribute

raw_html: bool = True

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

smart_punctuation: bool = False

Typographic quotes, dashes and ellipses.

strikethrough class-attribute instance-attribute

strikethrough: bool = False

~~text~~ -> <del> (or <s>).

tables class-attribute instance-attribute

tables: bool = False

GFM pipe tables.

task_lists class-attribute instance-attribute

task_lists: bool = False

- [x] item -> list items with checkboxes.

gfm classmethod

gfm(**changes: Any) -> Self

GitHub Flavored Markdown: tables, strikethrough, autolinks and task lists.

Parameters:

Name Type Description Default
changes Any

Further options to set, e.g. footnotes=True.

{}
Source code in src/mkconvert/parsers/base.py
@classmethod
def gfm(cls, **changes: Any) -> Self:
    """GitHub Flavored Markdown: tables, strikethrough, autolinks and task lists.

    Args:
        changes: Further options to set, e.g. `footnotes=True`.
    """
    values: dict[str, Any] = dict(
        tables=True, strikethrough=True, autolinks=True, task_lists=True
    )
    return cls(**(values | changes))

:fa-brands-github: Show source on GitHub