Markup and markdown
When we write things down we usually do so for two reasons: for our own reference in future or to present it to others. How we present it may change, but it invariably involves formatting what we have written so that it carries visual cues about its structure, emphases etc. with a view to helping readers.
We started talking a bit about this in the last lesson when we went from listing things for ourselves by simply putting items on separate lines to marking individual items with a hyphen. While either method works for the writer, as we discussed in that lesson, adding hyphens before list items ensures that when we present that list to others it will still make sense as a list.
What is markup?
Markup, or more properly a markup language, is a system of annotating a document to convey processing information. What that means, simply, is that if you want your plain text file to one day become a PDF file or an ePub book or presentation slides or anything else, you need to sprinkle in little symbols to convey what formatting, or styling, you want.
In practice, this is a lot simpler than it sounds, and we have done one exercise with this already: lists. Adding a hyphen was not too complicated. So what a lot of people do is always add markup, often even when you do not want to present -- or process -- your plain text file in different ways. In such cases the markup adds very little extra weight to a document, might even help your own review of a plain text file in future since it adds structural cues, and in any case means all your plain text files are always ready to be converted -- or processed -- into other forms.
Markdown
There are many different forms of markup, with different languages using different forms. A popular older form is org-mode dating to the Emacs text editor. But org-mode today has a small userbase and while it can be worth picking up and putting to use, it might prove more beneficial to start with a more widely used variant known as ‘markdown’.
The ‘down’ in markdown is a nod to the fact that it is simple by design. You do very little -- mark it down -- rather than a lot -- mark it up -- like you would with other, more standardised markup languages like HTML.
Markdown is not standardised, strictly speaking. But there is enough commonality in use that it may well have an unwritten standardisation. There are attempts at standardising it, however, such as CommonMark.
One thing worth keeping in mind is that markdown does not actually format text. There are editors that make it appear this way, straddling the line between visual or WYSIWYG formatting and plain text, but markdown itself is intended to do nothing of the sort.
Re-visiting headings
In a previous lesson we talked about headings. Back then we said a heading could simply be text that is written on a line by itself. This is still true, but if you wanted to add a visual cue or, better still, if you had a second level heading and you absolutely had to specify a hierarchy, you would re-write it with markdown.
Consider the same example from that lesson. Say you wrote this in plain text:
This is a heading
And this is the body to which that heading belongs.
How do we know, though? Visual cues, mostly.
When you look at that line you can tell it is a heading
probably because of its wording, probably because of
how it is placed there all by itself, or probably
because of how this paragraph beneath is so different.
Either way you look at it, the beauty of plain text
lies in its simplicity and our human nature to be
able to quickly, effortlessly recognise unwritten cues.
Nobody will look at this extract and not identify
the first line as a heading.
It would look like it already does. That is the finished product. But what if you had a second level heading like this?
This is a level one heading
This is a level two heading
And this is the body to which that heading belongs.
How do we know, though? Visual cues, mostly.
When you look at that line you can tell it is a heading
probably because of its wording, probably because of
how it is placed there all by itself, or probably
because of how this paragraph beneath is so different.
What heading level is this?
Either way you look at it, the beauty of plain text
lies in its simplicity and our human nature to be
able to quickly, effortlessly recognise unwritten cues.
Nobody will look at this extract and not identify
the first line as a heading.
There is no way to reliably demonstrate what level the third heading in that example is. In all fairness, you could use an old technique that typewriters have been using for decades and turn it all uppercase:
THIS IS A LEVEL ONE HEADING
This is a level two heading
And this is the body to which that heading belongs.
How do we know, though? Visual cues, mostly.
When you look at that line you can tell it is a heading
probably because of its wording, probably because of
how it is placed there all by itself, or probably
because of how this paragraph beneath is so different.
This is another level two heading
Either way you look at it, the beauty of plain text
lies in its simplicity and our human nature to be
able to quickly, effortlessly recognise unwritten cues.
Nobody will look at this extract and not identify
the first line as a heading.
It is now clear that the third heading is at level two. But what about level three? And what if you do not want to write in all-uppercase text for headings within your article? Maybe, like this very document you are now reading, all-uppercase is useful only for titles.
This is where markup can help us. You can use markdown to signify you heading levels. Just like you used a hyphen for list items, use an octothorpe # for headings. And again, just like list items, spaces matter: you need to leave one space between the octothorpe and the heading text.
# This is a level one heading
## This is a level two heading
And this is the body to which that heading belongs.
How do we know, though? Visual cues, mostly.
When you look at that line you can tell it is a heading
probably because of its wording, probably because of
how it is placed there all by itself, or probably
because of how this paragraph beneath is so different.
## This is another level two heading
Either way you look at it, the beauty of plain text
lies in its simplicity and our human nature to be
able to quickly, effortlessly recognise unwritten cues.
Nobody will look at this extract and not identify
the first line as a heading.
Notice how level two headings now have two octothorpes. Likewise level three headings are signified by ### and level four by #### all the way to level six. The plain text file above will look like this when processed:
This is a level one heading
This is a level two heading
And this is the body to which that heading belongs. How do we know, though? Visual cues, mostly. When you look at that line you can tell it is a heading probably because of its wording, probably because of how it is placed there all by itself, or probably because of how this paragraph beneath is so different.
This is another level two heading
Either way you look at it, the beauty of plain text lies in its simplicity and our human nature to be able to quickly, effortlessly recognise unwritten cues. Nobody will look at this extract and not identify the first line as a heading.
You cannot mix markup languages, so pick one and stick to it. We strongly recommend markdown, which is what we use throughout this website. But know that there are others and the rules of most markup languages are comparable even as the specific symbols may vary. Here is a small selection of markup for headings besides the octothorpe:
= AsciiDoc level one heading
== AsciiDoc level two heading
* Org-mode level one heading
** Org-mode level two heading
h1. Textile level one heading
h2. Textile level two heading
= MediaWiki level one heading =
== MediaWiki level two heading ==
<h1>HTML level one heading</h1>
<h2>HTML level two heading</h2>
Even within markdown you have less popular alternatives such as underlining with equals signs:
Alternative level one heading in markdown
=========================================
Alternative level two heading in markdown
-----------------------------------------
Being much more cumbersome to write, this sort of underlining is not as popular as the straightforward octothorpe. You might still want to use it if you like that it is visually bolder.
Other markdown symbols
Now that we have a familiarity with how markdown works, we can quickly look at all the other formatting symbols. There are a few others which we will encounter in subsequent lessons, but try to become familiar with these for now:
| Format | Symbol |
|---|---|
| Heading level one | # Heading level one |
| Heading level two | ## Heading level two |
| Italic | *italic* |
| Bold | **bold** |
| List item | - List item |
| List item | * List item |
| Numbered list | 1. Numbered list |
| Numbered list | 1) Numbered list |
| Horizontal rule | *** |
| Horizontal rule | --- |
╭ > Blockquotes | |
| Blockquotes | ┤ > can span |
╰ > multiple lines |
We are now in a position to somewhat beautify our email list from an earlier lesson. We can add headings and italics and number our list this way:
# Attendees at XYZ conference
9--11 July 2024
*Chemin du Petit Saconnex*
*Geneva, Switzerland*
## Alcohol with dinner
1. [email protected]
2. [email protected]
3. [email protected]
## No alcohol with dinner
4) [email protected]
6) [email protected]
7) [email protected]
Not only does this look even better thanks to a clearer and unambiguous structure, it can also be processed to look better (see below).
Notice that the numbers in the second list are wrong. Perhaps we had someone at number 5 who dropped out in the last minute, so we deleted them from our list. But that did not mean we had to re-number the entire list manually. No, the only number that matters is the first one: the list numbering starts with that and then proceeds to the end so long as there is a number for each item.
Here is what the processed text would look like:
Attendees at XYZ conference
9--11 July 2024
Chemin du Petit Saconnex
Geneva, SwitzerlandAlcohol with dinner
No alcohol with dinner
TIP A great benefit of using markup is that you do not have to move between your keyboard and mouse. You can italicise as you type, for example. Of course you can also do this with cmd + I or ctrl + I on your word processor application. But you cannot do plenty of other things there, like proper headings. And as you will see in a coming lesson you can also make tables this way with markdown, or add images or links. The markdown symbols table above was made with markdown too.
Philosophy
There is a lot of thinking that goes behind writing plain text. First and foremost is that plain text should be readable. Note from all our examples so far how markdown does not get in the way of plain text being readable. If anything, it makes the document it clearer still. This is why HTML did not take off except on the web where it was critical infrastructure. Nobody wrote quick notes to themselves using HTML; it was always plain text even before markdown (perhaps with AsciiDoc or org-mode).
But what exactly does it clarify: the language, the structure, the presentation? Perhaps all three? This is a separate discussion but is nevertheless worth considering whenever we use markup of any kind.
When it comes to appearance remember that the output samples shown above -- and indeed everywhere else on this website -- are just one possible example. You can always style the output as you like, you can even style multiple outputs for the same source of text. But that one source of text -- the source of truth as some call it -- will always be your plain text file, likely with markup of some sort.
Other markdown codes
Having listed other markdown symbols above, we will now quickly run through them with examples and processed outputs.
This text is normal. *This is italics.* **And this is bold.**
***
The line above is a horizontal rule.
Think of it as a visual separator.
Ideally, having a blank line around it makes it clearer.
This text is normal. This is italics. And this is bold.
The line above is a horizontal rule. Think of it as a visual separator. Ideally, having a blank line around it makes it clearer.
This is normal text.
> This is a block quote.
>
> You can have blank lines too.\
> And multiple lines of course.
And then continue the main text body.
This is normal text.
This is a block quote.
You can have blank lines too.
And multiple lines of course.And then continue the main text body.
Use it sparingly, but know that a backslash \ character has many uses that you will learn as we go. One of these is to signify a forced break in the line. With that character in, two lines will no longer join as one in the processed output. This is what we have done in the example above to break lines in the blockquote.
Use markdown to signal what is and let the processor handle what it looks like.
TIP Although we recommended earlier that you should keep different markup variants separate, HTML is an exception to this. While you should not be mixing, say, markdown and org-mode, both will nevertheless accept HTML. Most people will never need it in a plain text file -- markdown is plenty -- but if you do, you can use it. HTML is more capable, but it was never designed to be easily readable.
Speaking of capability, it should be clear by now what Markdown cannot do: e.g., it cannot colour text and it cannot lay ‘pages’ out precisely.
This document is part of the plain text lesson plan. If you are ready, you can proceed to the next lesson.