Skip to main content

md2gemtext - A simple library for converting Markdown to Gemtext

Introduction

md2gemtext is a small and simple library that provides code for converting Markdown into the hypertext markup language of the Gemini project.

Installation

md2gemtext is available from PyPI and can be installed with your package installer of choice.

With pip:

pip install md2gemtext

With uv:

uv add md2gemtext

Quick start

The library provides a main conversion function called markdown_to_gemtext. It is passed a string of Markdown you wish to convert, and returns the converted Gemtext string:

from md2gemtext import markdown_to_gemtext, Options

markdown = """
# Welcome

This is a paragraph with [a link](https://example.com) inside.
"""

gemtext = markdown_to_gemtext(markdown)
print(gemtext)

Output:

# Welcome

This is a paragraph with a link{a} inside.

=> https://example.com {a} a link

Options

Conversion behavior can be configured using the Options class:

from md2gemtext import Options, markdown_to_gemtext

options = Options(
    retain_inline_markup=False,   # Strip bold, italic, code markup
    space_after_paragraphs=True,  # Add empty line after paragraphs
    space_after_blockquotes=True, # Add empty line after blockquotes
    space_after_lists=True,       # Add empty line after runs of list items
    hide_front_matter=True,       # Hide/filter out front matter (default is False, which emits it)
    extra_linkable_protocols=["spartan", "finger", "nex"], # Additional protocols to linkify
    preformat_tables=True,        # Emit tables as preformatted blocks with alt-text 'table'
    html_block_handling="convert", # HTML blocks: 'convert', 'preformat', or 'striptags'
    html_inline_handling="striptags", # Inline HTML tags: 'striptags' (default) or 'keep'
)

gemtext = markdown_to_gemtext(markdown, options=options)

Command Line Interface

md2gemtext includes a command-line tool which reads from files or stdin:

# Read from file
md2gemtext document.md

# Read from stdin
cat document.md | md2gemtext

# Strip inline markup
md2gemtext --strip-inline-markup document.md

# Add extra protocols to linkify
md2gemtext --extra-protocol spartan --extra-protocol nex document.md

# Emit tables as plain aligned text instead of preformatted blocks
md2gemtext --no-preformat-tables document.md

# Set HTML block handling mode ('convert', 'preformat', or 'striptags')
md2gemtext --html-block-handling preformat document.md

# Keep inline HTML tags rather than stripping them
md2gemtext --html-inline-handling keep document.md

Release files for md2gemtext 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md2gemtext 1.0.0
File Size Uploaded
md2gemtext-1.0.0.tar.gz 10.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md2gemtext 1.0.0
File Interpreter ABI Platform
md2gemtext-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / md2gemtext-1.0.0.tar.gz

Download URL md2gemtext-1.0.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a7ec50d305acd3c629638e44a874b7db69b5264753a193a892f78a7a78c8cc93
BLAKE2b-256 checksum
How to use checksums
a7bd439b7407e528fe8ebc8e0703e321c1ff9efba446db436ebe8ab1329efc6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / md2gemtext-1.0.0-py3-none-any.whl

Download URL md2gemtext-1.0.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70cebb7d38b5a6d839d15c9d475eb347cd7fcd86b7732a801ffacc839ae747b9
BLAKE2b-256 checksum
How to use checksums
3347197ce60df816112e22a2c0c3e5c388b2b571511bc5d237afed7988850e67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page