Added thanks and gratitude
Fix error in example
Adjusted readme
A simple Gemtext to HTML parser for Python which aims to be straightforward and importable for your Python-based Gemini projects.
This was built to serve my own specific use-case, since none of the results on PyPI.org appeared to match my needs to provide Gemtext -> HTML conversion as an importable library. huntingb/gemtext-html-converter also exists and is probably much better written, but I wanted to experiment for myself as well try to produce something that was a self-contained Python module.
The output for this is fairly non-fancy: you might want to prettify or clean the HTML if you want to write it to a file or include it in another document.
Feature list:
=>
) are parsed with optional link text. Any links without link text have the target repeated inside the anchor tags e.g. => gemini://example.org
becomes <a href="gemini://example.org>gemini://example.org"</a>
*
) are parsed as unordered lists, with opening and closing <ul>
tags.>
) are rendered using <blockquote>
tags#
, ##
, and ###
) become the appropriate <h1>
, <h2>
, or <h3>
header tag.```
) renders using <pre>
tags, and preserves newlines within the block.<p>
tags.Non-features (that will not be implemented):
standalone
parameter, but it added more state and it's difficult to tell from Section 5.5.1 of the Gemini specification whether # Heading One
should be analagous to <title>Heading One</title>
as well as <h1>Heading One</h1>
.This is a pet project designed to act as a library to support my other gemini pet project. It won't be under proactive development once I've confirmed it's behaving as intended.
This said, I'd like it if it were useful to others. I will try my best to respond to Merge requests and Issues, but I am not a professional Python developer.
I will be using semantic versioning to version the project. I do not envision the project to go far beyond version 1.0 because Gemtext is stable. I will mostly be bugfixing and don't intend to add many features or functionality. Therefore there may be many 1.0.x versions.
Until I'm confident that it's behaving as expected, the project is at Version 0.1.0.
The goal is to enable you to install this library via pip
, and possibly to build some package files for package managers for GNU/Linux users to manage the library through their distro package manager. Watch this space.
Simply import into your project, instantiate, and then call parse()
on your gemtext input.
from gmi2html import Gmi2HTML
parser = Gmi2HTML()
# Parse a string
gemtext = "# Example Gemtext\nHello Gemini! Insert Space Metaphor here!"
result = parser.parse(gemtext) # "<h1>Example Gemtext</h1><p>Hello Gemini! Insert Space Metaphor here!</p>"
# Parse a whole document
with open('./tests/test-gemtext-file.gmi', 'r') as gmi_file:
gemtext = gmi_file.read()
parser.parse(gemtext)
# Combine with other projects to build more complex things
# https://pypi.org/project/ignition-gemini/
import ignition
response = ignition.request("gemini://gemini.circumlunar.space/")
html = parser.parse(response.data())
Please feel free to open issues! I'm not a particularly advanced Python programmer so I am also very open to Merge requests if you provide a summary of the changes and ensure your code is commented thoroughly.
Ideally the following will be implemented in the future:
With support / learning:
I am very open to contributions.
My requirements are:
Your code should pass the unit tests. Please run them via:
python3 -m unittest -v tests/parser_tests.py
If you can write some better unit tests, that'd be very cool and I'd love to learn from you.
I generated some boilerplate in CONTRIBUTING.md which should cover most other contributory-style things.
Licensed using the GPL 3, which means your software should be too if you're using this as a library.