{"id":9128,"date":"2013-02-27T12:06:21","date_gmt":"2013-02-27T17:06:21","guid":{"rendered":"https:\/\/crashingpatient.com\/?p=9128"},"modified":"2014-07-15T18:14:15","modified_gmt":"2014-07-15T22:14:15","slug":"markdown-syntax-from-bret-terpstra","status":"publish","type":"post","link":"https:\/\/crashingpatient.com\/miscellaneous\/markdown-syntax-from-bret-terpstra.htm\/","title":{"rendered":"Markdown Syntax from John Gruber’s Site"},"content":{"rendered":"
For any markup that is not covered by Markdown\u2019s syntax, you simply use HTML itself. There\u2019s no need to preface it or delimit it to indicate that you\u2019re switching from Markdown to HTML; you just use the tags. The only restrictions are that block-level HTML elements \u2014 e.g. Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can\u2019t use Markdown-style Markdown allows you to use these characters naturally, taking care of all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged; otherwise it will be translated into and Markdown will leave it alone. But if you write: <\/p>\n Markdown will translate it to: <\/p>\n Similarly, because Markdown supports inline HTML<\/a>, if you use angle brackets as delimiters for HTML tags, Markdown will treat them as such. But if you write: <\/p>\n Markdown will translate it to: <\/p>\n However, inside Markdown code spans and blocks, angle brackets and ampersands are always<\/em> encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line \u2014 a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs. The implication of the \u201cone or more consecutive lines of text\u201d rule is that Markdown supports \u201chard-wrapped\u201d text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type\u2019s \u201cConvert Line Breaks\u201d option) which translate every line break character in a paragraph into a Atx-style headers use 1-6 hash characters at the start of the line, corresponding to header levels 1-6. For example: <\/p>\n Markdown uses email-style Markdown allows you to be lazy and only put the Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of Blockquotes can contain other Markdown elements, including headers, lists, and code blocks: <\/p>\n Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu. <\/p>\n Markdown supports ordered (numbered) and unordered (bulleted) lists. Unordered lists use asterisks, pluses, and hyphens \u2014 interchangably \u2014 as list markers: <\/p>\n is equivalent to: <\/p>\n and: <\/p>\n Ordered lists use numbers followed by periods: <\/p>\n List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab. To make lists look nice, you can wrap items with hanging indents: <\/p>\n But if you want to be lazy, you don\u2019t have to: <\/p>\n If list items are separated by blank lines, Markdown will wrap the items in will turn into: <\/p>\n List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab: <\/p>\n It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy: <\/p>\n It\u2019s worth noting that it\u2019s possible to trigger an ordered list by accident, by writing something like this: <\/p>\n In other words, a number-period-space<\/em> sequence at the beginning of a line. To avoid this, you can backslash-escape the period: <\/p>\n You can produce a horizontal rule tag ( Markdown supports two style of links: inline<\/em> and reference<\/em>. In both styles, the link text is delimited by [square brackets]. To create an inline link, use a set of regular parentheses immediately after the link text\u2019s closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an optional<\/em> title for the link, surrounded in quotes. For example: <\/p>\n Will produce: <\/p>\n If you\u2019re referring to a local resource on the same server, you can use relative paths: <\/p>\n Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link: <\/p>\n You can optionally use a space to separate the sets of brackets: <\/p>\n Then, anywhere in the document, you define your link label like this, on a line by itself: <\/p>\n That is: <\/p>\n The following three link definitions are equivalent: <\/p>\n Note:<\/strong> There is a known bug in Markdown.pl 1.0.1 which prevents single quotes from being used to delimit link titles. The link URL may, optionally, be surrounded by angle brackets: <\/p>\n You can put the title attribute on the next line and use extra spaces or tabs for padding, which tends to look better with longer URLs: <\/p>\n Link definitions are only used for creating links during Markdown processing, and are stripped from your document in the HTML output. Link definition names may consist of letters, numbers, spaces, and punctuation \u2014 but they are not<\/em> case sensitive. E.g. these two links: <\/p>\n are equivalent. The implicit link name<\/em> shortcut allows you to omit the name of the link, in which case the link text itself is used as the name. Just use an empty set of square brackets \u2014 e.g., to link the word \u201cGoogle\u201d to the google.com web site, you could simply write: <\/p>\n And then define the link: <\/p>\n Because link names may contain spaces, this shortcut even works for multiple words in the link text: <\/p>\n And then define the link: <\/p>\n Link definitions can be placed anywhere in your Markdown document. I tend to put them immediately after each paragraph in which they\u2019re used, but if you want, you can put them all at the end of your document, sort of like footnotes. Here\u2019s an example of reference links in action: <\/p>\n Using the implicit link name shortcut, you could instead write: <\/p>\n Both of the above examples will produce the following HTML output: <\/p>\n For comparison, here is the same paragraph written using Markdown\u2019s inline link style: <\/p>\n The point of reference-style links is not that they\u2019re easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it\u2019s 176 characters; and as raw HTML, it\u2019s 234 characters. In the raw HTML, there\u2019s more markup than there is text. With Markdown\u2019s reference-style links, a source document much more closely resembles the final output, as rendered in a browser. By allowing you to move the markup-related metadata out of the paragraph, you can add links without interrupting the narrative flow of your prose. <\/p>\n Markdown treats asterisks ( will produce: <\/p>\n You can use whichever style you prefer; the lone restriction is that the same character must be used to open and close an emphasis span. Emphasis can be used in the middle of a word: <\/p>\n But if you surround an To indicate a span of code, wrap it with backtick quotes ( will produce: <\/p>\n To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters: <\/p>\n which will produce this: <\/p>\n The backtick delimiters surrounding a code span may include spaces \u2014 one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span: <\/p>\n will produce: <\/p>\n With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags. Markdown will turn this: <\/p>\n into: <\/p>\n You can write this: <\/p>\n to produce: <\/p>\n Admittedly, it\u2019s fairly difficult to devise a \u201cnatural\u201d syntax for placing images into a plain text document format. Markdown uses an image syntax that is intended to resemble the syntax for links, allowing for two styles: inline<\/em> and reference<\/em>. Inline image syntax looks like this: <\/p>\n That is: <\/p>\n Reference-style image syntax looks like this: <\/p>\n Where \u201cid\u201d is the name of a defined image reference. Image references are defined using syntax identical to link references: <\/p>\n As of this writing, Markdown has no syntax for specifying the dimensions of an image; if this is important to you, you can simply use regular HTML Markdown supports a shortcut style for creating \u201cautomatic\u201d links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this: <\/p>\n Markdown will turn this into: <\/p>\n<div><\/code>,
<table><\/code>,
<pre><\/code>,
<p><\/code>, etc. \u2014 must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted)
<p><\/code> tags around HTML block-level tags. For example, to add an HTML table to a Markdown article: <\/p>\n
This is a regular paragraph. <table> <tr> <td>Foo<\/td> <\/tr> <\/table> This is another regular paragraph. <\/code><\/pre>\n
*emphasis*<\/code> inside an HTML block. Span-level HTML tags \u2014 e.g.
<span><\/code>,
<cite><\/code>, or
<del><\/code> \u2014 can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you\u2019d prefer to use HTML
<a><\/code> or
<img><\/code> tags instead of Markdown\u2019s link or image syntax, go right ahead. Unlike block-level HTML tags, Markdown syntax is<\/em> processed within span-level tags. <\/p>\n
<\/span>Automatic Escaping for Special Characters<\/span><\/h3>\n
&<\/code>. So, if you want to include a copyright symbol in your article, you can write: <\/p>\n
© <\/code><\/pre>\n
AT&T <\/code><\/pre>\n
AT&T <\/code><\/pre>\n
4 < 5 <\/code><\/pre>\n
4 < 5 <\/code><\/pre>\n
<<\/code> and
&<\/code> in your example code needs to be escaped.) <\/p>\n
\n<\/span>Block Elements<\/span><\/h2>\n
<\/span>Paragraphs and Line Breaks<\/span><\/h3>\n
<br \/><\/code> tag. When you do<\/em> want to insert a
<br \/><\/code> break tag using Markdown, you end a line with two or more spaces, then type return. Yes, this takes a tad more effort to create a
<br \/><\/code>, but a simplistic \u201cevery line break is a
<br \/><\/code>\u201d rule wouldn\u2019t work for Markdown. Markdown\u2019s email-style blockquoting<\/a> and multi-paragraph list items<\/a> work best \u2014 and look better \u2014 when you format them with hard breaks. <\/p>\n
<\/span>Headers<\/span><\/h3>\n
# This is an H1 ## This is an H2 ###### This is an H6 <\/code><\/pre>\n
<\/span>Blockquotes<\/span><\/h3>\n
><\/code> characters for blockquoting. If you\u2019re familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a
><\/code> before every line: <\/p>\n
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse > id sem consectetuer libero luctus adipiscing. <\/code><\/pre>\n
><\/code> before the first line of a hard-wrapped paragraph: <\/p>\n
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. <\/code><\/pre>\n
><\/code>: <\/p>\n
> This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level. <\/code><\/pre>\n
> ## This is a header. > > 1. This is the first list item. > 2. This is the second list item. > > Here's some example code: > > return shell_exec(\"echo $input | $markdown_script\"); <\/code><\/pre>\n
<\/span>Lists<\/span><\/h3>\n
* Red * Green * Blue <\/code><\/pre>\n
+ Red + Green + Blue <\/code><\/pre>\n
- Red - Green - Blue <\/code><\/pre>\n
1. Bird 2. McHale 3. Parish <\/code><\/pre>\n
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. <\/code><\/pre>\n
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. <\/code><\/pre>\n
<p><\/code> tags in the HTML output. For example, this input: <\/p>\n
* Bird * Magic <\/code><\/pre>\n
<ul> <li>Bird<\/li> <li>Magic<\/li> <\/ul> <\/code><\/pre>\n
1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 2. Suspendisse id sem consectetuer libero luctus adipiscing. <\/code><\/pre>\n
* This is a list item with two paragraphs. This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Another item in the same list. <\/code><\/pre>\n
1986. What a great season. <\/code><\/pre>\n
1986\\. What a great season. <\/code><\/pre>\n
<\/span>Horizontal Rules<\/span><\/h3>\n
<hr \/><\/code>) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks. Each of the following lines will produce a horizontal rule: <\/p>\n
* * * *** ***** - - - --------------------------------------- <\/code><\/pre>\n
\n<\/span>Span Elements<\/span><\/h2>\n
<\/span>Links<\/span><\/h3>\n
This is [an example](http:\/\/example.com\/ \"Title\") inline link. [This link](http:\/\/example.net\/) has no title attribute. <\/code><\/pre>\n
<p>This is <a href=\"http:\/\/example.com\/\" title=\"Title\"> an example<\/a> inline link.<\/p> <p><a href=\"http:\/\/example.net\/\">This link<\/a> has no title attribute.<\/p> <\/code><\/pre>\n
See my [About](\/about\/) page for details. <\/code><\/pre>\n
This is [an example][id] reference-style link. <\/code><\/pre>\n
This is [an example] [id] reference-style link. <\/code><\/pre>\n
[id]: http:\/\/example.com\/ \"Optional Title Here\" <\/code><\/pre>\n
\n
[foo]: http:\/\/example.com\/ \"Optional Title Here\" [foo]: http:\/\/example.com\/ 'Optional Title Here' [foo]: http:\/\/example.com\/ (Optional Title Here) <\/code><\/pre>\n
[id]: <http:\/\/example.com\/> \"Optional Title Here\" <\/code><\/pre>\n
[id]: http:\/\/example.com\/longish\/path\/to\/resource\/here \"Optional Title Here\" <\/code><\/pre>\n
[link text][a] [link text][A] <\/code><\/pre>\n
[Google][] <\/code><\/pre>\n
[Google]: http:\/\/google.com\/ <\/code><\/pre>\n
Visit [Daring Fireball][] for more information. <\/code><\/pre>\n
[Daring Fireball]: http:\/\/daringfireball.net\/ <\/code><\/pre>\n
I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3]. [1]: http:\/\/google.com\/ \"Google\" [2]: http:\/\/search.yahoo.com\/ \"Yahoo Search\" [3]: http:\/\/search.msn.com\/ \"MSN Search\" <\/code><\/pre>\n
I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [google]: http:\/\/google.com\/ \"Google\" [yahoo]: http:\/\/search.yahoo.com\/ \"Yahoo Search\" [msn]: http:\/\/search.msn.com\/ \"MSN Search\" <\/code><\/pre>\n
<p>I get 10 times more traffic from <a href=\"http:\/\/google.com\/\" title=\"Google\">Google<\/a> than from <a href=\"http:\/\/search.yahoo.com\/\" title=\"Yahoo Search\">Yahoo<\/a> or <a href=\"http:\/\/search.msn.com\/\" title=\"MSN Search\">MSN<\/a>.<\/p> <\/code><\/pre>\n
I get 10 times more traffic from [Google](http:\/\/google.com\/ \"Google\") than from [Yahoo](http:\/\/search.yahoo.com\/ \"Yahoo Search\") or [MSN](http:\/\/search.msn.com\/ \"MSN Search\"). <\/code><\/pre>\n
<\/span>Emphasis<\/span><\/h3>\n
*<\/code>) and underscores (
_<\/code>) as indicators of emphasis. Text wrapped with one
*<\/code> or
_<\/code> will be wrapped with an HTML
<em><\/code> tag; double
*<\/code>\u2019s or
_<\/code>\u2019s will be wrapped with an HTML
<strong><\/code> tag. E.g., this input: <\/p>\n
*single asterisks* _single underscores_ **double asterisks** __double underscores__ <\/code><\/pre>\n
<em>single asterisks<\/em> <em>single underscores<\/em> <strong>double asterisks<\/strong> <strong>double underscores<\/strong> <\/code><\/pre>\n
un*frigging*believable <\/code><\/pre>\n
*<\/code> or
_<\/code> with spaces, it\u2019ll be treated as a literal asterisk or underscore. To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis delimiter, you can backslash escape it: <\/p>\n
\\*this text is surrounded by literal asterisks\\* <\/code><\/pre>\n
<\/span>Code<\/span><\/h3>\n
`<\/code>). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example: <\/p>\n
Use the `printf()` function. <\/code><\/pre>\n
<p>Use the <code>printf()<\/code> function.<\/p> <\/code><\/pre>\n
``There is a literal backtick (`) here.`` <\/code><\/pre>\n
<p><code>There is a literal backtick (`) here.<\/code><\/p> <\/code><\/pre>\n
A single backtick in a code span: `` ` `` A backtick-delimited string in a code span: `` `foo` `` <\/code><\/pre>\n
<p>A single backtick in a code span: <code>`<\/code><\/p> <p>A backtick-delimited string in a code span: <code>`foo`<\/code><\/p> <\/code><\/pre>\n
Please don't use any `<blink>` tags. <\/code><\/pre>\n
<p>Please don't use any <code><blink><\/code> tags.<\/p> <\/code><\/pre>\n
`—` is the decimal-encoded equivalent of `—`. <\/code><\/pre>\n
<p><code>&#8212;<\/code> is the decimal-encoded equivalent of <code>&mdash;<\/code>.<\/p> <\/code><\/pre>\n
<\/span>Images<\/span><\/h3>\n
![Alt text](\/path\/to\/img.jpg) ![Alt text](\/path\/to\/img.jpg \"Optional title\") <\/code><\/pre>\n
\n
!<\/code>;<\/li>\n
alt<\/code> attribute text for the image;<\/li>\n
title<\/code> attribute enclosed in double or single quotes.<\/li>\n<\/ul>\n
![Alt text][id] <\/code><\/pre>\n
[id]: url\/to\/image \"Optional title attribute\" <\/code><\/pre>\n
<img><\/code> tags. <\/p>\n
\n<\/span>Miscellaneous<\/span><\/h2>\n
<\/span>Automatic Links<\/span><\/h3>\n
<http:\/\/example.com\/> <\/code><\/pre>\n