md0: simple markdown subset for painless parsing and rendering

md0 is a format for hypertext documents. It is designed to be easy to parse and render, and is a proper subset of markdown. The main goal is to make it easier to share text-based content online, for authors, readers, and tool builders. The original motivation is to create a format that can be easily consumed by resource-constrained devices. The following image shows this file rendered by the ORBIT browser on the Playdate console:

md0 on Playdate

If you are familiar with gemtext, think of md0 as that but with support for inline links and also happens to be valid markdown (so you can convert it to different formats with existing tools).

md0 consists of two simple extensions to plain text: links and images, as follows:

All other text is treated as plain text. This document is a valid md0 file despite the use of bold, code syntax from full markdown - those will simply be rendered verbatim.

Text is rendered line-by-line, and each line is rendered word-by-word (words are delimited by spaces), so consequtive spaces will be treated as a single space (but consequtive lines will be preserved). A link ref should be rendered in a way to distinguish it from plain text. This includes rendering it as-is ([word][n] already indicates its is a link), as word with an underline, in a different font, with a different background color, etc.

A reference Python layout implementation is available in render.py. It lays out md0 text with word wrapping at a maximum of 50 characters per line and returns the laid out text along with a dictionary mapping link numbers to their positions. You can also check out the rendering code of ORBIT (in Lua) which shows how single-word link text makes it trivial to draw the link and caculate hit boxes. But the simplest way to render md0 is just to print it verbatim and only make the link defs clickable - using IDs instead of the link itself in refs makes the raw text readable as-is.