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

Text.Gemini

Description

A tiny Gemtext (text/gemini) parser.

Parses Gemtext documents from and back to Text. See the Section 5 of the Gemini Protocol specification.

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]

A Gemtext unordered list. -- GemList <Lines>

GemQuote !Text

A Gemtext quote. -- GemQuote <Text>

GemPre ![Text] !(Maybe Text)

A Gemtext preformat. -- 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 file as GemDocument. The text should be supplied as an LF-ending Text.

decodeLine :: Text -> GemItem Source #

Parse a single Gemtext line as GemItem.

The preformatted texts are regarded as GemTexts as they are strictly multiline.

Encoding as Text

encode :: GemDocument -> Text Source #

Encode parsed GemDocument as a Gemtext file. The output Text uses LF-endings. Uses the encodeItem function below.

Valid prefixes are escaped before encoding.

Empty lists are ignored if given.

encodeItem :: GemItem -> Text Source #

Encode a single parsed GemItem as Gemtext text. The output Text uses LF-endings and might be multiple lines.

Valid prefixes are escaped before encoding.

Beware that the output text doesn't end with a newline.

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