hugo-to-gemini/testdata/links.md
Timur Demin 5f755e4fa3
Encode link URIs before rendering into Gemtext
This makes gmnhg encode link destinations before rendering them into
Gemtext according to RFC 3986. This particularly fixes spaces in links.

Invalid URIs will skipped from rendering entirely.

Fixes #49.
2022-01-14 00:19:40 +05:00

3.3 KiB

Links

gmnhg supports links, images, and footnotes. These are extracted from paragraphs and other block elements recursively.

As there's no inline links in Gemtext, gmnhg instead renders links blocks after paragraphs. Links blocks are sorted by type: first footnotes, then images, then links, blocks of a distinct type separated by a single newline.

For inline Markdown links, the text inside the square brackets is used as link title: for instance, the link to Gemini specification along with a link to the current CommonMark spec will generate a block of two links.

gomarkdown works with reference-style links as well. Unused reference links are ignored.

xkcd #1853 serves quite well as an inline image example.

Other container elements can contain inline links as well. For instance, this is an example of a link inside a blockquote:

OTR has significant usability drawbacks for inter-client mobility. — XEP-0384

Links will get encoded according to RFC 3986, like this sample [link](/URI with spaces) to nowhere. The other sample link to somewhere on GitHub will not get transformed: sample.

Footnotes

gmnhg supports footnotes, written like this1. Footnotes can use any references, including alphanumeric ones2; alphanumeric references will be replaced with numeric IDs on render.

gmnhg additionally supports a special kind of lists: lists consisting solely of links. For these, content rendering will be skipped entirely, and a links block will be rendered instead.

Markdown lists

Links-only lists can be of any type, but they can only be of level 1. The two lists below will get rendered as links blocks:

  1. Best practices for Gemini implementers
  2. Project Gemini FAQ

The list below contains other meaningful text in its items, and will get rendered as a regular list:

A series of inline links in a single paragraph, if the paragraph contains no extra meaningful symbols (aside from spaces and newlines), will also get rendered as a single links block:

gmnhg Gemini specification

This also works for single-link paragraphs:

Gemini specification


  1. Footnotes can only consist of a single source line due to a quirk of gomarkdown. This line looks like it would belong to footnote 1, but it actually doesn't, and is therefore treated as a new paragraph. ↩︎

  2. Footnotes can contain any kind of inline formatting paragraphs do. For instance, this is a link to GitHub. ↩︎