Skip to main content

A simple library for parsing the Gemtext markup language

Project description

gemtext - A simple library for parsing the Gemtext markup language

Introduction

gemtext is a small and simple library that provides code for parsing the hypertext markup language of the Gemini project.

Installation

gemtext is available from pypi and can be installed with your package installer of choice.

With pip:

pip install gemtext

With uv:

uv add gemtext

Quick start

The library provides a single main parsing class called Gemtext. It is initialised with a text of gemtext and the content property provides a list of lines, typed with their parsed type, each having its own relevant properties.

A very minimal parser might look like this:

import fileinput
from gemtext import Gemtext

def parse_input() -> None:
    for gem_line in Gemtext("".join(fileinput.input())).content:
        print(f"{gem_line!r}")

The library contains a simple test command line tool, which can be accessed either via the Python -m switch, or depending on your environment, via the gemtext command. For example, given this content of a file called example.gmi:

# This is a heading

## This is a sub-heading

### This is a sub-sub-heading

=> gemini://davep.gemcities.com/ Dave's test capsule

> This is a deep and meaningful quote

```
Here is some pre-formatted text.

Here's some more of that text.
```

* One
* Two
* Three

The gemtext command (or python -m gemtext) would produce:

$ gemtext example.gmi
Heading(content='This is a heading', level=1)
Paragraph(content='')
Heading(content='This is a sub-heading', level=2)
Paragraph(content='')
Heading(content='This is a sub-sub-heading', level=3)
Paragraph(content='')
Link(content="Dave's test capsule", uri='gemini://davep.gemcities.com/')
Paragraph(content='')
Quote(content='This is a deep and meaningful quote')
Paragraph(content='')
PreFormatted(content="Here is some pre-formatted text.\n\nHere's some more of that text.")
Paragraph(content='')
ListItem(content='One')
ListItem(content='Two')
ListItem(content='Three')

See the main documentation for the full API.

Project details


Download files

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

Source Distribution

gemtext-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

gemtext-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file gemtext-1.0.0.tar.gz.

File metadata

  • Download URL: gemtext-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 gemtext-1.0.0.tar.gz
Algorithm Hash digest
SHA256 68654c4a28f5c775454f31e2b90ccdc2f0bfaf4732cb269506767f5af2506ed5
MD5 89d5a0f3f000e38690e6fcc5f66c7cdc
BLAKE2b-256 451fc2b1af66a18cfbcd9f9d586610f7466bb8da57808a03d0ff8772b7129131

See more details on using hashes here.

File details

Details for the file gemtext-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: gemtext-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 gemtext-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 066dc133cd9d68a93eee844cfb9bbbd9d856acdeecff748677c08986b7957ded
MD5 7b6cd3854fa5a6ed4c3f375df0f25d63
BLAKE2b-256 9213bf22c338cd84389b8be37df566c61b2a436beac63713441e18335a1a20f3

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 Pingdom Monitoring Sentry Error logging StatusPage Status page