tags as an easy way to keep them on separate lines without needing CSS.
=> https://geminiprotocol.net/docs/cheatsheet.gmi Gemtext cheatsheet
=> https://example.com/
If you write a link on the line directly after a blockquote (as a source/citation), both elements will be merged into a captioned
:
> You will not be saved by General Motors or the pre-fabricated house.
> You will not be saved by dialectic materialism or the Lambeth Conference.
> You will not be saved by Vitamin D or the expanding universe.
> In fact, you will not be saved.
=> https://allpoetry.com/Nightmare,-With-Angels from “Nightmare, With Angels”, by Stephen Vincent Benét
### Preformatted text
The problem with pre-formatted blocks in gemtext is that people use the same pattern for so many different things: pure decoration, images that need alt-text, captioned visual information, code samples that need to be read as plaintext...
The parser converts all of these to the same basic structure in HTML: a element wrapped in a element. However, you can specify the type of pre-formatted text using the description written after the opening backtick fence (```), which modifies the HTML. Types consist of a prefix word, then a colon, then a space. Here are the types:
* If it starts with “text”, “code”, or “sample”, then the block is raw text, like a code example or a poem. The description is added to a element above the text. If the prefix is “code” or “sample” then the content of the element will be wrapped in or tags.
* If it starts with “caption”, then the block is visual information, like a chart, diagram, or image. The block is marked with aria-hidden and the description is copied to a element above the text.
* If it starts any other way (including no description), then the block is pure decoration. The entire is marked with aria-hidden.
Here's an example of ASCII art with an explanatory caption:
```caption: The Legend of Zelda: Link's Awakening title ASCII art, from a spoiler-free walkthrough on GameFAQs
||
_||_
| | THE LEGEND OF
______| |_______ ______________ ______ ____
/ ____| |__ / \ __ \ / \ "\ \_ \
/ / | | / / | | \ | | | |"\ | \ \
/__/ _| |/ / / | | \_| | | | | | | \
/ __ / / / | |_/| | | | | | | | \
/_/| / / / | | | | | | | | | /_\ \
|/ / | |_ | | | | | | | ; __ \
/ / / | | \/ _| | || | | | / / \ \
/ / / | |___/ / |/|| |_/ |/ / \ \
/ /| __|______/|____|/______//___\ /___\
/ / / | / /
/ / / | / / LINK'S AWAKENING
/ / /| |____/ /
/_____| |______/ - - - - - - - - - -
| |
| | SPOILERFREE WALKTHROUGH
\ /
\/
```
=> https://gamefaqs.gamespot.com/gameboy/563277-the-legend-of-zelda-links-awakening/faqs/34994 image source (artist: Kaas)
And here's an example of a raw text code sample, with the language in the caption:
```code: CSS
pre {
overflow-x: auto;
}
```
Finally, here's a purely decorative pre-formatted block that should be ignored by accessibility apps:
```
~~~~~ * ~~~~~
```
It's a little complex and clunky, but this is my best attempt to make an easy-to-use and accessible distinction between all these use-cases.
## The controls
### Browse
The “Browse…” button lets you open a .gmi, .gemini, or .txt file in the input area.
### Parse
The “Parse” button parses the gemtext into HTML, then displays the raw code in the bottom, read-only, textarea, and renders it after that.
### Reset
The “Reset” button resets the parser, so it shows this default gemtext and its raw and rendered HTML.
## Under the hood
First, the parser splits the input into chunks using the backtick fences (``` at the start of a line). The odd-numbered chunks are regular text and the even-numbered chunks are pre-formatted text. Pre-formatted text gets processed according to its description, and regular text gets processed for every other bit of syntax.
The parser makes heavy use of regular expressions (regex). I tried making a line-by-line parser, and while it was a few times faster in relative terms, it only saved milliseconds in absolute terms and the code was longer and less readable.
## Parsing HTML to gemtext?
This sounds nice in theory, but there are way too many problems in practice:
* nesting: HTML allows it, gemtext doesn't
* the unaccounted elements: how do you parse , , –, etc.?
* flexibility: there are many ways to accomplish things in HTML that can be done only one way in gemtext, which means the parser needs to standardise (according to whose standards?)
Markdown avoids some or all of these due to its complexity and the fact that it's a superset of HTML (that is, you can use HTML in markdown since it's meant to be parsed to HTML anyway). Gemtext doesn't have that freedom, so some of these problems are impossible to overcome.