gemmula-1.1.1: A tiny gemtext parser
Copyright(c) Sena 2024
LicenseAGPL-3.0-or-later
MaintainerSena <jn-sena@proton.me>
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.Gemini

Description

A tiny gemtext (unofficially text/gemini) parser

Parses gemtext documents from and back to Text.

See the Gemini hypertext format specification at https://geminiprotocol.net/docs/gemtext-specification.gmi.

Synopsis

Gemtext types

type GemDocument = [GemItem] Source #

A gemtext document, in the form of an ordered list of GemItems

data GemItem Source #

A gemtext item

Constructors

GemText !Text

A regular gemtext line -- GemText <Text>

GemLink !Text !(Maybe Text)

A gemtext link -- GemLink <Link> [Optional Description]

GemHeading !Int !Text

A gemtext heading of 3 levels max -- GemHeading <Level> <Text>

GemList ![Text]

An unordered gemtext list -- GemList <Lines>

GemQuote !Text

A gemtext quote -- GemQuote <Text>

GemPre ![Text] !(Maybe Text)

A preformatted gemtext block -- GemPre <Lines> [Optional Alt Text]

Instances

Instances details
Show GemItem Source # 
Instance details

Defined in Text.Gemini

Eq GemItem Source # 
Instance details

Defined in Text.Gemini

Methods

(==) :: GemItem -> GemItem -> Bool #

(/=) :: GemItem -> GemItem -> Bool #

Decoding from text

decode :: Text -> GemDocument Source #

Parse a gemtext block as GemDocument.

The text should be supplied as a Text which uses LF line breaks.

decodeLine :: Text -> GemItem Source #

Parse a single gemtext line as GemItem.

Preformatted text blocks are regarded as GemTexts as they are strictly multiline.

Encoding into text

encode :: GemDocument -> Text Source #

Encode a parsed GemDocument into a gemtext block.

The output Text uses LF line breaks.

Valid prefixes are escaped before encoding. See the encodeItem function below.

Empty lists are ignored if given.

encodeItem :: GemItem -> Text Source #

Encode a single parsed GemItem into gemtext.

Beware that the output text does not end with a newline.

The output Text might be multiple lines, in which case it uses LF line breaks.

Valid prefixes are escaped before encoding.

The spaces in GemLinks are replaced with %20 to normalize them.