Lightweight Markup Languages | 2 | WebReference

Lightweight Markup Languages | 2

By Arpan Dhandhania


Lightweight markup languages are markup languages designed with an honest attempt to make them simple enough for non-programmers to read and write in them. They were originally used on text-only displays on which you could not display bold or italicized text. Another application of lightweight markup languages is where people might need to read the document source as well as present a well-formatted rendered output.

Until a few years ago, to publish anything on the internet, you had three options:

1. Pay some guy who knows HTML a good sum of money to publish your stuff.

2. Befriend a web developer and get him to publish it for a lot less.

3. Spend endless hours at the computer and DIY (do it yourself).

In the last few years, the first two options have not changed. The third option however, has become a lot simpler. You have ready-made content management systems and weblogs, which make it a lot simpler for you to publish your ideas yourself. You enter the content (with a little bit of markup) into text boxes and that is converted into a standard document markup language like HTML or XML.

There are several lightweight markup languages available on the internet. In this article, we will see how to use the two most popular languages: Textile and Markdown.

Textile

Textile was developed by Dean Allen and he called it the "the humane web text generator". It was originally implemented in PHP, but later on others translated it into other programming languages like Perl, Python and Java. The current version of Textile is version 2.0 that was launched in 2006.

You can download the source code for PHP from here.

Markdown

The creators of Markdown, John Gruber and Aaron Swartz felt the need to develop a language with maximum readability of both the source code as well as the rendered output. It has taken cues from existing conventions for marking up plain text in emails. Gruber originally wrote Markdown in Perl, but then it was translated into other languages too.

Markdown doesn't support some of the features, like inline HTML and tables, that Textile does. However, Markdown Extra is a lightweight markup language that extends Markdown. We will look at how Markdown Extra implements those missing features.

You can download the source code of Markdown Extra in PHP from here.

And the others

There are several other lightweight markup languages like WikiText, Setext, ATX and etText. There could be many reasons as to why these didn't become popular. Personally I find them either unintuitive and complicated or not featured enough. As far as I am concerned, lightweight markup languages are meant to be used for formatting text for the web, not for writing technical documents.

HTML Elements in Textile/Markdown

The purpose of this article is to see how the various features can be implemented using both languages. It will give you a basis for deciding which language suits your needs better. I have covered the following elements, which are most often used by people:

Headings

HTML supports six levels of headings, <h1> thru <h6>. Both Textile and Markdown also support up to six headings. Textile is extremely particular about white spaces. You need to put a space after specifying the heading size and a blank line after each marked up line. Markdown however is easier on the white space. You don't need to leave a space after the hashes, and you can optionally add the same number of hashes at the end of the line.

Textile

Generated HTML code:

Markdown

Generated HTML code:

Phrase Emphasis

There are several ways to lay emphasis on a phrase in HTML. Textile supports many of them while Markdown only supports bold and italics.

Textile

Generated HTML code:

HTML output:

This sentence is italicized.

The last 3 words of this sentence are in bold.

You can also strike through .

And to insert a text, you can do like this.

This is the 3 rd time I am telling you the same thing.

H 2 0 is essential to life.

This is spanned out text.

You can also insert some <html> code in the middle of a sentence.

Markdown

Generated HTML Code:

HTML output:

this is italicized text

and some in bold

You can also use underscore to put emphasis instead of using asterisk.

Two consecutive underscores can be used to make some text bold

Note: Markdown supports both asterisk and underscore to make text bold or italicized.

Horizontal Rules

Horizontal rules are not supported by Textile. Markdown allows you to insert a horizontal rule in three ways.

Markdown

Generated HTML Code:

Links

Textile

Generated HTML code:

HTML output:

This is how you can link to LooseStitch using Textile.

Markdown

Generated HTML code:

HTML output:

If you are using Markdown, and want to create a link to LooseStitch, you need to do things differently.

Images

Both, Textile and Markdown allow you to create image tags easily. Markdown allows you to specify a title for the image while Textile doesn't have a way to specify the title.

Textile

Generated HTML code:

HTML output:

Markdown

Generated HTML code:

HTML output:

alt text for image

Ordered & Unordered Lists

Textile

Generated HTML code:

Markdown

Generated HTML code:

Tables

For those of you who know HTML, you may be jealous of how tables can be created in lightweight markup languages. It is such a pain to create a table in HTML. Textile makes it so simple to generate tables that you will not want to go back to creating tables in HTML. Markdown unfortunately doesn't support table creation.

Textile

Generated HTML code:

This article has covered how to use the two most popular lightweight markup languages: Textile and Markdown.

Original: December 15, 2009