siiky
2022/07/05
2022/07/05
en
Yesterday I made a Scheme library to read Gemtext into a simple AST: a list of lines of text, headers, links, list blocks, or code blocks.
some text
"some text"
Just a string, not tagged in any way. Empty lines are kept.
^(#+)\s+(.*)$
If *strict-gemtext-headers* is enabled, header lines of level > 3 are not considered headers.
title
"##### title" ; (w/ strict-gemtext-headers enabled)
'(header 5 "title") ; (w/ strict-gemtext-headers disabled)
## Links
'(link "some-uri.gmi" "Optional alt text")
If there's no alt text, the empty string is used:
=> some-uri.gmi
'(link "some-uri.gmi" "")
## Lists
'(list "item 1"
"item 2")
## Code blocks (pretend there's no space between the three backticks)
some pre-formatted text
'(code "some optional alt text"
"some"
"pre-formatted"
"text")
If there's no alt text, the empty string is used:
some pre-formatted text
'(code ""
"some"
"pre-formatted"
"text")
## Example
There are two steps to compute the factorial of a number:
=> gemini://gemi.dev/cgi-bin/wp.cgi/view/en?Factorial | Factorial
Here's the code in Haskell:
fact n = prod [1..n]
'((header 1 "Factorial")
""
"There are two steps to compute the factorial of a number:"
""
(list "Compute the list of integers from 1 up to the number"
"Multiply all the integers of the list")
""
(link "gemini://gemi.dev/cgi-bin/wp.cgi/view/en?Factorial" "")
(link "gemini://gemi.dev/cgi-bin/wp.cgi/view/en?Factorial" "Factorial")
""
(header 2 "Haskell code")
""
"Here's the code in Haskell:"
""
(code "hs"
"fact n = prod [1..n]"))
## Output Patterns
(header level title)
(link uri alt-text)
(code alt-text . lines)
(list . items)
text/gemini
This content has been proxied by September (3851b).