Copyright | (c) 2024 Sena |
---|---|
License | LGPL-3.0-or-later |
Maintainer | contact@sena.pink |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Text.Gemini
Description
Parse gemtext (text/gemini
) documents from and back into Text
.
See the Gemini hypertext format specification at https://geminiprotocol.net/docs/gemtext-specification.gmi.
Synopsis
- type GemDocument = [GemItem]
- data GemItem
- decode :: Text -> GemDocument
- decodeLine :: Text -> GemItem
- encode :: GemDocument -> Text
- encodeItem :: GemItem -> Text
- documentTitle :: GemDocument -> Maybe Text
Gemtext types
type GemDocument = [GemItem] Source #
A gemtext document, in the form of a list of GemItem
s
A gemtext item
Constructors
GemText !Text | A regular gemtext line -- |
GemLink !Text !(Maybe Text) | A gemtext link -- |
GemHeading !Int !Text | A gemtext heading of 3 levels max -- |
GemList ![Text] | An unordered gemtext list -- Gemtext specification does not endorse grouping list items this way. This approach is purely for practical reasons, such as ease of conversion to unordered HTML lists. |
GemQuote !Text | A gemtext quote -- |
GemPre ![Text] !(Maybe Text) | A preformatted gemtext block -- |
Decoding from text
decode :: Text -> GemDocument Source #
Parse a gemtext block as a GemDocument
.
The input Text
must use either CRLF or LF.
decodeLine :: Text -> GemItem Source #
Encoding into text
encode :: GemDocument -> Text Source #
Encode a parsed GemDocument
into a gemtext block.
The output Text
uses CRLF line breaks and ends with a newline.
Empty lists are ignored completely if present. See the encodeItem
function
for additional quirks.
encodeItem :: GemItem -> Text Source #
Encode a single parsed GemItem
into gemtext.
The output Text
does not end with an additional newline, and might be
multiple lines, in which case it uses CRLF line breaks.
Prefixes are escaped as necessary before encoding and the spaces in GemLink
s
are replaced with %20
to normalize them. Line breaks inside the body of an
item are also replaced with a space.
Utility functions
documentTitle :: GemDocument -> Maybe Text Source #
Get the title of the GemDocument
, which is the very first GemHeading
in the document, regardless of the level of the heading.