Skip to main content

GitHub License Discord Github Actions Black

rst2gemtext aims to convert reStructuredText markup to Gemtext, the markup format used by Gemini. It can be used both as a Python library or as a CLI tool.

This project is currently work in progress.

Requirements

  • Python >= 3.10

  • docutils

  • pygments

Installation

pip install rst2gemtext

Usage

Command Line Interface (CLI)

Example:

rst2gemtext input.rst output.gmi

Usage:

usage: rst2gemtext [-h] [--print-xml] input_rst output_gemtext

Converts reStructuredText to Gemtext (Gemini markup format)

positional arguments:
  input_rst       the reStructuredText file to convert
  output_gemtext  the output Gemtext file

options:
  -h, --help      show this help message and exit
  --print-xml     print the reStructuredText DOM as XML for debugging purpose

Inaccurate output? Report bugs to https://github.com/flozz/rst2gemtext/issues

Python Library

Example: Converting a reStructuredText string to a Gemtext string:

import rst2gemtext
output_gemtext = rst2gemtext.convert("my restructured text string")

Example: Converting a reStructuredText file to a Gemtext file:

import rst2gemtext

with open("input.rst", "r") as input_file:
    input_rst = input_file.read()

output_gemtext = rst2gemtext.convert(input_rst)

with open("output.gmi", "w") as output_file:
    output_file.write(output_gemtext)

Contributing

Questions

If you have any question, you can:

Bugs

Please open an issue on GitHub with as much information as possible if you found a bug:

  • Your operating system / Linux distribution (and its version)

  • How you installed the software

  • All the logs and message outputted by the software

  • etc.

If the issue is about the outputted Gemtext (wrong markup, unsupported reStructuredText feature,…), please provide:

  • An example reStructuedText document that generates the wrong output or that contains the unsupported syntax

  • The wrong Gemtext output (the one currently generated by rst2gemtext)

  • The expected Gemtext output

Pull requests

Please consider filing a bug before starting to work on a new feature; it will allow us to discuss the best way to do it. It is obviously unnecessary if you just want to fix a typo or small errors in the code.

Please note that your code must follow the coding style defined by the pep8 and pass tests. Black and Flake8 are used on this project to enforce the coding style.

Run the tests

You must install Nox first:

pip3 install nox

Then you can check for lint error:

nox --session lint

and run the tests:

nox --session test

You can use following commands to run the tests only on a certain Python version (the corresponding Python interpreter must be installed on your machine):

nox --session test-3.10
nox --session test-3.11
nox --session test-3.12
nox --session test-3.13
nox --session test-3.14

You can also fix coding style errors automatically with:

nox -s black_fix

Support this project

Want to support this project?

Changelog

  • [NEXT] (changes on master, but not released yet):

    • Nothing yet ;)

  • v0.7.0:

    • feat(table): Handled docutils csv-table directive and draw ASCII-art table from it (@Dryusdan, @flozz, #22)

    • feat(table): Handled docutils list-table directive and draw ASCII-art table from it (@Dryusdan, @flozz, #22)

  • v0.6.0:

    • feat(label): Handled label nodes (@flozz)

    • feat(footnote): Handled footnote and footnote_reference nodes (@flozz)

    • misc(deps): Added Python 3.14 support (@flozz)

    • misc(deps)!: Removed Python 3.9 support (@flozz)

  • v0.5.0:

    • feat(attribution_node): Added support for attribution nodes used by the epigraph directive (#8, @flozz)

    • fix: Fixed ImportError with docutils >= 0.22 (#7, @flozz)

    • Fix(image_node): Merge image link and its target link if both are identical (#6, @flozz)

    • misc(packaging): Modernized packaging: replaced setup.py and setuptools by pyproject.toml and flit (@flozz)

  • v0.4.0:

    • feat: Skip topic nodes as the ToC will not be generated (@flozz)

    • fix: Fixed bad link list deduplication when a non-breaking space is used in anchor text (@flozz)

    • fix: Fixed troncated tables when multiline content is present in the last row (@flozz)

    • misc(deps): Added Python 3.12, 3.13 support (@flozz)

    • misc(deps)!: Removed Python 3.7, 3.8 support (@flozz)

  • v0.3.1:

    • fix: Fixed truncated tables when last row contains bullet lists (@flozz, #1)

  • v0.3.0:

    • feat: Handle admonitons (admonition, attention, caution, danger, error, hint, important, note, tip and warning nodes) (@flozz)

  • v0.2.0:

    • feat: Pass the source file name to docutils to allow the include directive to work (@flozz)

    • feat: Added a basic support of the table (and associated) nodes (@flozz)

  • v0.1.0:

    • Initial release.

    • Supported rst nodes:

      • block_quote

      • bullet_list

      • caption

      • comment

      • emphasis

      • enumerated_list

      • figure

      • image

      • list_item

      • literal

      • literal_block

      • paragraph

      • raw

      • reference

      • section

      • strong

      • substitution_definition

      • substitution_reference

      • system_message

      • target

      • Text

      • title

      • transition

Download files

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

Source Distribution

rst2gemtext-0.7.0.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

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

rst2gemtext-0.7.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file rst2gemtext-0.7.0.tar.gz.

File metadata

  • Download URL: rst2gemtext-0.7.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rst2gemtext-0.7.0.tar.gz
Algorithm Hash digest
SHA256 387f8ec0b12143755ce3a16d30d8afa44d04b8963c0af6c54f69845d94193edb
MD5 07cefa1e27740539303e064bd1102ac9
BLAKE2b-256 0667a7e11244764899ff8f30ed106ca180b84658c5965739b1426f3483b5ac47

See more details on using hashes here.

File details

Details for the file rst2gemtext-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: rst2gemtext-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rst2gemtext-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b105f24de17fb4c4a3734849e7e38233dc561bb644cc932a807d2a2d0eaf0e1
MD5 cc5cbf7039fd04502f8a3400e1900eb2
BLAKE2b-256 4f1e022bf97cf9c92a1de9e8d048ddbbd2ed3923a9276dc3824eec7645ed53d9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

1 file

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