Skip to content

API

A simple Markdown to Gemtext converter.

HTMLBlockHandling

HTMLBlockHandling = Literal[
    "convert", "preformat", "striptags"
]

Options for handling the conversion of HTML blocks.

HTMLInlineHandling

HTMLInlineHandling = Literal['keep', 'striptags']

Options for handling the conversion of inline HTML tags.

Options

Bases: NamedTuple

Configuration options for the converter.

extra_linkable_protocols class-attribute instance-attribute

extra_linkable_protocols: Sequence[str] = ()

Additional protocol names to linkify (e.g. ['spartan', 'finger', 'nex']).

hide_front_matter class-attribute instance-attribute

hide_front_matter: bool = False

Whether to hide front matter. If False (default), emits it as preformatted text.

html_block_handling class-attribute instance-attribute

html_block_handling: HTMLBlockHandling = 'convert'

How to handle HTML blocks: 'convert', 'preformat', or 'striptags'.

html_inline_handling class-attribute instance-attribute

html_inline_handling: HTMLInlineHandling = 'striptags'

How to handle inline HTML tags: 'keep' or 'striptags'.

preformat_tables class-attribute instance-attribute

preformat_tables: bool = True

Whether to format tables as preformatted blocks with alt-text 'table'.

retain_inline_markup class-attribute instance-attribute

retain_inline_markup: bool = True

Whether to retain inline Markdown markup (e.g. italic, bold, code).

space_after_blockquotes class-attribute instance-attribute

space_after_blockquotes: bool = True

Whether to add an empty line after blockquotes.

space_after_lists class-attribute instance-attribute

space_after_lists: bool = True

Whether to add an empty line after a run of list items is broken.

space_after_paragraphs class-attribute instance-attribute

space_after_paragraphs: bool = True

Whether to add an empty line after paragraphs.

markdown_to_gemtext

markdown_to_gemtext(
    markdown_content: str, options: Options | None = None
) -> str

Convert Markdown content to Gemtext.

Parameters:

Name Type Description Default

markdown_content

str

The Markdown content to convert.

required

options

Options | None

Optional conversion options.

None

Returns:

Type Description
str

The converted Gemtext content.