Alfarebis

Musings on informatics, language, music...

How to use target attribute in Markdown

Markdown is a lightweight markup language which makes web page editing more flexible than html editing. However, this comes with a price: markdown does not support complex html structures. In some cases, post processing may help.


Markdown only supports basic editing. For example, you can easily create a markdown hyperlink (a), that will be rendered as a html weblink (b), but you cannot add a target attribute (c):

(a) [text](http://www.example.com/index.html)

(b) <a href="http://www.example.com/index.html">text</a>

(c) <a target="_blank" href="http://www.example.com/index.html">text</a>

There are different post processing solutions possible.

For this blog, created with the bashblog tool, we slightly modify the format of the markdown hyperlink, where we simply precede the http with an arbitrary string (e.g. tg_blanc_), whenever the hyperlink needs the attribute target="_blank":

(d) [text](tg_blanc_http://www.example.com/index.html)

After compiling the html documents from the markdown files, a post processing script is used to update the created html documents. The post processor includes a sed script that transforms all tg_blanc_http into the required format:

 sed 's:href="tg_blanc_https:target="_blank" href="https:g'

As a result, the markdown hyperlink (d) will be transformed to weblink (c):

Tags: linux, markdown, target