Tumble Confused Device

.oOo.

Gemtext or Markdown

Recently I’ve stumbled upon the Gemini Protocol and Gemtext. I am really interested in its syntax simplicity. In some aspects is like a minimal Markdown, although not fully compatible. The good thing is that it can be learnt in one minute. Also, it has a line oriented philosophy that makes parsing Gemtext very easy. This leads to a very straightforward approach to writing and that is what I like the most.

=> Gemini Protocol

Quick Gemtext reference

Headings: Only # can be used.

# Heading 1

## Heading 2

### Heading 3

Lists: only flat, no nested lists, only uses *

* item!
* item!
* item!

Links: This one is the really nice but breaks Markdown (and Text is optional)

=> URL Text 

Quotes: As expected…Simple and practical

> quote

And that is it. The only major thing is that line breaks and empty lines are respected as opposed to Markdown, and that might be a good thing.

=> Gemtext Spec - oficial
=> Gemtext Spec

The syntax is so simple and so line oriented that a parser is really easy to build. You only have to match the beginning of the first characters and parse them into what ever format you need.

A simple example could be written in bash like this (incomplete, there’s no PRE element yet - coded fences)

gem2html(){

	local LINHA="$*"

	if [[ "$LINHA" =~ ^"# " ]]; then
		printf "<h1>%s</h1>\n" "${LINHA#\#\ }"
		elif [[ "$LINHA" =~ ^"## " ]]; then
			printf "<h2>%s</h2>\n" "${LINHA#\#\#\ }"
			elif [[ "$LINHA" =~ ^"### " ]]; then
				printf "<h3>%s</h3>\n" "${LINHA#\#\#\#\ }"
				elif [[ "$LINHA" =~ ^"=> " ]]; then
					read -r first url texto <<< "$LINHA"
					if [[ -z "$url" ]]; then 
						exit
					fi
					if [[ -z "$texto" ]]; then
						printf "<a href='%s'>%s</a>\n" "$url" "$url"
					else
						printf "<a href='%s'>%s</a>\n" "$url" "$texto"
					fi
				elif [[ "$LINHA" =~ ^"* " ]]; then
					printf "<li>%s</li>\n" "${LINHA#\*\ }"
				elif [[ "$LINHA" =~ ^"> " ]]; then
					printf "<blockquote>%s</blockquote>\n" "${LINHA#\>\ }"
				else
					printf "%s\n" "$LINHA"
	fi

}

.oOo.