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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md2gemtext-0.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md2gemtext-0.0.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file md2gemtext-0.0.1.tar.gz.

File metadata

  • Download URL: md2gemtext-0.0.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for md2gemtext-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8e33a8824843abefc6a929c4d8f449a0bb12b52e7c0faceebe4f1fc373579443
MD5 acb452f901fd5fdef47a743c4da32c75
BLAKE2b-256 c1667d6ce64afbab2c656ed01bffc55e59835ecd9b29434000708e537d1b092d

See more details on using hashes here.

File details

Details for the file md2gemtext-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: md2gemtext-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for md2gemtext-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a35efdf143123498ef823f0ca85e24d9e3a78fc78378473607a00de2f425a0b1
MD5 abb3574cd1d30dae0c5c61112f53b72f
BLAKE2b-256 56e907317dee880e088476e3beaec877705724818fa0d2a2c41d4f4a982166d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page