├── doc ├── todo.md └── broken.md ├── .npmignore ├── test ├── new │ ├── escaped_angles.md │ ├── escaped_angles.html │ ├── gfm_del.md │ ├── not_a_link.md │ ├── lazy_blockquotes.md │ ├── gfm_del.html │ ├── nested_code.md │ ├── not_a_link.html │ ├── ref_paren.md │ ├── same_bullet.md │ ├── case_insensitive_refs.md │ ├── gfm_em.md │ ├── nested_square_link.md │ ├── autolink_lines.md │ ├── case_insensitive_refs.html │ ├── nested_code.html │ ├── gfm_break.html │ ├── gfm_em.html │ ├── ref_paren.html │ ├── list_item_text.md │ ├── nested_em.md │ ├── uppercase_hex.html │ ├── gfm_links.md │ ├── gfm_links_invalid.html │ ├── hr_list_break.md │ ├── nested_square_link.html │ ├── gfm_break.md │ ├── lazy_blockquotes.html │ ├── links.html │ ├── same_bullet.html │ ├── list_item_text.html │ ├── blockquote_list_item.md │ ├── gfm_hashtag.md │ ├── nogfm_hashtag.md │ ├── autolink_lines.html │ ├── gfm_links_invalid.md │ ├── gfm_hashtag.html │ ├── nested_em.html │ ├── gfm_links.html │ ├── nogfm_hashtag.html │ ├── hr_list_break.html │ ├── mangle_xss.md │ ├── uppercase_hex.md │ ├── blockquote_list_item.html │ ├── smartypants.html │ ├── smartypants.md │ ├── tricky_list.md │ ├── def_blocks.md │ ├── double_link.md │ ├── mangle_xss.html │ ├── double_link.html │ ├── links.md │ ├── def_blocks.html │ ├── tricky_list.html │ ├── gfm_code.md │ ├── loose_lists.md │ ├── toplevel_paragraphs.md │ ├── gfm_tables.md │ ├── gfm_code.html │ ├── toplevel_paragraphs.html │ ├── relative_urls.md │ ├── gfm_code_hr_list.md │ ├── loose_lists.html │ ├── gfm_code_hr_list.html │ ├── main.md │ ├── main.html │ ├── links_reference_style.md │ ├── relative_urls.html │ ├── gfm_tables.html │ └── links_reference_style.html ├── original │ ├── nested_blockquotes.md │ ├── tidyness.md │ ├── literal_quotes_in_titles.md │ ├── strong_and_em_together.md │ ├── nested_blockquotes.html │ ├── tidyness.html │ ├── code_spans.md │ ├── literal_quotes_in_titles.html │ ├── blockquotes_with_code_blocks.md │ ├── inline_html_advanced.md │ ├── inline_html_comments.md │ ├── code_spans.html │ ├── inline_html_advanced.html │ ├── strong_and_em_together.html │ ├── hard_wrapped_paragraphs_with_list_like_lines.md │ ├── inline_html_comments.html │ ├── code_blocks.md │ ├── hard_wrapped_paragraphs_with_list_like_lines.html │ ├── blockquotes_with_code_blocks.html │ ├── links_shortcut_references.html │ ├── auto_links.md │ ├── links_shortcut_references.md │ ├── code_blocks.html │ ├── tabs.md │ ├── links_inline_style.md │ ├── amps_and_angles_encoding.md │ ├── tabs.html │ ├── links_inline_style.html │ ├── amps_and_angles_encoding.html │ ├── horizontal_rules.md │ ├── auto_links.html │ ├── horizontal_rules.html │ ├── inline_html_simple.md │ ├── inline_html_simple.html │ ├── links_reference_style.md │ ├── links_reference_style.html │ ├── ordered_and_unordered_lists.md │ ├── backslash_escapes.md │ ├── backslash_escapes.html │ ├── ordered_and_unordered_lists.html │ ├── markdown_documentation_basics.md │ ├── markdown_documentation_basics.html │ ├── markdown_documentation_syntax.md │ └── markdown_documentation_syntax.html ├── browser │ ├── index.html │ ├── index.js │ └── test.js ├── README └── index.js ├── .gitignore ├── index.js ├── .travis.yml ├── .github └── ISSUE_TEMPLATE.md ├── component.json ├── Makefile ├── bower.json ├── Gulpfile.js ├── package.json ├── LICENSE ├── man ├── marked.1 └── marked.1.txt ├── bin └── marked ├── README.md └── marked.min.js /doc/todo.md: -------------------------------------------------------------------------------- 1 | # Todo 2 | 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | test/ 3 | -------------------------------------------------------------------------------- /test/new/escaped_angles.md: -------------------------------------------------------------------------------- 1 | \> 2 | -------------------------------------------------------------------------------- /test/new/escaped_angles.html: -------------------------------------------------------------------------------- 1 |

>

2 | -------------------------------------------------------------------------------- /test/new/gfm_del.md: -------------------------------------------------------------------------------- 1 | hello ~~hi~~ world 2 | -------------------------------------------------------------------------------- /test/new/not_a_link.md: -------------------------------------------------------------------------------- 1 | \[test](not a link) 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test/compiled_tests 3 | -------------------------------------------------------------------------------- /test/new/lazy_blockquotes.md: -------------------------------------------------------------------------------- 1 | > hi there 2 | bud 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/marked'); 2 | -------------------------------------------------------------------------------- /test/new/gfm_del.html: -------------------------------------------------------------------------------- 1 |

hello hi world

2 | -------------------------------------------------------------------------------- /test/new/nested_code.md: -------------------------------------------------------------------------------- 1 | ````` hi ther `` ok ``` ````` 2 | -------------------------------------------------------------------------------- /test/new/not_a_link.html: -------------------------------------------------------------------------------- 1 |

[test](not a link)

2 | -------------------------------------------------------------------------------- /test/new/ref_paren.md: -------------------------------------------------------------------------------- 1 | [hi] 2 | 3 | [hi]: /url (there) 4 | -------------------------------------------------------------------------------- /test/new/same_bullet.md: -------------------------------------------------------------------------------- 1 | * test 2 | + test 3 | - test 4 | -------------------------------------------------------------------------------- /test/new/case_insensitive_refs.md: -------------------------------------------------------------------------------- 1 | [hi] 2 | 3 | [HI]: /url 4 | -------------------------------------------------------------------------------- /test/new/gfm_em.md: -------------------------------------------------------------------------------- 1 | These words should_not_be_emphasized. 2 | -------------------------------------------------------------------------------- /test/new/nested_square_link.md: -------------------------------------------------------------------------------- 1 | [the `]` character](/url) 2 | -------------------------------------------------------------------------------- /test/new/autolink_lines.md: -------------------------------------------------------------------------------- 1 | hello world 2 | 3 | -------------------------------------------------------------------------------- /test/new/case_insensitive_refs.html: -------------------------------------------------------------------------------- 1 |

hi

2 | -------------------------------------------------------------------------------- /test/new/nested_code.html: -------------------------------------------------------------------------------- 1 |

hi ther `` ok ```

2 | -------------------------------------------------------------------------------- /test/new/gfm_break.html: -------------------------------------------------------------------------------- 1 |

Look at the
pretty line
breaks.

2 | -------------------------------------------------------------------------------- /test/new/gfm_em.html: -------------------------------------------------------------------------------- 1 |

These words should_not_be_emphasized.

2 | -------------------------------------------------------------------------------- /test/new/ref_paren.html: -------------------------------------------------------------------------------- 1 |

hi

2 | -------------------------------------------------------------------------------- /test/new/list_item_text.md: -------------------------------------------------------------------------------- 1 | * item1 2 | 3 | * item2 4 | 5 | text 6 | -------------------------------------------------------------------------------- /test/new/nested_em.md: -------------------------------------------------------------------------------- 1 | *test **test** test* 2 | 3 | _test __test__ test_ 4 | -------------------------------------------------------------------------------- /test/new/uppercase_hex.html: -------------------------------------------------------------------------------- 1 |

lowerclickmelower 2 | upperclickmeupper

3 | -------------------------------------------------------------------------------- /test/new/gfm_links.md: -------------------------------------------------------------------------------- 1 | This should be a link: http://example.com/hello-world. 2 | -------------------------------------------------------------------------------- /test/original/nested_blockquotes.md: -------------------------------------------------------------------------------- 1 | > foo 2 | > 3 | > > bar 4 | > 5 | > foo 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.8" 5 | - "0.6" 6 | -------------------------------------------------------------------------------- /test/new/gfm_links_invalid.html: -------------------------------------------------------------------------------- 1 |

This should not be linked: http://example.com/%ff

2 | -------------------------------------------------------------------------------- /test/new/hr_list_break.md: -------------------------------------------------------------------------------- 1 | * hello 2 | world 3 | * how 4 | are 5 | * * * 6 | you today? 7 | -------------------------------------------------------------------------------- /test/new/nested_square_link.html: -------------------------------------------------------------------------------- 1 |

the ] character

2 | -------------------------------------------------------------------------------- /test/new/gfm_break.md: -------------------------------------------------------------------------------- 1 | --- 2 | breaks: true 3 | --- 4 | Look at the 5 | pretty line 6 | breaks. 7 | -------------------------------------------------------------------------------- /test/new/lazy_blockquotes.html: -------------------------------------------------------------------------------- 1 |
2 |

hi there 3 | bud

4 |
5 | -------------------------------------------------------------------------------- /test/new/links.html: -------------------------------------------------------------------------------- 1 |

URL

2 |

URL

3 |

URL

4 |

URL

5 |

URL

6 | -------------------------------------------------------------------------------- /test/new/same_bullet.html: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/new/list_item_text.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/new/blockquote_list_item.md: -------------------------------------------------------------------------------- 1 | This fails in markdown.pl and upskirt: 2 | 3 | * hello 4 | > world 5 | -------------------------------------------------------------------------------- /test/new/gfm_hashtag.md: -------------------------------------------------------------------------------- 1 | --- 2 | gfm: true 3 | --- 4 | #header 5 | 6 | # header1 7 | 8 | # header2 9 | -------------------------------------------------------------------------------- /test/new/nogfm_hashtag.md: -------------------------------------------------------------------------------- 1 | --- 2 | gfm: false 3 | --- 4 | #header 5 | 6 | # header1 7 | 8 | # header2 9 | -------------------------------------------------------------------------------- /test/new/autolink_lines.html: -------------------------------------------------------------------------------- 1 |

hello world 2 | http://example.com 3 |

4 | -------------------------------------------------------------------------------- /test/new/gfm_links_invalid.md: -------------------------------------------------------------------------------- 1 | --- 2 | sanitize: true 3 | --- 4 | This should not be linked: http://example.com/%ff 5 | -------------------------------------------------------------------------------- /test/new/gfm_hashtag.html: -------------------------------------------------------------------------------- 1 |

#header

2 | 3 |

header1

4 | 5 |

header2

6 | -------------------------------------------------------------------------------- /test/original/tidyness.md: -------------------------------------------------------------------------------- 1 | > A list within a blockquote: 2 | > 3 | > * asterisk 1 4 | > * asterisk 2 5 | > * asterisk 3 6 | -------------------------------------------------------------------------------- /test/new/nested_em.html: -------------------------------------------------------------------------------- 1 |

test test test

2 | 3 |

test test test

4 | -------------------------------------------------------------------------------- /test/new/gfm_links.html: -------------------------------------------------------------------------------- 1 |

This should be a link: 2 | http://example.com/hello-world.

3 | -------------------------------------------------------------------------------- /test/new/nogfm_hashtag.html: -------------------------------------------------------------------------------- 1 |

header

2 | 3 |

header1

4 | 5 |

header2

6 | -------------------------------------------------------------------------------- /test/new/hr_list_break.html: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 | 10 |

you today?

11 | -------------------------------------------------------------------------------- /test/new/mangle_xss.md: -------------------------------------------------------------------------------- 1 | --- 2 | sanatize: true 3 | mangle: false 4 | --- 5 | < 6 | 7 | 8 | -------------------------------------------------------------------------------- /test/new/uppercase_hex.md: -------------------------------------------------------------------------------- 1 | --- 2 | sanitize: true 3 | --- 4 | lower[click me](javascript:...)lower 5 | upper[click me](javascript:...)upper 6 | -------------------------------------------------------------------------------- /test/new/blockquote_list_item.html: -------------------------------------------------------------------------------- 1 |

This fails in markdown.pl and upskirt:

2 | 3 | 4 | -------------------------------------------------------------------------------- /test/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | marked tests 3 |

testing...

4 | 5 | 6 | -------------------------------------------------------------------------------- /test/original/literal_quotes_in_titles.md: -------------------------------------------------------------------------------- 1 | Foo [bar][]. 2 | 3 | Foo [bar](/url/ "Title with "quotes" inside"). 4 | 5 | 6 | [bar]: /url/ "Title with "quotes" inside" 7 | 8 | -------------------------------------------------------------------------------- /test/original/strong_and_em_together.md: -------------------------------------------------------------------------------- 1 | ***This is strong and em.*** 2 | 3 | So is ***this*** word. 4 | 5 | ___This is strong and em.___ 6 | 7 | So is ___this___ word. 8 | -------------------------------------------------------------------------------- /test/original/nested_blockquotes.html: -------------------------------------------------------------------------------- 1 |
2 |

foo

3 | 4 |
5 |

bar

6 |
7 | 8 |

foo

9 |
10 | -------------------------------------------------------------------------------- /test/original/tidyness.html: -------------------------------------------------------------------------------- 1 |
2 |

A list within a blockquote:

3 | 8 |
9 | -------------------------------------------------------------------------------- /test/new/smartypants.html: -------------------------------------------------------------------------------- 1 |

Hello world ‘how’ “are” you – today…

2 | 3 |

“It’s a more ‘challenging’ smartypants test…”

4 | 5 |

‘And,’ as a bonus — “one 6 | multiline” test!

7 | -------------------------------------------------------------------------------- /test/original/code_spans.md: -------------------------------------------------------------------------------- 1 | `` 2 | 3 | Fix for backticks within HTML tag: like this 4 | 5 | Here's how you put `` `backticks` `` in a code span. 6 | 7 | -------------------------------------------------------------------------------- /test/original/literal_quotes_in_titles.html: -------------------------------------------------------------------------------- 1 |

Foo bar.

2 | 3 |

Foo bar.

4 | -------------------------------------------------------------------------------- /test/new/smartypants.md: -------------------------------------------------------------------------------- 1 | --- 2 | smartypants: true 3 | --- 4 | Hello world 'how' "are" you -- today... 5 | 6 | "It's a more 'challenging' smartypants test..." 7 | 8 | 'And,' as a bonus --- "one 9 | multiline" test! 10 | -------------------------------------------------------------------------------- /test/new/tricky_list.md: -------------------------------------------------------------------------------- 1 | **hello** _world_ 2 | 3 | * hello world 4 | 5 | **hello** _world_ 6 | 7 | * hello world 8 | 9 | **hello** _world_ 10 | 11 | * Hello world 12 | 13 | **hello** _world_ 14 | 15 | * hello world 16 | -------------------------------------------------------------------------------- /test/original/blockquotes_with_code_blocks.md: -------------------------------------------------------------------------------- 1 | > Example: 2 | > 3 | > sub status { 4 | > print "working"; 5 | > } 6 | > 7 | > Or: 8 | > 9 | > sub status { 10 | > return "working"; 11 | > } 12 | -------------------------------------------------------------------------------- /test/new/def_blocks.md: -------------------------------------------------------------------------------- 1 | > hello 2 | > [1]: hello 3 | 4 | * * * 5 | 6 | > hello 7 | [2]: hello 8 | 9 | 10 | * hello 11 | * [3]: hello 12 | 13 | 14 | * hello 15 | [4]: hello 16 | 17 | 18 | > foo 19 | > bar 20 | [1]: foo 21 | > bar 22 | -------------------------------------------------------------------------------- /test/new/double_link.md: -------------------------------------------------------------------------------- 1 |

Already linked: http://example.com/.

2 | 3 | Already linked: [http://example.com/](http://example.com/). 4 | 5 | Already linked: **http://example.com/**. 6 | -------------------------------------------------------------------------------- /test/original/inline_html_advanced.md: -------------------------------------------------------------------------------- 1 | Simple block on one line: 2 | 3 |
foo
4 | 5 | And nested without indentation: 6 | 7 |
8 |
9 |
10 | foo 11 |
12 |
13 |
14 |
bar
15 |
16 | -------------------------------------------------------------------------------- /test/original/inline_html_comments.md: -------------------------------------------------------------------------------- 1 | Paragraph one. 2 | 3 | 4 | 5 | 8 | 9 | Paragraph two. 10 | 11 | 12 | 13 | The end. 14 | -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | In this directory: 2 | 3 | # 4 | # MarkdownTester -- Run tests for Markdown implementations 5 | # 6 | # Copyright (c) 2004-2005 John Gruber 7 | # 8 | # 9 | 10 | Partially modified for testing purposes. 11 | -------------------------------------------------------------------------------- /test/new/mangle_xss.html: -------------------------------------------------------------------------------- 1 |

<svg/onload="alert(1)"//@x

2 | 3 |

bar"onclick="alert('XSS')"@foo

4 | -------------------------------------------------------------------------------- /test/original/code_spans.html: -------------------------------------------------------------------------------- 1 |

<test a=" content of attribute ">

2 | 3 |

Fix for backticks within HTML tag: like this

4 | 5 |

Here's how you put `backticks` in a code span.

6 | 7 | -------------------------------------------------------------------------------- /test/original/inline_html_advanced.html: -------------------------------------------------------------------------------- 1 |

Simple block on one line:

2 | 3 |
foo
4 | 5 |

And nested without indentation:

6 | 7 |
8 |
9 |
10 | foo 11 |
12 |
13 |
14 |
bar
15 |
16 | -------------------------------------------------------------------------------- /test/original/strong_and_em_together.html: -------------------------------------------------------------------------------- 1 |

This is strong and em.

2 | 3 |

So is this word.

4 | 5 |

This is strong and em.

6 | 7 |

So is this word.

8 | -------------------------------------------------------------------------------- /test/original/hard_wrapped_paragraphs_with_list_like_lines.md: -------------------------------------------------------------------------------- 1 | In Markdown 1.0.0 and earlier. Version 2 | 8. This line turns into a list item. 3 | Because a hard-wrapped line in the 4 | middle of a paragraph looked like a 5 | list item. 6 | 7 | Here's one with a bullet. 8 | * criminey. 9 | -------------------------------------------------------------------------------- /test/original/inline_html_comments.html: -------------------------------------------------------------------------------- 1 |

Paragraph one.

2 | 3 | 4 | 5 | 8 | 9 |

Paragraph two.

10 | 11 | 12 | 13 |

The end.

14 | -------------------------------------------------------------------------------- /test/new/double_link.html: -------------------------------------------------------------------------------- 1 |

Already linked: http://example.com/.

2 | 3 |

Already linked: http://example.com/.

4 | 5 |

Already linked: http://example.com/.

6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expectation 2 | 3 | 4 | 5 | ## Result 6 | 7 | 8 | 9 | ## What was attempted 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/original/code_blocks.md: -------------------------------------------------------------------------------- 1 | code block on the first line 2 | 3 | Regular text. 4 | 5 | code block indented by spaces 6 | 7 | Regular text. 8 | 9 | the lines in this block 10 | all contain trailing spaces 11 | 12 | Regular Text. 13 | 14 | code block on the last line 15 | -------------------------------------------------------------------------------- /test/original/hard_wrapped_paragraphs_with_list_like_lines.html: -------------------------------------------------------------------------------- 1 |

In Markdown 1.0.0 and earlier. Version 2 | 8. This line turns into a list item. 3 | Because a hard-wrapped line in the 4 | middle of a paragraph looked like a 5 | list item.

6 | 7 |

Here's one with a bullet. 8 | * criminey.

9 | -------------------------------------------------------------------------------- /test/new/links.md: -------------------------------------------------------------------------------- 1 | --- 2 | sanitize: true 3 | --- 4 | [URL](javascript:alert) 5 | 6 | [URL](vbscript:alert) 7 | 8 | [URL](javascript:alert(1)) 9 | 10 | [URL](javascript:document;alert(1)) 11 | 12 | [URL](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K) 13 | -------------------------------------------------------------------------------- /test/original/blockquotes_with_code_blocks.html: -------------------------------------------------------------------------------- 1 |
2 |

Example:

3 | 4 |
sub status {
 5 |     print "working";
 6 | }
 7 | 
8 | 9 |

Or:

10 | 11 |
sub status {
12 |     return "working";
13 | }
14 | 
15 |
16 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "marked", 3 | "version": "0.3.4", 4 | "repo": "chjj/marked", 5 | "description": "A markdown parser built for speed", 6 | "keywords": ["markdown", "markup", "html"], 7 | "scripts": ["lib/marked.js"], 8 | "main": "lib/marked.js", 9 | "license": "MIT" 10 | } 11 | -------------------------------------------------------------------------------- /test/original/links_shortcut_references.html: -------------------------------------------------------------------------------- 1 |

This is the simple case.

2 | 3 |

This one has a line 4 | break.

5 | 6 |

This one has a line 7 | break with a line-ending space.

8 | 9 |

this and the other

10 | -------------------------------------------------------------------------------- /test/original/auto_links.md: -------------------------------------------------------------------------------- 1 | Link: . 2 | 3 | With an ampersand: 4 | 5 | * In a list? 6 | * 7 | * It should. 8 | 9 | > Blockquoted: 10 | 11 | Auto-links should not occur here: `` 12 | 13 | or here: 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @cp lib/marked.js marked.js 3 | @uglifyjs --comments '/\*[^\0]+?Copyright[^\0]+?\*/' -o marked.min.js lib/marked.js 4 | 5 | clean: 6 | @rm marked.js 7 | @rm marked.min.js 8 | 9 | bench: 10 | @node test --bench 11 | 12 | man/marked.1.txt: 13 | groff -man -Tascii man/marked.1 | col -b > man/marked.1.txt 14 | 15 | .PHONY: clean all 16 | -------------------------------------------------------------------------------- /test/original/links_shortcut_references.md: -------------------------------------------------------------------------------- 1 | This is the [simple case]. 2 | 3 | [simple case]: /simple 4 | 5 | 6 | 7 | This one has a [line 8 | break]. 9 | 10 | This one has a [line 11 | break] with a line-ending space. 12 | 13 | [line break]: /foo 14 | 15 | 16 | [this] [that] and the [other] 17 | 18 | [this]: /this 19 | [that]: /that 20 | [other]: /other 21 | -------------------------------------------------------------------------------- /test/new/def_blocks.html: -------------------------------------------------------------------------------- 1 |
2 |

hello 3 | [1]: hello

4 |
5 | 6 |
7 | 8 |
9 |

hello

10 |
11 | 12 | 13 |
    14 |
  • hello
  • 15 |
  • [3]: hello
  • 16 |
17 | 18 | 19 |
    20 |
  • hello
  • 21 |
22 | 23 | 24 |
25 |

foo 26 | bar 27 | bar

28 |
29 | -------------------------------------------------------------------------------- /test/original/code_blocks.html: -------------------------------------------------------------------------------- 1 |
code block on the first line
 2 | 
3 | 4 |

Regular text.

5 | 6 |
code block indented by spaces
 7 | 
8 | 9 |

Regular text.

10 | 11 |
the lines in this block  
12 | all contain trailing spaces  
13 | 
14 | 15 |

Regular Text.

16 | 17 |
code block on the last line
18 | 
19 | -------------------------------------------------------------------------------- /test/original/tabs.md: -------------------------------------------------------------------------------- 1 | + this is a list item 2 | indented with tabs 3 | 4 | + this is a list item 5 | indented with spaces 6 | 7 | Code: 8 | 9 | this code block is indented by one tab 10 | 11 | And: 12 | 13 | this code block is indented by two tabs 14 | 15 | And: 16 | 17 | + this is an example list item 18 | indented with tabs 19 | 20 | + this is an example list item 21 | indented with spaces 22 | -------------------------------------------------------------------------------- /test/original/links_inline_style.md: -------------------------------------------------------------------------------- 1 | Just a [URL](/url/). 2 | 3 | [URL and title](/url/ "title"). 4 | 5 | [URL and title](/url/ "title preceded by two spaces"). 6 | 7 | [URL and title](/url/ "title preceded by a tab"). 8 | 9 | [URL and title](/url/ "title has spaces afterward" ). 10 | 11 | [URL and title]( /url/has space ). 12 | 13 | [URL and title]( /url/has space/ "url has space and title"). 14 | 15 | [Empty](). 16 | -------------------------------------------------------------------------------- /test/new/tricky_list.html: -------------------------------------------------------------------------------- 1 |

hello world

2 | 3 |
    4 |
  • hello world
  • 5 |
6 | 7 |

hello world

8 | 9 |
    10 |
  • hello world
  • 11 |
12 | 13 |

hello world

14 | 15 |
    16 |
  • Hello world
  • 17 |
18 | 19 |

hello world

20 | 21 |
    22 |
  • hello world
  • 23 |
24 | -------------------------------------------------------------------------------- /test/original/amps_and_angles_encoding.md: -------------------------------------------------------------------------------- 1 | AT&T has an ampersand in their name. 2 | 3 | AT&T is another way to write it. 4 | 5 | This & that. 6 | 7 | 4 < 5. 8 | 9 | 6 > 5. 10 | 11 | Here's a [link] [1] with an ampersand in the URL. 12 | 13 | Here's a link with an amersand in the link text: [AT&T] [2]. 14 | 15 | Here's an inline [link](/script?foo=1&bar=2). 16 | 17 | Here's an inline [link](). 18 | 19 | 20 | [1]: http://example.com/?foo=1&bar=2 21 | [2]: http://att.com/ "AT&T" 22 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "marked", 3 | "homepage": "https://github.com/chjj/marked", 4 | "authors": [ 5 | "Christopher Jeffrey " 6 | ], 7 | "description": "A markdown parser built for speed", 8 | "keywords": [ 9 | "markdown", 10 | "markup", 11 | "html" 12 | ], 13 | "main": "lib/marked.js", 14 | "license": "MIT", 15 | "ignore": [ 16 | "**/.*", 17 | "node_modules", 18 | "bower_components", 19 | "app/bower_components", 20 | "test", 21 | "tests" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /test/new/gfm_code.md: -------------------------------------------------------------------------------- 1 | ``` js 2 | var a = 'hello'; 3 | console.log(a + ' world'); 4 | ``` 5 | 6 | ~~~bash 7 | echo "hello, ${WORLD}" 8 | ~~~ 9 | 10 | ```````longfence 11 | Q: What do you call a tall person who sells stolen goods? 12 | ``````` 13 | 14 | ~~~~~~~~~~ ManyTildes 15 | A longfence! 16 | ~~~~~~~~~~ 17 | 18 | How about an empty code block? 19 | 20 | ```js 21 | ``` 22 | 23 | How about a code block with only an empty line? 24 | 25 | ```js 26 | 27 | ``` 28 | 29 | With some trailing empty lines: 30 | 31 | ``` 32 | ciao 33 | 34 | 35 | ``` 36 | -------------------------------------------------------------------------------- /test/new/loose_lists.md: -------------------------------------------------------------------------------- 1 | * hello 2 | world 3 | 4 | how 5 | are 6 | * you 7 | 8 | 9 | 10 | better behavior: 11 | 12 | * hello 13 | * world 14 | how 15 | 16 | are 17 | you 18 | 19 | * today 20 | * hi 21 | 22 | 23 | 24 | * hello 25 | 26 | * world 27 | * hi 28 | 29 | 30 | 31 | * hello 32 | * world 33 | 34 | * hi 35 | 36 | 37 | 38 | * hello 39 | * world 40 | 41 | how 42 | * hi 43 | 44 | 45 | 46 | * hello 47 | * world 48 | * how 49 | 50 | are 51 | 52 | 53 | 54 | * hello 55 | * world 56 | 57 | * how 58 | 59 | are 60 | -------------------------------------------------------------------------------- /test/original/tabs.html: -------------------------------------------------------------------------------- 1 |
    2 |
  • this is a list item 3 | indented with tabs

  • 4 |
  • this is a list item 5 | indented with spaces

  • 6 |
7 | 8 |

Code:

9 | 10 |
this code block is indented by one tab
11 | 
12 | 13 |

And:

14 | 15 |
    this code block is indented by two tabs
16 | 
17 | 18 |

And:

19 | 20 |
+   this is an example list item
21 |     indented with tabs
22 | 
23 | +   this is an example list item
24 |     indented with spaces
25 | 
26 | -------------------------------------------------------------------------------- /Gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uglify = require('gulp-uglify'); 3 | var concat = require('gulp-concat'); 4 | 5 | var preserveFirstComment = function() { 6 | var set = false; 7 | 8 | return function() { 9 | if (set) return false; 10 | set = true; 11 | return true; 12 | }; 13 | }; 14 | 15 | gulp.task('uglify', function() { 16 | gulp.src('lib/marked.js') 17 | .pipe(uglify({preserveComments: preserveFirstComment()})) 18 | .pipe(concat('marked.min.js')) 19 | .pipe(gulp.dest('.')); 20 | }); 21 | 22 | gulp.task('default', ['uglify']); 23 | -------------------------------------------------------------------------------- /test/original/links_inline_style.html: -------------------------------------------------------------------------------- 1 |

Just a URL.

2 | 3 |

URL and title.

4 | 5 |

URL and title.

6 | 7 |

URL and title.

8 | 9 |

URL and title.

10 | 11 |

URL and title.

12 | 13 |

URL and title.

14 | 15 |

Empty.

16 | -------------------------------------------------------------------------------- /test/new/toplevel_paragraphs.md: -------------------------------------------------------------------------------- 1 | --- 2 | gfm: true 3 | --- 4 | hello world 5 | how are you 6 | how are you 7 | 8 | hello world 9 | ``` 10 | how are you 11 | ``` 12 | 13 | hello world 14 | * * * 15 | 16 | hello world 17 | # how are you 18 | 19 | hello world 20 | how are you 21 | =========== 22 | 23 | hello world 24 | > how are you 25 | 26 | hello world 27 | * how are you 28 | 29 | hello world 30 |
how are you
31 | 32 | hello world 33 | how are you 34 | 35 | hello [world][how] 36 | 37 | [how]: /are/you 38 | 39 |
hello
40 | 41 | hello 42 | -------------------------------------------------------------------------------- /test/new/gfm_tables.md: -------------------------------------------------------------------------------- 1 | | Heading 1 | Heading 2 2 | | --------- | --------- 3 | | Cell 1 | Cell 2 4 | | Cell 3 | Cell 4 5 | 6 | | Header 1 | Header 2 | Header 3 | Header 4 | 7 | | :------: | -------: | :------- | -------- | 8 | | Cell 1 | Cell 2 | Cell 3 | Cell 4 | 9 | | Cell 5 | Cell 6 | Cell 7 | Cell 8 | 10 | 11 | Test code 12 | 13 | Header 1 | Header 2 14 | -------- | -------- 15 | Cell 1 | Cell 2 16 | Cell 3 | Cell 4 17 | 18 | Header 1|Header 2|Header 3|Header 4 19 | :-------|:------:|-------:|-------- 20 | Cell 1 |Cell 2 |Cell 3 |Cell 4 21 | *Cell 5*|Cell 6 |Cell 7 |Cell 8 22 | -------------------------------------------------------------------------------- /test/original/amps_and_angles_encoding.html: -------------------------------------------------------------------------------- 1 |

AT&T has an ampersand in their name.

2 | 3 |

AT&T is another way to write it.

4 | 5 |

This & that.

6 | 7 |

4 < 5.

8 | 9 |

6 > 5.

10 | 11 |

Here's a link with an ampersand in the URL.

12 | 13 |

Here's a link with an amersand in the link text: AT&T.

14 | 15 |

Here's an inline link.

16 | 17 |

Here's an inline link.

18 | -------------------------------------------------------------------------------- /test/original/horizontal_rules.md: -------------------------------------------------------------------------------- 1 | Dashes: 2 | 3 | --- 4 | 5 | --- 6 | 7 | --- 8 | 9 | --- 10 | 11 | --- 12 | 13 | - - - 14 | 15 | - - - 16 | 17 | - - - 18 | 19 | - - - 20 | 21 | - - - 22 | 23 | 24 | Asterisks: 25 | 26 | *** 27 | 28 | *** 29 | 30 | *** 31 | 32 | *** 33 | 34 | *** 35 | 36 | * * * 37 | 38 | * * * 39 | 40 | * * * 41 | 42 | * * * 43 | 44 | * * * 45 | 46 | 47 | Underscores: 48 | 49 | ___ 50 | 51 | ___ 52 | 53 | ___ 54 | 55 | ___ 56 | 57 | ___ 58 | 59 | _ _ _ 60 | 61 | _ _ _ 62 | 63 | _ _ _ 64 | 65 | _ _ _ 66 | 67 | _ _ _ 68 | -------------------------------------------------------------------------------- /test/original/auto_links.html: -------------------------------------------------------------------------------- 1 |

Link: http://example.com/.

2 | 3 |

With an ampersand: http://example.com/?foo=1&bar=2

4 | 5 | 10 | 11 |
12 |

Blockquoted: http://example.com/

13 |
14 | 15 |

Auto-links should not occur here: <http://example.com/>

16 | 17 |
or here: <http://example.com/>
18 | 
19 | -------------------------------------------------------------------------------- /test/new/gfm_code.html: -------------------------------------------------------------------------------- 1 |
var a = 'hello';
 2 | console.log(a + ' world');
3 |
echo "hello, ${WORLD}"
4 |
Q: What do you call a tall person who sells stolen goods?
5 |
A longfence!
6 |

How about an empty code block?

7 |
8 |

How about a code block with only an empty line?

9 |

10 | 
11 | 12 |

With some trailing empty lines:

13 |
ciao
14 | 
15 | 
16 | 
-------------------------------------------------------------------------------- /test/new/toplevel_paragraphs.html: -------------------------------------------------------------------------------- 1 |

hello world 2 | how are you 3 | how are you

4 | 5 |

hello world

6 |
how are you
7 | 8 |

hello world

9 |
10 | 11 |

hello world

12 |

how are you

13 | 14 |

hello world

15 |

how are you

16 | 17 |

hello world

18 |

how are you

19 | 20 |

hello world

21 |
  • how are you
22 | 23 |

hello world

24 |
how are you
25 | 26 |

hello world 27 | how are you

28 | 29 |

hello world 30 |

31 | 32 |
hello
33 | 34 |

hello

35 | -------------------------------------------------------------------------------- /test/new/relative_urls.md: -------------------------------------------------------------------------------- 1 | --- 2 | baseUrl: "http://example.com/base/" 3 | --- 4 | # Absolutization of RFC 3986 URIs 5 | 6 | ## Absolute URI 7 | [![section 4.3](http://example.com/logo)](http://example.com/) 8 | 9 | ## Network-path reference 10 | [![section 4.2](//example.com/logo)](//example.com/) 11 | 12 | ## Absolute path 13 | [![section 4.2](/path/to/img)](/path/to/content) 14 | 15 | ## Relative path 16 | [![section 4.2](img)](content) 17 | 18 | ## Dot-relative path 19 | [![section 3.3](./img)](./content) 20 | 21 | [![section 3.3](../img)](../content) 22 | 23 | ## Same-document query 24 | [![section 4.4](?type=image)](?) 25 | 26 | ## Same-document fragment 27 | [![section 4.4](#img)](#) 28 | 29 | ## Empty 30 | [section 4.2]() 31 | -------------------------------------------------------------------------------- /test/original/horizontal_rules.html: -------------------------------------------------------------------------------- 1 |

Dashes:

2 | 3 |
4 | 5 |
6 | 7 |
8 | 9 |
10 | 11 |
---
12 | 
13 | 14 |
15 | 16 |
17 | 18 |
19 | 20 |
21 | 22 |
- - -
23 | 
24 | 25 |

Asterisks:

26 | 27 |
28 | 29 |
30 | 31 |
32 | 33 |
34 | 35 |
***
36 | 
37 | 38 |
39 | 40 |
41 | 42 |
43 | 44 |
45 | 46 |
* * *
47 | 
48 | 49 |

Underscores:

50 | 51 |
52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 |
___
60 | 
61 | 62 |
63 | 64 |
65 | 66 |
67 | 68 |
69 | 70 |
_ _ _
71 | 
72 | -------------------------------------------------------------------------------- /test/new/gfm_code_hr_list.md: -------------------------------------------------------------------------------- 1 | ## foo 2 | 3 | 1. bar: 4 | 5 | > - one 6 | - two 7 | - three 8 | - four 9 | - five 10 | 11 | 1. foo: 12 | 13 | ``` 14 | line 1 15 | line 2 16 | ``` 17 | 18 | 1. foo: 19 | 20 | 1. foo `bar` bar: 21 | 22 | ``` erb 23 | some code here 24 | ``` 25 | 26 | 2. foo `bar` bar: 27 | 28 | ``` erb 29 | foo 30 | --- 31 | bar 32 | --- 33 | foo 34 | bar 35 | ``` 36 | 37 | 3. foo `bar` bar: 38 | 39 | ``` html 40 | --- 41 | foo 42 | foo 43 | --- 44 | bar 45 | ``` 46 | 47 | 4. foo `bar` bar: 48 | 49 | foo 50 | --- 51 | bar 52 | 53 | 5. foo 54 | -------------------------------------------------------------------------------- /test/new/loose_lists.html: -------------------------------------------------------------------------------- 1 |
    2 |
  • hello 3 | world

    4 | 5 |

    how 6 | are

  • 7 |
  • you
  • 8 |
9 | 10 | 11 | 12 |

better behavior:

13 | 14 |
  • hello

    • world 15 | how

      are 16 | you

    • today

  • hi
17 | 18 | 19 | 20 |
    21 |
  • hello

  • 22 |
  • world

  • 23 |
  • hi
  • 24 |
25 | 26 | 27 | 28 |
    29 |
  • hello
  • 30 |
  • world

  • 31 |
  • hi

  • 32 |
33 | 34 | 35 | 36 |
    37 |
  • hello
  • 38 |
  • world

    39 | 40 |

    how

  • 41 |
  • hi
  • 42 |
43 | 44 | 45 | 46 |
    47 |
  • hello
  • 48 |
  • world
  • 49 |
  • how

    50 | 51 |

    are

  • 52 |
53 | 54 | 55 | 56 |
    57 |
  • hello
  • 58 |
  • world

  • 59 |
  • how

    60 | 61 |

    are

  • 62 |
63 | -------------------------------------------------------------------------------- /test/original/inline_html_simple.md: -------------------------------------------------------------------------------- 1 | Here's a simple block: 2 | 3 |
4 | foo 5 |
6 | 7 | This should be a code block, though: 8 | 9 |
10 | foo 11 |
12 | 13 | As should this: 14 | 15 |
foo
16 | 17 | Now, nested: 18 | 19 |
20 |
21 |
22 | foo 23 |
24 |
25 |
26 | 27 | This should just be an HTML comment: 28 | 29 | 30 | 31 | Multiline: 32 | 33 | 37 | 38 | Code block: 39 | 40 | 41 | 42 | Just plain comment, with trailing spaces on the line: 43 | 44 | 45 | 46 | Code: 47 | 48 |
49 | 50 | Hr's: 51 | 52 |
53 | 54 |
55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 | 66 |
67 | 68 |
69 | 70 | -------------------------------------------------------------------------------- /test/new/gfm_code_hr_list.html: -------------------------------------------------------------------------------- 1 |

foo

2 |
    3 |
  1. bar:

    4 |
    5 |
      6 |
    • one
        7 |
      • two
          8 |
        • three
        • 9 |
        • four
        • 10 |
        • five
        • 11 |
        12 |
      • 13 |
      14 |
    • 15 |
    16 |
    17 |
  2. 18 |
  3. foo:

    19 |
     line 1
    20 |  line 2
    21 |
  4. 22 |
  5. foo:

    23 |
      24 |
    1. foo bar bar:

      25 |
       some code here
      26 | 
      27 |
    2. 28 |
    3. foo bar bar:

      29 |
       foo
      30 |  ---
      31 |  bar
      32 |  ---
      33 |  foo
      34 |  bar
      35 |
    4. 36 |
    5. foo bar bar:

      37 |
       ---
      38 |  foo
      39 |  foo
      40 |  ---
      41 |  bar
      42 |
    6. 43 |
    7. foo bar bar:

      44 |
       foo
      45 |  ---
      46 |  bar
      47 |
    8. 48 |
    9. foo

      49 |
    10. 50 |
    51 |
  6. 52 |
53 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "marked", 3 | "description": "A markdown parser built for speed", 4 | "author": "Christopher Jeffrey", 5 | "version": "0.3.12", 6 | "main": "./lib/marked.js", 7 | "bin": "./bin/marked", 8 | "man": "./man/marked.1", 9 | "repository": "git://github.com/chjj/marked.git", 10 | "homepage": "https://github.com/chjj/marked", 11 | "bugs": { 12 | "url": "http://github.com/chjj/marked/issues" 13 | }, 14 | "license": "MIT", 15 | "keywords": [ 16 | "markdown", 17 | "markup", 18 | "html" 19 | ], 20 | "tags": [ 21 | "markdown", 22 | "markup", 23 | "html" 24 | ], 25 | "devDependencies": { 26 | "markdown": "*", 27 | "showdown": "*", 28 | "markdown-it": "*", 29 | "front-matter": "^2.3.0", 30 | "glob-to-regexp": "0.3.0", 31 | "gulp": "^3.8.11", 32 | "gulp-uglify": "^1.1.0", 33 | "gulp-concat": "^2.5.2" 34 | }, 35 | "scripts": { 36 | "test": "node test", 37 | "bench": "node test --bench" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/browser/index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | var test = require('../') 4 | , runTests = test.runTests 5 | , load = test.load; 6 | 7 | var express = require('express') 8 | , app = express(); 9 | 10 | app.use(function(req, res, next) { 11 | var setHeader = res.setHeader; 12 | res.setHeader = function(name) { 13 | switch (name) { 14 | case 'Cache-Control': 15 | case 'Last-Modified': 16 | case 'ETag': 17 | return; 18 | } 19 | return setHeader.apply(res, arguments); 20 | }; 21 | next(); 22 | }); 23 | 24 | var dir = __dirname + '/../tests' 25 | , files = {}; 26 | 27 | app.get('/test.js', function(req, res, next) { 28 | var test = fs.readFileSync(__dirname + '/test.js', 'utf8') 29 | , files = load(); 30 | 31 | test = test.replace('__TESTS__', JSON.stringify(files)); 32 | test = test.replace('__MAIN__', runTests + ''); 33 | 34 | res.contentType('.js'); 35 | res.send(test); 36 | }); 37 | 38 | app.use(express.static(__dirname + '/../../lib')); 39 | app.use(express.static(__dirname)); 40 | 41 | app.listen(8080); 42 | -------------------------------------------------------------------------------- /test/original/inline_html_simple.html: -------------------------------------------------------------------------------- 1 |

Here's a simple block:

2 | 3 |
4 | foo 5 |
6 | 7 |

This should be a code block, though:

8 | 9 |
<div>
10 |     foo
11 | </div>
12 | 
13 | 14 |

As should this:

15 | 16 |
<div>foo</div>
17 | 
18 | 19 |

Now, nested:

20 | 21 |
22 |
23 |
24 | foo 25 |
26 |
27 |
28 | 29 |

This should just be an HTML comment:

30 | 31 | 32 | 33 |

Multiline:

34 | 35 | 39 | 40 |

Code block:

41 | 42 |
<!-- Comment -->
43 | 
44 | 45 |

Just plain comment, with trailing spaces on the line:

46 | 47 | 48 | 49 |

Code:

50 | 51 |
<hr />
52 | 
53 | 54 |

Hr's:

55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 | 66 |
67 | 68 |
69 | 70 |
71 | 72 |
73 | -------------------------------------------------------------------------------- /test/original/links_reference_style.md: -------------------------------------------------------------------------------- 1 | Foo [bar] [1]. 2 | 3 | Foo [bar][1]. 4 | 5 | Foo [bar] 6 | [1]. 7 | 8 | [1]: /url/ "Title" 9 | 10 | 11 | With [embedded [brackets]] [b]. 12 | 13 | 14 | Indented [once][]. 15 | 16 | Indented [twice][]. 17 | 18 | Indented [thrice][]. 19 | 20 | Indented [four][] times. 21 | 22 | [once]: /url 23 | 24 | [twice]: /url 25 | 26 | [thrice]: /url 27 | 28 | [four]: /url 29 | 30 | 31 | [b]: /url/ 32 | 33 | * * * 34 | 35 | [this] [this] should work 36 | 37 | So should [this][this]. 38 | 39 | And [this] []. 40 | 41 | And [this][]. 42 | 43 | And [this]. 44 | 45 | But not [that] []. 46 | 47 | Nor [that][]. 48 | 49 | Nor [that]. 50 | 51 | [Something in brackets like [this][] should work] 52 | 53 | [Same with [this].] 54 | 55 | In this case, [this](/somethingelse/) points to something else. 56 | 57 | Backslashing should suppress \[this] and [this\]. 58 | 59 | [this]: foo 60 | 61 | 62 | * * * 63 | 64 | Here's one where the [link 65 | breaks] across lines. 66 | 67 | Here's another where the [link 68 | breaks] across lines, but with a line-ending space. 69 | 70 | 71 | [link breaks]: /url/ 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2014, Christopher Jeffrey (https://github.com/chjj/) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /test/new/main.md: -------------------------------------------------------------------------------- 1 | [test]: http://google.com/ "Google" 2 | 3 | # A heading 4 | 5 | Just a note, I've found that I can't test my markdown parser vs others. 6 | For example, both markdown.js and showdown code blocks in lists wrong. They're 7 | also completely [inconsistent][test] with regards to paragraphs in list items. 8 | 9 | A link. Not anymore. 10 | 11 | 13 | 14 | * List Item 1 15 | 16 | * List Item 2 17 | * New List Item 1 18 | Hi, this is a list item. 19 | * New List Item 2 20 | Another item 21 | Code goes here. 22 | Lots of it... 23 | * New List Item 3 24 | The last item 25 | 26 | * List Item 3 27 | The final item. 28 | 29 | * List Item 4 30 | The real final item. 31 | 32 | Paragraph. 33 | 34 | > * bq Item 1 35 | > * bq Item 2 36 | > * New bq Item 1 37 | > * New bq Item 2 38 | > Text here 39 | 40 | * * * 41 | 42 | > Another blockquote! 43 | > I really need to get 44 | > more creative with 45 | > mockup text.. 46 | > markdown.js breaks here again 47 | 48 | Another Heading 49 | ------------- 50 | 51 | Hello *world*. Here is a [link](//hello). 52 | And an image ![alt](src). 53 | 54 | Code goes here. 55 | Lots of it... 56 | -------------------------------------------------------------------------------- /test/new/main.html: -------------------------------------------------------------------------------- 1 |

A heading

Just a note, I've found that I can't test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They're also completely inconsistent with regards to paragraphs in list items.

A link. Not anymore.

  • List Item 1

  • List Item 2

    • New List Item 1 Hi, this is a list item.
    • New List Item 2 Another item
      Code goes here.
      3 | Lots of it...
    • New List Item 3 The last item
  • List Item 3 The final item.

  • List Item 4 The real final item.

Paragraph.

  • bq Item 1
  • bq Item 2
    • New bq Item 1
    • New bq Item 2 Text here

Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again

Another Heading

Hello world. Here is a link. And an image alt.

Code goes here.
4 | Lots of it...
5 | -------------------------------------------------------------------------------- /test/new/links_reference_style.md: -------------------------------------------------------------------------------- 1 | Foo [bar] [1]. 2 | 3 | Foo [bar][1]. 4 | 5 | Foo [bar] 6 | [1]. 7 | 8 | [1]: /url/ "Title" 9 | 10 | 11 | With [embedded [brackets]] [b]. 12 | 13 | 14 | Indented [once][]. 15 | 16 | Indented [twice][]. 17 | 18 | Indented [thrice][]. 19 | 20 | Indented [four][] times. 21 | 22 | [once]: /url 23 | 24 | [twice]: /url 25 | 26 | [thrice]: /url 27 | 28 | [four]: /url 29 | 30 | 31 | [b]: /url/ 32 | 33 | * * * 34 | 35 | [this] [this] should work 36 | 37 | So should [this][this]. 38 | 39 | And [this] []. 40 | 41 | And [this][]. 42 | 43 | And [this]. 44 | 45 | But not [that] []. 46 | 47 | Nor [that][]. 48 | 49 | Nor [that]. 50 | 51 | [Something in brackets like [this][] should work] 52 | 53 | [Same with [this].] 54 | 55 | In this case, [this](/somethingelse/) points to something else. 56 | 57 | Backslashing should suppress \[this] and [this\]. 58 | 59 | [this]: foo 60 | 61 | A link reference definition cannot interrupt a paragraph. 62 | [bar]: /baz 63 | 64 | [bar] 65 | 66 | However, it can directly follow other block elements, such as headings 67 | 68 | # [Foo] 69 | [foo]: /url 70 | > bar 71 | 72 | * * * 73 | 74 | Here's one where the [link 75 | breaks] across lines. 76 | 77 | Here's another where the [link 78 | breaks] across lines, but with a line-ending space. 79 | 80 | 81 | [link breaks]: /url/ 82 | -------------------------------------------------------------------------------- /test/original/links_reference_style.html: -------------------------------------------------------------------------------- 1 |

Foo bar.

2 | 3 |

Foo bar.

4 | 5 |

Foo bar.

6 | 7 |

With embedded [brackets].

8 | 9 |

Indented once.

10 | 11 |

Indented twice.

12 | 13 |

Indented thrice.

14 | 15 |

Indented [four][] times.

16 | 17 |
[four]: /url
18 | 
19 | 20 |
21 | 22 |

this should work

23 | 24 |

So should this.

25 | 26 |

And this.

27 | 28 |

And this.

29 | 30 |

And this.

31 | 32 |

But not [that] [].

33 | 34 |

Nor [that][].

35 | 36 |

Nor [that].

37 | 38 |

[Something in brackets like this should work]

39 | 40 |

[Same with this.]

41 | 42 |

In this case, this points to something else.

43 | 44 |

Backslashing should suppress [this] and [this].

45 | 46 |
47 | 48 |

Here's one where the link 49 | breaks across lines.

50 | 51 |

Here's another where the link 52 | breaks across lines, but with a line-ending space.

53 | -------------------------------------------------------------------------------- /test/new/relative_urls.html: -------------------------------------------------------------------------------- 1 |

Absolutization of RFC 3986 URIs

2 | 3 |

Absolute URI

4 | 5 |

section 4.3

6 | 7 |

Network-path reference

8 | 9 |

section 4.2

10 | 11 |

Absolute path

12 | 13 |

section 4.2

14 | 15 |

Relative path

16 | 17 |

section 4.2

18 | 19 |

Dot-relative path

20 | 21 |

section 3.3

22 | 23 |

section 3.3

24 | 25 |

Same-document query

26 | 27 |

section 4.4

28 | 29 |

Same-document fragment

30 | 31 |

section 4.4

32 | 33 |

Empty

34 | 35 |

section 4.2

36 | -------------------------------------------------------------------------------- /test/browser/test.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 3 | var console = {} 4 | , files = __TESTS__; 5 | 6 | console.log = function(text) { 7 | var args = Array.prototype.slice.call(arguments, 1) 8 | , i = 0; 9 | 10 | text = text.replace(/%\w/g, function() { 11 | return args[i++] || ''; 12 | }); 13 | 14 | if (window.console) window.console.log(text); 15 | document.body.innerHTML += '
' + escape(text) + '
'; 16 | }; 17 | 18 | if (!Object.keys) { 19 | Object.keys = function(obj) { 20 | var out = [] 21 | , key; 22 | 23 | for (key in obj) { 24 | if (Object.prototype.hasOwnProperty.call(obj, key)) { 25 | out.push(key); 26 | } 27 | } 28 | 29 | return out; 30 | }; 31 | } 32 | 33 | if (!Array.prototype.forEach) { 34 | Array.prototype.forEach = function(callback, context) { 35 | for (var i = 0; i < this.length; i++) { 36 | callback.call(context || null, this[i], i, obj); 37 | } 38 | }; 39 | } 40 | 41 | if (!String.prototype.trim) { 42 | String.prototype.trim = function() { 43 | return this.replace(/^\s+|\s+$/g, ''); 44 | }; 45 | } 46 | 47 | function load() { 48 | return files; 49 | } 50 | 51 | function escape(html, encode) { 52 | return html 53 | .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') 54 | .replace(//g, '>') 56 | .replace(/"/g, '"') 57 | .replace(/'/g, '''); 58 | } 59 | 60 | (__MAIN__)(); 61 | 62 | }).call(this); 63 | -------------------------------------------------------------------------------- /test/new/gfm_tables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Heading 1Heading 2
Cell 1Cell 2
Cell 3Cell 4
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
19 |
Test code
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Header 1Header 2
Cell 1Cell 2
Cell 3Cell 4
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
38 | -------------------------------------------------------------------------------- /test/new/links_reference_style.html: -------------------------------------------------------------------------------- 1 |

Foo bar.

2 | 3 |

Foo bar.

4 | 5 |

Foo bar.

6 | 7 |

With embedded [brackets].

8 | 9 |

Indented once.

10 | 11 |

Indented twice.

12 | 13 |

Indented thrice.

14 | 15 |

Indented [four][] times.

16 | 17 |
[four]: /url
18 | 
19 | 20 |
21 | 22 |

this should work

23 | 24 |

So should this.

25 | 26 |

And this.

27 | 28 |

And this.

29 | 30 |

And this.

31 | 32 |

But not [that] [].

33 | 34 |

Nor [that][].

35 | 36 |

Nor [that].

37 | 38 |

[Something in brackets like this should work]

39 | 40 |

[Same with this.]

41 | 42 |

In this case, this points to something else.

43 | 44 |

Backslashing should suppress [this] and [this].

45 | 46 |

A link reference definition cannot interrupt a paragraph. 47 | [bar]: /baz

48 |

[bar]

49 | 50 |

However, it can directly follow other block elements, such as headings

51 |

Foo

52 |
53 |

bar

54 |
55 | 56 |
57 | 58 |

Here's one where the link 59 | breaks across lines.

60 | 61 |

Here's another where the link 62 | breaks across lines, but with a line-ending space.

63 | -------------------------------------------------------------------------------- /test/original/ordered_and_unordered_lists.md: -------------------------------------------------------------------------------- 1 | ## Unordered 2 | 3 | Asterisks tight: 4 | 5 | * asterisk 1 6 | * asterisk 2 7 | * asterisk 3 8 | 9 | 10 | Asterisks loose: 11 | 12 | * asterisk 1 13 | 14 | * asterisk 2 15 | 16 | * asterisk 3 17 | 18 | * * * 19 | 20 | Pluses tight: 21 | 22 | + Plus 1 23 | + Plus 2 24 | + Plus 3 25 | 26 | 27 | Pluses loose: 28 | 29 | + Plus 1 30 | 31 | + Plus 2 32 | 33 | + Plus 3 34 | 35 | * * * 36 | 37 | 38 | Minuses tight: 39 | 40 | - Minus 1 41 | - Minus 2 42 | - Minus 3 43 | 44 | 45 | Minuses loose: 46 | 47 | - Minus 1 48 | 49 | - Minus 2 50 | 51 | - Minus 3 52 | 53 | 54 | ## Ordered 55 | 56 | Tight: 57 | 58 | 1. First 59 | 2. Second 60 | 3. Third 61 | 62 | and: 63 | 64 | 1. One 65 | 2. Two 66 | 3. Three 67 | 68 | 69 | Loose using tabs: 70 | 71 | 1. First 72 | 73 | 2. Second 74 | 75 | 3. Third 76 | 77 | and using spaces: 78 | 79 | 1. One 80 | 81 | 2. Two 82 | 83 | 3. Three 84 | 85 | Multiple paragraphs: 86 | 87 | 1. Item 1, graf one. 88 | 89 | Item 2. graf two. The quick brown fox jumped over the lazy dog's 90 | back. 91 | 92 | 2. Item 2. 93 | 94 | 3. Item 3. 95 | 96 | 97 | 98 | ## Nested 99 | 100 | * Tab 101 | * Tab 102 | * Tab 103 | 104 | Here's another: 105 | 106 | 1. First 107 | 2. Second: 108 | * Fee 109 | * Fie 110 | * Foe 111 | 3. Third 112 | 113 | Same thing but with paragraphs: 114 | 115 | 1. First 116 | 117 | 2. Second: 118 | * Fee 119 | * Fie 120 | * Foe 121 | 122 | 3. Third 123 | 124 | 125 | This was an error in Markdown 1.0.1: 126 | 127 | * this 128 | 129 | * sub 130 | 131 | that 132 | -------------------------------------------------------------------------------- /test/original/backslash_escapes.md: -------------------------------------------------------------------------------- 1 | These should all get escaped: 2 | 3 | Backslash: \\ 4 | 5 | Backtick: \` 6 | 7 | Asterisk: \* 8 | 9 | Underscore: \_ 10 | 11 | Left brace: \{ 12 | 13 | Right brace: \} 14 | 15 | Left bracket: \[ 16 | 17 | Right bracket: \] 18 | 19 | Left paren: \( 20 | 21 | Right paren: \) 22 | 23 | Greater-than: \> 24 | 25 | Hash: \# 26 | 27 | Period: \. 28 | 29 | Bang: \! 30 | 31 | Plus: \+ 32 | 33 | Minus: \- 34 | 35 | 36 | 37 | These should not, because they occur within a code block: 38 | 39 | Backslash: \\ 40 | 41 | Backtick: \` 42 | 43 | Asterisk: \* 44 | 45 | Underscore: \_ 46 | 47 | Left brace: \{ 48 | 49 | Right brace: \} 50 | 51 | Left bracket: \[ 52 | 53 | Right bracket: \] 54 | 55 | Left paren: \( 56 | 57 | Right paren: \) 58 | 59 | Greater-than: \> 60 | 61 | Hash: \# 62 | 63 | Period: \. 64 | 65 | Bang: \! 66 | 67 | Plus: \+ 68 | 69 | Minus: \- 70 | 71 | 72 | Nor should these, which occur in code spans: 73 | 74 | Backslash: `\\` 75 | 76 | Backtick: `` \` `` 77 | 78 | Asterisk: `\*` 79 | 80 | Underscore: `\_` 81 | 82 | Left brace: `\{` 83 | 84 | Right brace: `\}` 85 | 86 | Left bracket: `\[` 87 | 88 | Right bracket: `\]` 89 | 90 | Left paren: `\(` 91 | 92 | Right paren: `\)` 93 | 94 | Greater-than: `\>` 95 | 96 | Hash: `\#` 97 | 98 | Period: `\.` 99 | 100 | Bang: `\!` 101 | 102 | Plus: `\+` 103 | 104 | Minus: `\-` 105 | 106 | 107 | These should get escaped, even though they're matching pairs for 108 | other Markdown constructs: 109 | 110 | \*asterisks\* 111 | 112 | \_underscores\_ 113 | 114 | \`backticks\` 115 | 116 | This is a code span with a literal backslash-backtick sequence: `` \` `` 117 | 118 | This is a tag with unescaped backticks bar. 119 | 120 | This is a tag with backslashes bar. 121 | -------------------------------------------------------------------------------- /test/original/backslash_escapes.html: -------------------------------------------------------------------------------- 1 |

These should all get escaped:

2 | 3 |

Backslash: \

4 | 5 |

Backtick: `

6 | 7 |

Asterisk: *

8 | 9 |

Underscore: _

10 | 11 |

Left brace: {

12 | 13 |

Right brace: }

14 | 15 |

Left bracket: [

16 | 17 |

Right bracket: ]

18 | 19 |

Left paren: (

20 | 21 |

Right paren: )

22 | 23 |

Greater-than: >

24 | 25 |

Hash: #

26 | 27 |

Period: .

28 | 29 |

Bang: !

30 | 31 |

Plus: +

32 | 33 |

Minus: -

34 | 35 |

These should not, because they occur within a code block:

36 | 37 |
Backslash: \\
 38 | 
 39 | Backtick: \`
 40 | 
 41 | Asterisk: \*
 42 | 
 43 | Underscore: \_
 44 | 
 45 | Left brace: \{
 46 | 
 47 | Right brace: \}
 48 | 
 49 | Left bracket: \[
 50 | 
 51 | Right bracket: \]
 52 | 
 53 | Left paren: \(
 54 | 
 55 | Right paren: \)
 56 | 
 57 | Greater-than: \>
 58 | 
 59 | Hash: \#
 60 | 
 61 | Period: \.
 62 | 
 63 | Bang: \!
 64 | 
 65 | Plus: \+
 66 | 
 67 | Minus: \-
 68 | 
69 | 70 |

Nor should these, which occur in code spans:

71 | 72 |

Backslash: \\

73 | 74 |

Backtick: \`

75 | 76 |

Asterisk: \*

77 | 78 |

Underscore: \_

79 | 80 |

Left brace: \{

81 | 82 |

Right brace: \}

83 | 84 |

Left bracket: \[

85 | 86 |

Right bracket: \]

87 | 88 |

Left paren: \(

89 | 90 |

Right paren: \)

91 | 92 |

Greater-than: \>

93 | 94 |

Hash: \#

95 | 96 |

Period: \.

97 | 98 |

Bang: \!

99 | 100 |

Plus: \+

101 | 102 |

Minus: \-

103 | 104 | 105 |

These should get escaped, even though they're matching pairs for 106 | other Markdown constructs:

107 | 108 |

*asterisks*

109 | 110 |

_underscores_

111 | 112 |

`backticks`

113 | 114 |

This is a code span with a literal backslash-backtick sequence: \`

115 | 116 |

This is a tag with unescaped backticks bar.

117 | 118 |

This is a tag with backslashes bar.

119 | -------------------------------------------------------------------------------- /man/marked.1: -------------------------------------------------------------------------------- 1 | .ds q \N'34' 2 | .TH marked 1 "2014-01-31" "v0.3.1" "marked.js" 3 | 4 | .SH NAME 5 | marked \- a javascript markdown parser 6 | 7 | .SH SYNOPSIS 8 | .B marked 9 | [\-o \fI\fP] [\-i \fI\fP] [\-\-help] 10 | [\-\-tokens] [\-\-pedantic] [\-\-gfm] 11 | [\-\-breaks] [\-\-tables] [\-\-sanitize] 12 | [\-\-smart\-lists] [\-\-lang\-prefix \fI\fP] 13 | [\-\-no\-etc...] [\-\-silent] [\fIfilename\fP] 14 | 15 | .SH DESCRIPTION 16 | .B marked 17 | is a full-featured javascript markdown parser, built for speed. It also includes 18 | multiple GFM features. 19 | 20 | .SH EXAMPLES 21 | .TP 22 | cat in.md | marked > out.html 23 | .TP 24 | echo "hello *world*" | marked 25 | .TP 26 | marked \-o out.html in.md \-\-gfm 27 | .TP 28 | marked \-\-output="hello world.html" \-i in.md \-\-no-breaks 29 | 30 | .SH OPTIONS 31 | .TP 32 | .BI \-o,\ \-\-output\ [\fIoutput\fP] 33 | Specify file output. If none is specified, write to stdout. 34 | .TP 35 | .BI \-i,\ \-\-input\ [\fIinput\fP] 36 | Specify file input, otherwise use last argument as input file. If no input file 37 | is specified, read from stdin. 38 | .TP 39 | .BI \-t,\ \-\-tokens 40 | Output a token stream instead of html. 41 | .TP 42 | .BI \-\-pedantic 43 | Conform to obscure parts of markdown.pl as much as possible. Don't fix original 44 | markdown bugs. 45 | .TP 46 | .BI \-\-gfm 47 | Enable github flavored markdown. 48 | .TP 49 | .BI \-\-breaks 50 | Enable GFM line breaks. Only works with the gfm option. 51 | .TP 52 | .BI \-\-tables 53 | Enable GFM tables. Only works with the gfm option. 54 | .TP 55 | .BI \-\-sanitize 56 | Sanitize output. Ignore any HTML input. 57 | .TP 58 | .BI \-\-smart\-lists 59 | Use smarter list behavior than the original markdown. 60 | .TP 61 | .BI \-\-lang\-prefix\ [\fIprefix\fP] 62 | Set the prefix for code block classes. 63 | .TP 64 | .BI \-\-mangle 65 | Mangle email addresses. 66 | .TP 67 | .BI \-\-no\-sanitize,\ \-no-etc... 68 | The inverse of any of the marked options above. 69 | .TP 70 | .BI \-\-silent 71 | Silence error output. 72 | .TP 73 | .BI \-h,\ \-\-help 74 | Display help information. 75 | 76 | .SH CONFIGURATION 77 | For configuring and running programmatically. 78 | 79 | .B Example 80 | 81 | require('marked')('*foo*', { gfm: true }); 82 | 83 | .SH BUGS 84 | Please report any bugs to https://github.com/chjj/marked. 85 | 86 | .SH LICENSE 87 | Copyright (c) 2011-2014, Christopher Jeffrey (MIT License). 88 | 89 | .SH "SEE ALSO" 90 | .BR markdown(1), 91 | .BR node.js(1) 92 | -------------------------------------------------------------------------------- /man/marked.1.txt: -------------------------------------------------------------------------------- 1 | marked(1) marked.js marked(1) 2 | 3 | 4 | 5 | NAME 6 | marked - a javascript markdown parser 7 | 8 | 9 | SYNOPSIS 10 | marked [-o ] [-i ] [--help] [--tokens] [--pedantic] 11 | [--gfm] [--breaks] [--tables] [--sanitize] [--smart-lists] [--lang-pre‐ 12 | fix ] [--no-etc...] [--silent] [filename] 13 | 14 | 15 | DESCRIPTION 16 | marked is a full-featured javascript markdown parser, built for speed. 17 | It also includes multiple GFM features. 18 | 19 | 20 | EXAMPLES 21 | cat in.md | marked > out.html 22 | 23 | echo "hello *world*" | marked 24 | 25 | marked -o out.html in.md --gfm 26 | 27 | marked --output="hello world.html" -i in.md --no-breaks 28 | 29 | 30 | OPTIONS 31 | -o, --output [output] 32 | Specify file output. If none is specified, write to stdout. 33 | 34 | -i, --input [input] 35 | Specify file input, otherwise use last argument as input file. 36 | If no input file is specified, read from stdin. 37 | 38 | -t, --tokens 39 | Output a token stream instead of html. 40 | 41 | --pedantic 42 | Conform to obscure parts of markdown.pl as much as possible. 43 | Don't fix original markdown bugs. 44 | 45 | --gfm Enable github flavored markdown. 46 | 47 | --breaks 48 | Enable GFM line breaks. Only works with the gfm option. 49 | 50 | --tables 51 | Enable GFM tables. Only works with the gfm option. 52 | 53 | --sanitize 54 | Sanitize output. Ignore any HTML input. 55 | 56 | --smart-lists 57 | Use smarter list behavior than the original markdown. 58 | 59 | --lang-prefix [prefix] 60 | Set the prefix for code block classes. 61 | 62 | --mangle 63 | Mangle email addresses. 64 | 65 | --no-sanitize, -no-etc... 66 | The inverse of any of the marked options above. 67 | 68 | --silent 69 | Silence error output. 70 | 71 | -h, --help 72 | Display help information. 73 | 74 | 75 | CONFIGURATION 76 | For configuring and running programmatically. 77 | 78 | Example 79 | 80 | require('marked')('*foo*', { gfm: true }); 81 | 82 | 83 | BUGS 84 | Please report any bugs to https://github.com/chjj/marked. 85 | 86 | 87 | LICENSE 88 | Copyright (c) 2011-2014, Christopher Jeffrey (MIT License). 89 | 90 | 91 | SEE ALSO 92 | markdown(1), node.js(1) 93 | 94 | 95 | 96 | v0.3.1 2014-01-31 marked(1) 97 | -------------------------------------------------------------------------------- /test/original/ordered_and_unordered_lists.html: -------------------------------------------------------------------------------- 1 |

Unordered

2 | 3 |

Asterisks tight:

4 | 5 |
    6 |
  • asterisk 1
  • 7 |
  • asterisk 2
  • 8 |
  • asterisk 3
  • 9 |
10 | 11 |

Asterisks loose:

12 | 13 |
    14 |
  • asterisk 1

  • 15 |
  • asterisk 2

  • 16 |
  • asterisk 3

  • 17 |
18 | 19 |
20 | 21 |

Pluses tight:

22 | 23 |
    24 |
  • Plus 1
  • 25 |
  • Plus 2
  • 26 |
  • Plus 3
  • 27 |
28 | 29 |

Pluses loose:

30 | 31 |
    32 |
  • Plus 1

  • 33 |
  • Plus 2

  • 34 |
  • Plus 3

  • 35 |
36 | 37 |
38 | 39 |

Minuses tight:

40 | 41 |
    42 |
  • Minus 1
  • 43 |
  • Minus 2
  • 44 |
  • Minus 3
  • 45 |
46 | 47 |

Minuses loose:

48 | 49 |
    50 |
  • Minus 1

  • 51 |
  • Minus 2

  • 52 |
  • Minus 3

  • 53 |
54 | 55 |

Ordered

56 | 57 |

Tight:

58 | 59 |
    60 |
  1. First
  2. 61 |
  3. Second
  4. 62 |
  5. Third
  6. 63 |
64 | 65 |

and:

66 | 67 |
    68 |
  1. One
  2. 69 |
  3. Two
  4. 70 |
  5. Three
  6. 71 |
72 | 73 |

Loose using tabs:

74 | 75 |
    76 |
  1. First

  2. 77 |
  3. Second

  4. 78 |
  5. Third

  6. 79 |
80 | 81 |

and using spaces:

82 | 83 |
    84 |
  1. One

  2. 85 |
  3. Two

  4. 86 |
  5. Three

  6. 87 |
88 | 89 |

Multiple paragraphs:

90 | 91 |
    92 |
  1. Item 1, graf one.

    93 | 94 |

    Item 2. graf two. The quick brown fox jumped over the lazy dog's 95 | back.

  2. 96 |
  3. Item 2.

  4. 97 |
  5. Item 3.

  6. 98 |
99 | 100 |

Nested

101 | 102 |
    103 |
  • Tab 104 |
      105 |
    • Tab 106 |
        107 |
      • Tab
      • 108 |
    • 109 |
  • 110 |
111 | 112 |

Here's another:

113 | 114 |
    115 |
  1. First
  2. 116 |
  3. Second: 117 |
      118 |
    • Fee
    • 119 |
    • Fie
    • 120 |
    • Foe
    • 121 |
  4. 122 |
  5. Third
  6. 123 |
124 | 125 |

Same thing but with paragraphs:

126 | 127 |
    128 |
  1. First

  2. 129 |
  3. Second:

    130 | 131 |
      132 |
    • Fee
    • 133 |
    • Fie
    • 134 |
    • Foe
    • 135 |
  4. 136 |
  5. Third

  6. 137 |
138 | 139 | 140 |

This was an error in Markdown 1.0.1:

141 | 142 |
    143 |
  • this

    144 | 145 |
    • sub
    146 | 147 |

    that

  • 148 |
149 | -------------------------------------------------------------------------------- /bin/marked: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Marked CLI 5 | * Copyright (c) 2011-2013, Christopher Jeffrey (MIT License) 6 | */ 7 | 8 | var fs = require('fs') 9 | , util = require('util') 10 | , marked = require('../'); 11 | 12 | /** 13 | * Man Page 14 | */ 15 | 16 | function help() { 17 | var spawn = require('child_process').spawn; 18 | 19 | var options = { 20 | cwd: process.cwd(), 21 | env: process.env, 22 | setsid: false, 23 | customFds: [0, 1, 2] 24 | }; 25 | 26 | spawn('man', [__dirname + '/../man/marked.1'], options) 27 | .on('error', function(err) { 28 | fs.readFile(__dirname + '/../man/marked.1.txt', 'utf8', function(err, data) { 29 | if (err) throw err; 30 | console.log(data); 31 | }); 32 | }); 33 | } 34 | 35 | /** 36 | * Main 37 | */ 38 | 39 | function main(argv, callback) { 40 | var files = [] 41 | , options = {} 42 | , input 43 | , output 44 | , arg 45 | , tokens 46 | , opt; 47 | 48 | function getarg() { 49 | var arg = argv.shift(); 50 | 51 | if (arg.indexOf('--') === 0) { 52 | // e.g. --opt 53 | arg = arg.split('='); 54 | if (arg.length > 1) { 55 | // e.g. --opt=val 56 | argv.unshift(arg.slice(1).join('=')); 57 | } 58 | arg = arg[0]; 59 | } else if (arg[0] === '-') { 60 | if (arg.length > 2) { 61 | // e.g. -abc 62 | argv = arg.substring(1).split('').map(function(ch) { 63 | return '-' + ch; 64 | }).concat(argv); 65 | arg = argv.shift(); 66 | } else { 67 | // e.g. -a 68 | } 69 | } else { 70 | // e.g. foo 71 | } 72 | 73 | return arg; 74 | } 75 | 76 | while (argv.length) { 77 | arg = getarg(); 78 | switch (arg) { 79 | case '--test': 80 | return require('../test').main(process.argv.slice()); 81 | case '-o': 82 | case '--output': 83 | output = argv.shift(); 84 | break; 85 | case '-i': 86 | case '--input': 87 | input = argv.shift(); 88 | break; 89 | case '-t': 90 | case '--tokens': 91 | tokens = true; 92 | break; 93 | case '-h': 94 | case '--help': 95 | return help(); 96 | default: 97 | if (arg.indexOf('--') === 0) { 98 | opt = camelize(arg.replace(/^--(no-)?/, '')); 99 | if (!marked.defaults.hasOwnProperty(opt)) { 100 | continue; 101 | } 102 | if (arg.indexOf('--no-') === 0) { 103 | options[opt] = typeof marked.defaults[opt] !== 'boolean' 104 | ? null 105 | : false; 106 | } else { 107 | options[opt] = typeof marked.defaults[opt] !== 'boolean' 108 | ? argv.shift() 109 | : true; 110 | } 111 | } else { 112 | files.push(arg); 113 | } 114 | break; 115 | } 116 | } 117 | 118 | function getData(callback) { 119 | if (!input) { 120 | if (files.length <= 2) { 121 | return getStdin(callback); 122 | } 123 | input = files.pop(); 124 | } 125 | return fs.readFile(input, 'utf8', callback); 126 | } 127 | 128 | return getData(function(err, data) { 129 | if (err) return callback(err); 130 | 131 | data = tokens 132 | ? JSON.stringify(marked.lexer(data, options), null, 2) 133 | : marked(data, options); 134 | 135 | if (!output) { 136 | process.stdout.write(data + '\n'); 137 | return callback(); 138 | } 139 | 140 | return fs.writeFile(output, data, callback); 141 | }); 142 | } 143 | 144 | /** 145 | * Helpers 146 | */ 147 | 148 | function getStdin(callback) { 149 | var stdin = process.stdin 150 | , buff = ''; 151 | 152 | stdin.setEncoding('utf8'); 153 | 154 | stdin.on('data', function(data) { 155 | buff += data; 156 | }); 157 | 158 | stdin.on('error', function(err) { 159 | return callback(err); 160 | }); 161 | 162 | stdin.on('end', function() { 163 | return callback(null, buff); 164 | }); 165 | 166 | try { 167 | stdin.resume(); 168 | } catch (e) { 169 | callback(e); 170 | } 171 | } 172 | 173 | function camelize(text) { 174 | return text.replace(/(\w)-(\w)/g, function(_, a, b) { 175 | return a + b.toUpperCase(); 176 | }); 177 | } 178 | 179 | /** 180 | * Expose / Entry Point 181 | */ 182 | 183 | if (!module.parent) { 184 | process.title = 'marked'; 185 | main(process.argv.slice(), function(err, code) { 186 | if (err) throw err; 187 | return process.exit(code || 0); 188 | }); 189 | } else { 190 | module.exports = main; 191 | } 192 | -------------------------------------------------------------------------------- /doc/broken.md: -------------------------------------------------------------------------------- 1 | # Markdown is broken 2 | 3 | I have a lot of scraps of markdown engine oddities that I've collected over the 4 | years. What you see below is slightly messy, but it's what I've managed to 5 | cobble together to illustrate the differences between markdown engines, and 6 | why, if there ever is a markdown specification, it has to be absolutely 7 | thorough. There are a lot more of these little differences I have documented 8 | elsewhere. I know I will find them lingering on my disk one day, but until 9 | then, I'll continue to add whatever strange nonsensical things I find. 10 | 11 | Some of these examples may only mention a particular engine compared to marked. 12 | However, the examples with markdown.pl could easily be swapped out for 13 | discount, upskirt, or markdown.js, and you would very easily see even more 14 | inconsistencies. 15 | 16 | A lot of this was written when I was very unsatisfied with the inconsistencies 17 | between markdown engines. Please excuse the frustration noticeable in my 18 | writing. 19 | 20 | ## Examples of markdown's "stupid" list parsing 21 | 22 | ``` 23 | $ markdown.pl 24 | 25 | * item1 26 | 27 | * item2 28 | 29 | text 30 | ^D 31 |
    32 |
  • item1

    33 | 34 |
      35 |
    • item2
    • 36 |
    37 | 38 |

    text

  • 39 |

40 | ``` 41 | 42 | 43 | ``` 44 | $ marked 45 | * item1 46 | 47 | * item2 48 | 49 | text 50 | ^D 51 |
    52 |
  • item1

    53 |
      54 |
    • item2
    • 55 |
    56 |

    text

    57 |
  • 58 |
59 | ``` 60 | 61 | Which looks correct to you? 62 | 63 | - - - 64 | 65 | ``` 66 | $ markdown.pl 67 | * hello 68 | > world 69 | ^D 70 |

    71 |
  • hello

    72 | 73 |
    74 |

    world

  • 75 |

76 | 77 | ``` 78 | 79 | ``` 80 | $ marked 81 | * hello 82 | > world 83 | ^D 84 |
    85 |
  • hello
    86 |

    world

    87 |
    88 |
  • 89 |
90 | ``` 91 | 92 | Again, which looks correct to you? 93 | 94 | - - - 95 | 96 | EXAMPLE: 97 | 98 | ``` 99 | $ markdown.pl 100 | * hello 101 | * world 102 | * hi 103 | code 104 | ^D 105 |
    106 |
  • hello 107 |
      108 |
    • world
    • 109 |
    • hi 110 | code
    • 111 |
  • 112 |
113 | ``` 114 | 115 | The code isn't a code block even though it's after the bullet margin. I know, 116 | lets give it two more spaces, effectively making it 8 spaces past the bullet. 117 | 118 | ``` 119 | $ markdown.pl 120 | * hello 121 | * world 122 | * hi 123 | code 124 | ^D 125 |
    126 |
  • hello 127 |
      128 |
    • world
    • 129 |
    • hi 130 | code
    • 131 |
  • 132 |
133 | ``` 134 | 135 | And, it's still not a code block. Did you also notice that the 3rd item isn't 136 | even its own list? Markdown screws that up too because of its indentation 137 | unaware parsing. 138 | 139 | - - - 140 | 141 | Let's look at some more examples of markdown's list parsing: 142 | 143 | ``` 144 | $ markdown.pl 145 | 146 | * item1 147 | 148 | * item2 149 | 150 | text 151 | ^D 152 |
    153 |
  • item1

    154 | 155 |
      156 |
    • item2
    • 157 |
    158 | 159 |

    text

  • 160 |

161 | ``` 162 | 163 | Misnested tags. 164 | 165 | 166 | ``` 167 | $ marked 168 | * item1 169 | 170 | * item2 171 | 172 | text 173 | ^D 174 |
    175 |
  • item1

    176 |
      177 |
    • item2
    • 178 |
    179 |

    text

    180 |
  • 181 |
182 | ``` 183 | 184 | Which looks correct to you? 185 | 186 | - - - 187 | 188 | ``` 189 | $ markdown.pl 190 | * hello 191 | > world 192 | ^D 193 |

    194 |
  • hello

    195 | 196 |
    197 |

    world

  • 198 |

199 | 200 | ``` 201 | 202 | More misnested tags. 203 | 204 | 205 | ``` 206 | $ marked 207 | * hello 208 | > world 209 | ^D 210 |
    211 |
  • hello
    212 |

    world

    213 |
    214 |
  • 215 |
216 | ``` 217 | 218 | Again, which looks correct to you? 219 | 220 | - - - 221 | 222 | # Why quality matters - Part 2 223 | 224 | ``` bash 225 | $ markdown.pl 226 | * hello 227 | > world 228 | ^D 229 |

    230 |
  • hello

    231 | 232 |
    233 |

    world

  • 234 |

235 | 236 | ``` 237 | 238 | ``` bash 239 | $ sundown # upskirt 240 | * hello 241 | > world 242 | ^D 243 |
    244 |
  • hello 245 | > world
  • 246 |
247 | ``` 248 | 249 | ``` bash 250 | $ marked 251 | * hello 252 | > world 253 | ^D 254 |
  • hello

    world

255 | ``` 256 | 257 | Which looks correct to you? 258 | 259 | - - - 260 | 261 | See: https://github.com/evilstreak/markdown-js/issues/23 262 | 263 | ``` bash 264 | $ markdown.pl # upskirt/markdown.js/discount 265 | * hello 266 | var a = 1; 267 | * world 268 | ^D 269 |
    270 |
  • hello 271 | var a = 1;
  • 272 |
  • world
  • 273 |
274 | ``` 275 | 276 | ``` bash 277 | $ marked 278 | * hello 279 | var a = 1; 280 | * world 281 | ^D 282 |
  • hello 283 |
    code>var a = 1;
  • 284 |
  • world
285 | ``` 286 | 287 | Which looks more reasonable? Why shouldn't code blocks be able to appear in 288 | list items in a sane way? 289 | 290 | - - - 291 | 292 | ``` bash 293 | $ markdown.js 294 |
hello
295 | 296 | hello 297 | ^D 298 |

<div>hello</div>

299 | 300 |

<span>hello</span>

301 | ``` 302 | 303 | ``` bash 304 | $ marked 305 |
hello
306 | 307 | hello 308 | ^D 309 |
hello
310 | 311 | 312 |

hello 313 |

314 | ``` 315 | 316 | - - - 317 | 318 | See: https://github.com/evilstreak/markdown-js/issues/27 319 | 320 | ``` bash 321 | $ markdown.js 322 | [![an image](/image)](/link) 323 | ^D 324 |

![an image

325 | ``` 326 | 327 | ``` bash 328 | $ marked 329 | [![an image](/image)](/link) 330 | ^D 331 |

an image 332 |

333 | ``` 334 | 335 | - - - 336 | 337 | See: https://github.com/evilstreak/markdown-js/issues/24 338 | 339 | ``` bash 340 | $ markdown.js 341 | > a 342 | 343 | > b 344 | 345 | > c 346 | ^D 347 |

a

bundefined> c

348 | ``` 349 | 350 | ``` bash 351 | $ marked 352 | > a 353 | 354 | > b 355 | 356 | > c 357 | ^D 358 |

a 359 | 360 |

361 |

b 362 | 363 |

364 |

c 365 |

366 | ``` 367 | 368 | - - - 369 | 370 | ``` bash 371 | $ markdown.pl 372 | * hello 373 | * world 374 | how 375 | 376 | are 377 | you 378 | 379 | * today 380 | * hi 381 | ^D 382 |
    383 |
  • hello

    384 | 385 |
      386 |
    • world 387 | how
    • 388 |
    389 | 390 |

    are 391 | you

    392 | 393 |
      394 |
    • today
    • 395 |
  • 396 |
  • hi
  • 397 |
398 | ``` 399 | 400 | ``` bash 401 | $ marked 402 | * hello 403 | * world 404 | how 405 | 406 | are 407 | you 408 | 409 | * today 410 | * hi 411 | ^D 412 |
    413 |
  • hello

    414 |
      415 |
    • world 416 | how

      417 |

      are 418 | you

      419 |
    • 420 |
    • today

      421 |
    • 422 |
    423 |
  • 424 |
  • hi
  • 425 |
426 | ``` 427 | -------------------------------------------------------------------------------- /test/original/markdown_documentation_basics.md: -------------------------------------------------------------------------------- 1 | Markdown: Basics 2 | ================ 3 | 4 | 11 | 12 | 13 | Getting the Gist of Markdown's Formatting Syntax 14 | ------------------------------------------------ 15 | 16 | This page offers a brief overview of what it's like to use Markdown. 17 | The [syntax page] [s] provides complete, detailed documentation for 18 | every feature, but Markdown should be very easy to pick up simply by 19 | looking at a few examples of it in action. The examples on this page 20 | are written in a before/after style, showing example syntax and the 21 | HTML output produced by Markdown. 22 | 23 | It's also helpful to simply try Markdown out; the [Dingus] [d] is a 24 | web application that allows you type your own Markdown-formatted text 25 | and translate it to XHTML. 26 | 27 | **Note:** This document is itself written using Markdown; you 28 | can [see the source for it by adding '.text' to the URL] [src]. 29 | 30 | [s]: /projects/markdown/syntax "Markdown Syntax" 31 | [d]: /projects/markdown/dingus "Markdown Dingus" 32 | [src]: /projects/markdown/basics.text 33 | 34 | 35 | ## Paragraphs, Headers, Blockquotes ## 36 | 37 | A paragraph is simply one or more consecutive lines of text, separated 38 | by one or more blank lines. (A blank line is any line that looks like a 39 | blank line -- a line containing nothing spaces or tabs is considered 40 | blank.) Normal paragraphs should not be intended with spaces or tabs. 41 | 42 | Markdown offers two styles of headers: *Setext* and *atx*. 43 | Setext-style headers for `

` and `

` are created by 44 | "underlining" with equal signs (`=`) and hyphens (`-`), respectively. 45 | To create an atx-style header, you put 1-6 hash marks (`#`) at the 46 | beginning of the line -- the number of hashes equals the resulting 47 | HTML header level. 48 | 49 | Blockquotes are indicated using email-style '`>`' angle brackets. 50 | 51 | Markdown: 52 | 53 | A First Level Header 54 | ==================== 55 | 56 | A Second Level Header 57 | --------------------- 58 | 59 | Now is the time for all good men to come to 60 | the aid of their country. This is just a 61 | regular paragraph. 62 | 63 | The quick brown fox jumped over the lazy 64 | dog's back. 65 | 66 | ### Header 3 67 | 68 | > This is a blockquote. 69 | > 70 | > This is the second paragraph in the blockquote. 71 | > 72 | > ## This is an H2 in a blockquote 73 | 74 | 75 | Output: 76 | 77 |

A First Level Header

78 | 79 |

A Second Level Header

80 | 81 |

Now is the time for all good men to come to 82 | the aid of their country. This is just a 83 | regular paragraph.

84 | 85 |

The quick brown fox jumped over the lazy 86 | dog's back.

87 | 88 |

Header 3

89 | 90 |
91 |

This is a blockquote.

92 | 93 |

This is the second paragraph in the blockquote.

94 | 95 |

This is an H2 in a blockquote

96 |
97 | 98 | 99 | 100 | ### Phrase Emphasis ### 101 | 102 | Markdown uses asterisks and underscores to indicate spans of emphasis. 103 | 104 | Markdown: 105 | 106 | Some of these words *are emphasized*. 107 | Some of these words _are emphasized also_. 108 | 109 | Use two asterisks for **strong emphasis**. 110 | Or, if you prefer, __use two underscores instead__. 111 | 112 | Output: 113 | 114 |

Some of these words are emphasized. 115 | Some of these words are emphasized also.

116 | 117 |

Use two asterisks for strong emphasis. 118 | Or, if you prefer, use two underscores instead.

119 | 120 | 121 | 122 | ## Lists ## 123 | 124 | Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`, 125 | `+`, and `-`) as list markers. These three markers are 126 | interchangable; this: 127 | 128 | * Candy. 129 | * Gum. 130 | * Booze. 131 | 132 | this: 133 | 134 | + Candy. 135 | + Gum. 136 | + Booze. 137 | 138 | and this: 139 | 140 | - Candy. 141 | - Gum. 142 | - Booze. 143 | 144 | all produce the same output: 145 | 146 |
    147 |
  • Candy.
  • 148 |
  • Gum.
  • 149 |
  • Booze.
  • 150 |
151 | 152 | Ordered (numbered) lists use regular numbers, followed by periods, as 153 | list markers: 154 | 155 | 1. Red 156 | 2. Green 157 | 3. Blue 158 | 159 | Output: 160 | 161 |
    162 |
  1. Red
  2. 163 |
  3. Green
  4. 164 |
  5. Blue
  6. 165 |
166 | 167 | If you put blank lines between items, you'll get `

` tags for the 168 | list item text. You can create multi-paragraph list items by indenting 169 | the paragraphs by 4 spaces or 1 tab: 170 | 171 | * A list item. 172 | 173 | With multiple paragraphs. 174 | 175 | * Another item in the list. 176 | 177 | Output: 178 | 179 |

    180 |
  • A list item.

    181 |

    With multiple paragraphs.

  • 182 |
  • Another item in the list.

  • 183 |
184 | 185 | 186 | 187 | ### Links ### 188 | 189 | Markdown supports two styles for creating links: *inline* and 190 | *reference*. With both styles, you use square brackets to delimit the 191 | text you want to turn into a link. 192 | 193 | Inline-style links use parentheses immediately after the link text. 194 | For example: 195 | 196 | This is an [example link](http://example.com/). 197 | 198 | Output: 199 | 200 |

This is an 201 | example link.

202 | 203 | Optionally, you may include a title attribute in the parentheses: 204 | 205 | This is an [example link](http://example.com/ "With a Title"). 206 | 207 | Output: 208 | 209 |

This is an 210 | example link.

211 | 212 | Reference-style links allow you to refer to your links by names, which 213 | you define elsewhere in your document: 214 | 215 | I get 10 times more traffic from [Google][1] than from 216 | [Yahoo][2] or [MSN][3]. 217 | 218 | [1]: http://google.com/ "Google" 219 | [2]: http://search.yahoo.com/ "Yahoo Search" 220 | [3]: http://search.msn.com/ "MSN Search" 221 | 222 | Output: 223 | 224 |

I get 10 times more traffic from Google than from Yahoo or MSN.

228 | 229 | The title attribute is optional. Link names may contain letters, 230 | numbers and spaces, but are *not* case sensitive: 231 | 232 | I start my morning with a cup of coffee and 233 | [The New York Times][NY Times]. 234 | 235 | [ny times]: http://www.nytimes.com/ 236 | 237 | Output: 238 | 239 |

I start my morning with a cup of coffee and 240 | The New York Times.

241 | 242 | 243 | ### Images ### 244 | 245 | Image syntax is very much like link syntax. 246 | 247 | Inline (titles are optional): 248 | 249 | ![alt text](/path/to/img.jpg "Title") 250 | 251 | Reference-style: 252 | 253 | ![alt text][id] 254 | 255 | [id]: /path/to/img.jpg "Title" 256 | 257 | Both of the above examples produce the same output: 258 | 259 | alt text 260 | 261 | 262 | 263 | ### Code ### 264 | 265 | In a regular paragraph, you can create code span by wrapping text in 266 | backtick quotes. Any ampersands (`&`) and angle brackets (`<` or 267 | `>`) will automatically be translated into HTML entities. This makes 268 | it easy to use Markdown to write about HTML example code: 269 | 270 | I strongly recommend against using any `` tags. 271 | 272 | I wish SmartyPants used named entities like `—` 273 | instead of decimal-encoded entites like `—`. 274 | 275 | Output: 276 | 277 |

I strongly recommend against using any 278 | <blink> tags.

279 | 280 |

I wish SmartyPants used named entities like 281 | &mdash; instead of decimal-encoded 282 | entites like &#8212;.

283 | 284 | 285 | To specify an entire block of pre-formatted code, indent every line of 286 | the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`, 287 | and `>` characters will be escaped automatically. 288 | 289 | Markdown: 290 | 291 | If you want your page to validate under XHTML 1.0 Strict, 292 | you've got to put paragraph tags in your blockquotes: 293 | 294 |
295 |

For example.

296 |
297 | 298 | Output: 299 | 300 |

If you want your page to validate under XHTML 1.0 Strict, 301 | you've got to put paragraph tags in your blockquotes:

302 | 303 |
<blockquote>
304 |         <p>For example.</p>
305 |     </blockquote>
306 |     
307 | -------------------------------------------------------------------------------- /test/original/markdown_documentation_basics.html: -------------------------------------------------------------------------------- 1 |

Markdown: Basics

2 | 3 | 10 | 11 |

Getting the Gist of Markdown's Formatting Syntax

12 | 13 |

This page offers a brief overview of what it's like to use Markdown. 14 | The syntax page provides complete, detailed documentation for 15 | every feature, but Markdown should be very easy to pick up simply by 16 | looking at a few examples of it in action. The examples on this page 17 | are written in a before/after style, showing example syntax and the 18 | HTML output produced by Markdown.

19 | 20 |

It's also helpful to simply try Markdown out; the Dingus is a 21 | web application that allows you type your own Markdown-formatted text 22 | and translate it to XHTML.

23 | 24 |

Note: This document is itself written using Markdown; you 25 | can see the source for it by adding '.text' to the URL.

26 | 27 |

Paragraphs, Headers, Blockquotes

28 | 29 |

A paragraph is simply one or more consecutive lines of text, separated 30 | by one or more blank lines. (A blank line is any line that looks like a 31 | blank line -- a line containing nothing spaces or tabs is considered 32 | blank.) Normal paragraphs should not be intended with spaces or tabs.

33 | 34 |

Markdown offers two styles of headers: Setext and atx. 35 | Setext-style headers for <h1> and <h2> are created by 36 | "underlining" with equal signs (=) and hyphens (-), respectively. 37 | To create an atx-style header, you put 1-6 hash marks (#) at the 38 | beginning of the line -- the number of hashes equals the resulting 39 | HTML header level.

40 | 41 |

Blockquotes are indicated using email-style '>' angle brackets.

42 | 43 |

Markdown:

44 | 45 |
A First Level Header
 46 | ====================
 47 | 
 48 | A Second Level Header
 49 | ---------------------
 50 | 
 51 | Now is the time for all good men to come to
 52 | the aid of their country. This is just a
 53 | regular paragraph.
 54 | 
 55 | The quick brown fox jumped over the lazy
 56 | dog's back.
 57 | 
 58 | ### Header 3
 59 | 
 60 | > This is a blockquote.
 61 | > 
 62 | > This is the second paragraph in the blockquote.
 63 | >
 64 | > ## This is an H2 in a blockquote
 65 | 
66 | 67 |

Output:

68 | 69 |
<h1>A First Level Header</h1>
 70 | 
 71 | <h2>A Second Level Header</h2>
 72 | 
 73 | <p>Now is the time for all good men to come to
 74 | the aid of their country. This is just a
 75 | regular paragraph.</p>
 76 | 
 77 | <p>The quick brown fox jumped over the lazy
 78 | dog's back.</p>
 79 | 
 80 | <h3>Header 3</h3>
 81 | 
 82 | <blockquote>
 83 |     <p>This is a blockquote.</p>
 84 | 
 85 |     <p>This is the second paragraph in the blockquote.</p>
 86 | 
 87 |     <h2>This is an H2 in a blockquote</h2>
 88 | </blockquote>
 89 | 
90 | 91 |

Phrase Emphasis

92 | 93 |

Markdown uses asterisks and underscores to indicate spans of emphasis.

94 | 95 |

Markdown:

96 | 97 |
Some of these words *are emphasized*.
 98 | Some of these words _are emphasized also_.
 99 | 
100 | Use two asterisks for **strong emphasis**.
101 | Or, if you prefer, __use two underscores instead__.
102 | 
103 | 104 |

Output:

105 | 106 |
<p>Some of these words <em>are emphasized</em>.
107 | Some of these words <em>are emphasized also</em>.</p>
108 | 
109 | <p>Use two asterisks for <strong>strong emphasis</strong>.
110 | Or, if you prefer, <strong>use two underscores instead</strong>.</p>
111 | 
112 | 113 |

Lists

114 | 115 |

Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, 116 | +, and -) as list markers. These three markers are 117 | interchangable; this:

118 | 119 |
*   Candy.
120 | *   Gum.
121 | *   Booze.
122 | 
123 | 124 |

this:

125 | 126 |
+   Candy.
127 | +   Gum.
128 | +   Booze.
129 | 
130 | 131 |

and this:

132 | 133 |
-   Candy.
134 | -   Gum.
135 | -   Booze.
136 | 
137 | 138 |

all produce the same output:

139 | 140 |
<ul>
141 | <li>Candy.</li>
142 | <li>Gum.</li>
143 | <li>Booze.</li>
144 | </ul>
145 | 
146 | 147 |

Ordered (numbered) lists use regular numbers, followed by periods, as 148 | list markers:

149 | 150 |
1.  Red
151 | 2.  Green
152 | 3.  Blue
153 | 
154 | 155 |

Output:

156 | 157 |
<ol>
158 | <li>Red</li>
159 | <li>Green</li>
160 | <li>Blue</li>
161 | </ol>
162 | 
163 | 164 |

If you put blank lines between items, you'll get <p> tags for the 165 | list item text. You can create multi-paragraph list items by indenting 166 | the paragraphs by 4 spaces or 1 tab:

167 | 168 |
*   A list item.
169 | 
170 |     With multiple paragraphs.
171 | 
172 | *   Another item in the list.
173 | 
174 | 175 |

Output:

176 | 177 |
<ul>
178 | <li><p>A list item.</p>
179 | <p>With multiple paragraphs.</p></li>
180 | <li><p>Another item in the list.</p></li>
181 | </ul>
182 | 
183 | 184 |

Links

185 | 186 |

Markdown supports two styles for creating links: inline and 187 | reference. With both styles, you use square brackets to delimit the 188 | text you want to turn into a link.

189 | 190 |

Inline-style links use parentheses immediately after the link text. 191 | For example:

192 | 193 |
This is an [example link](http://example.com/).
194 | 
195 | 196 |

Output:

197 | 198 |
<p>This is an <a href="http://example.com/">
199 | example link</a>.</p>
200 | 
201 | 202 |

Optionally, you may include a title attribute in the parentheses:

203 | 204 |
This is an [example link](http://example.com/ "With a Title").
205 | 
206 | 207 |

Output:

208 | 209 |
<p>This is an <a href="http://example.com/" title="With a Title">
210 | example link</a>.</p>
211 | 
212 | 213 |

Reference-style links allow you to refer to your links by names, which 214 | you define elsewhere in your document:

215 | 216 |
I get 10 times more traffic from [Google][1] than from
217 | [Yahoo][2] or [MSN][3].
218 | 
219 | [1]: http://google.com/        "Google"
220 | [2]: http://search.yahoo.com/  "Yahoo Search"
221 | [3]: http://search.msn.com/    "MSN Search"
222 | 
223 | 224 |

Output:

225 | 226 |
<p>I get 10 times more traffic from <a href="http://google.com/"
227 | title="Google">Google</a> than from <a href="http://search.yahoo.com/"
228 | title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/"
229 | title="MSN Search">MSN</a>.</p>
230 | 
231 | 232 |

The title attribute is optional. Link names may contain letters, 233 | numbers and spaces, but are not case sensitive:

234 | 235 |
I start my morning with a cup of coffee and
236 | [The New York Times][NY Times].
237 | 
238 | [ny times]: http://www.nytimes.com/
239 | 
240 | 241 |

Output:

242 | 243 |
<p>I start my morning with a cup of coffee and
244 | <a href="http://www.nytimes.com/">The New York Times</a>.</p>
245 | 
246 | 247 |

Images

248 | 249 |

Image syntax is very much like link syntax.

250 | 251 |

Inline (titles are optional):

252 | 253 |
![alt text](/path/to/img.jpg "Title")
254 | 
255 | 256 |

Reference-style:

257 | 258 |
![alt text][id]
259 | 
260 | [id]: /path/to/img.jpg "Title"
261 | 
262 | 263 |

Both of the above examples produce the same output:

264 | 265 |
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
266 | 
267 | 268 |

Code

269 | 270 |

In a regular paragraph, you can create code span by wrapping text in 271 | backtick quotes. Any ampersands (&) and angle brackets (< or 272 | >) will automatically be translated into HTML entities. This makes 273 | it easy to use Markdown to write about HTML example code:

274 | 275 |
I strongly recommend against using any `<blink>` tags.
276 | 
277 | I wish SmartyPants used named entities like `&mdash;`
278 | instead of decimal-encoded entites like `&#8212;`.
279 | 
280 | 281 |

Output:

282 | 283 |
<p>I strongly recommend against using any
284 | <code>&lt;blink&gt;</code> tags.</p>
285 | 
286 | <p>I wish SmartyPants used named entities like
287 | <code>&amp;mdash;</code> instead of decimal-encoded
288 | entites like <code>&amp;#8212;</code>.</p>
289 | 
290 | 291 |

To specify an entire block of pre-formatted code, indent every line of 292 | the block by 4 spaces or 1 tab. Just like with code spans, &, <, 293 | and > characters will be escaped automatically.

294 | 295 |

Markdown:

296 | 297 |
If you want your page to validate under XHTML 1.0 Strict,
298 | you've got to put paragraph tags in your blockquotes:
299 | 
300 |     <blockquote>
301 |         <p>For example.</p>
302 |     </blockquote>
303 | 
304 | 305 |

Output:

306 | 307 |
<p>If you want your page to validate under XHTML 1.0 Strict,
308 | you've got to put paragraph tags in your blockquotes:</p>
309 | 
310 | <pre><code>&lt;blockquote&gt;
311 |     &lt;p&gt;For example.&lt;/p&gt;
312 | &lt;/blockquote&gt;
313 | </code></pre>
314 | 
315 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # marked 2 | 3 | > A full-featured markdown parser and compiler, written in JavaScript. Built 4 | > for speed. 5 | 6 | [![NPM version](https://badge.fury.io/js/marked.svg)][badge] 7 | 8 | ## Install 9 | 10 | ``` bash 11 | npm install marked --save 12 | ``` 13 | 14 | or if you want to use the `marked` CLI tool (not necessary when using npm run-scripts): 15 | 16 | ``` bash 17 | npm install -g marked 18 | ``` 19 | 20 | ## Usage 21 | 22 | Minimal usage: 23 | 24 | ```js 25 | var marked = require('marked'); 26 | console.log(marked('I am using __markdown__.')); 27 | // Outputs:

I am using markdown.

28 | ``` 29 | 30 | Example setting options with default values: 31 | 32 | ```js 33 | var marked = require('marked'); 34 | marked.setOptions({ 35 | renderer: new marked.Renderer(), 36 | gfm: true, 37 | tables: true, 38 | breaks: false, 39 | pedantic: false, 40 | sanitize: false, 41 | smartLists: true, 42 | smartypants: false 43 | }); 44 | 45 | console.log(marked('I am using __markdown__.')); 46 | ``` 47 | 48 | ### Browser 49 | 50 | ```html 51 | 52 | 53 | 54 | 55 | Marked in the browser 56 | 57 | 58 | 59 |
60 | 64 | 65 | 66 | ``` 67 | 68 | ## marked(markdownString [,options] [,callback]) 69 | 70 | ### markdownString 71 | 72 | Type: `string` 73 | 74 | String of markdown source to be compiled. 75 | 76 | ### options 77 | 78 | Type: `object` 79 | 80 | Hash of options. Can also be set using the `marked.setOptions` method as seen 81 | above. 82 | 83 | ### callback 84 | 85 | Type: `function` 86 | 87 | Function called when the `markdownString` has been fully parsed when using 88 | async highlighting. If the `options` argument is omitted, this can be used as 89 | the second argument. 90 | 91 | ## Options 92 | 93 | ### highlight 94 | 95 | Type: `function` 96 | 97 | A function to highlight code blocks. The first example below uses async highlighting with 98 | [node-pygmentize-bundled][pygmentize], and the second is a synchronous example using 99 | [highlight.js][highlight]: 100 | 101 | ```js 102 | var marked = require('marked'); 103 | 104 | var markdownString = '```js\n console.log("hello"); \n```'; 105 | 106 | // Async highlighting with pygmentize-bundled 107 | marked.setOptions({ 108 | highlight: function (code, lang, callback) { 109 | require('pygmentize-bundled')({ lang: lang, format: 'html' }, code, function (err, result) { 110 | callback(err, result.toString()); 111 | }); 112 | } 113 | }); 114 | 115 | // Using async version of marked 116 | marked(markdownString, function (err, content) { 117 | if (err) throw err; 118 | console.log(content); 119 | }); 120 | 121 | // Synchronous highlighting with highlight.js 122 | marked.setOptions({ 123 | highlight: function (code) { 124 | return require('highlight.js').highlightAuto(code).value; 125 | } 126 | }); 127 | 128 | console.log(marked(markdownString)); 129 | ``` 130 | 131 | #### highlight arguments 132 | 133 | `code` 134 | 135 | Type: `string` 136 | 137 | The section of code to pass to the highlighter. 138 | 139 | `lang` 140 | 141 | Type: `string` 142 | 143 | The programming language specified in the code block. 144 | 145 | `callback` 146 | 147 | Type: `function` 148 | 149 | The callback function to call when using an async highlighter. 150 | 151 | ### renderer 152 | 153 | Type: `object` 154 | Default: `new Renderer()` 155 | 156 | An object containing functions to render tokens to HTML. 157 | 158 | #### Overriding renderer methods 159 | 160 | The renderer option allows you to render tokens in a custom manner. Here is an 161 | example of overriding the default heading token rendering by adding an embedded anchor tag like on GitHub: 162 | 163 | ```javascript 164 | var marked = require('marked'); 165 | var renderer = new marked.Renderer(); 166 | 167 | renderer.heading = function (text, level) { 168 | var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-'); 169 | 170 | return '' + 175 | text + ''; 176 | }; 177 | 178 | console.log(marked('# heading+', { renderer: renderer })); 179 | ``` 180 | This code will output the following HTML: 181 | ```html 182 |

183 | 184 | 185 | 186 | heading+ 187 |

188 | ``` 189 | 190 | #### Block level renderer methods 191 | 192 | - code(*string* code, *string* language) 193 | - blockquote(*string* quote) 194 | - html(*string* html) 195 | - heading(*string* text, *number* level) 196 | - hr() 197 | - list(*string* body, *boolean* ordered) 198 | - listitem(*string* text) 199 | - paragraph(*string* text) 200 | - table(*string* header, *string* body) 201 | - tablerow(*string* content) 202 | - tablecell(*string* content, *object* flags) 203 | 204 | `flags` has the following properties: 205 | 206 | ```js 207 | { 208 | header: true || false, 209 | align: 'center' || 'left' || 'right' 210 | } 211 | ``` 212 | 213 | #### Inline level renderer methods 214 | 215 | - strong(*string* text) 216 | - em(*string* text) 217 | - codespan(*string* code) 218 | - br() 219 | - del(*string* text) 220 | - link(*string* href, *string* title, *string* text) 221 | - image(*string* href, *string* title, *string* text) 222 | - text(*string* text) 223 | 224 | ### gfm 225 | 226 | Type: `boolean` 227 | Default: `true` 228 | 229 | Enable [GitHub flavored markdown][gfm]. 230 | 231 | ### tables 232 | 233 | Type: `boolean` 234 | Default: `true` 235 | 236 | Enable GFM [tables][tables]. 237 | This option requires the `gfm` option to be true. 238 | 239 | ### breaks 240 | 241 | Type: `boolean` 242 | Default: `false` 243 | 244 | Enable GFM [line breaks][breaks]. 245 | This option requires the `gfm` option to be true. 246 | 247 | ### pedantic 248 | 249 | Type: `boolean` 250 | Default: `false` 251 | 252 | Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of 253 | the original markdown bugs or poor behavior. 254 | 255 | ### sanitize 256 | 257 | Type: `boolean` 258 | Default: `false` 259 | 260 | Sanitize the output. Ignore any HTML that has been input. 261 | 262 | ### smartLists 263 | 264 | Type: `boolean` 265 | Default: `true` 266 | 267 | Use smarter list behavior than the original markdown. May eventually be 268 | default with the old behavior moved into `pedantic`. 269 | 270 | ### smartypants 271 | 272 | Type: `boolean` 273 | Default: `false` 274 | 275 | Use "smart" typographic punctuation for things like quotes and dashes. 276 | 277 | ## Access to lexer and parser 278 | 279 | You also have direct access to the lexer and parser if you so desire. 280 | 281 | ``` js 282 | var tokens = marked.lexer(text, options); 283 | console.log(marked.parser(tokens)); 284 | ``` 285 | 286 | ``` js 287 | var lexer = new marked.Lexer(options); 288 | var tokens = lexer.lex(text); 289 | console.log(tokens); 290 | console.log(lexer.rules); 291 | ``` 292 | 293 | ## CLI 294 | 295 | ``` bash 296 | $ marked -o hello.html 297 | hello world 298 | ^D 299 | $ cat hello.html 300 |

hello world

301 | ``` 302 | 303 | ## Philosophy behind marked 304 | 305 | The point of marked was to create a markdown compiler where it was possible to 306 | frequently parse huge chunks of markdown without having to worry about 307 | caching the compiled output somehow...or blocking for an unnecessarily long time. 308 | 309 | marked is very concise and still implements all markdown features. It is also 310 | now fully compatible with the client-side. 311 | 312 | marked more or less passes the official markdown test suite in its 313 | entirety. This is important because a surprising number of markdown compilers 314 | cannot pass more than a few tests. It was very difficult to get marked as 315 | compliant as it is. It could have cut corners in several areas for the sake 316 | of performance, but did not in order to be exactly what you expect in terms 317 | of a markdown rendering. In fact, this is why marked could be considered at a 318 | disadvantage in the benchmarks. 319 | 320 | Along with implementing every markdown feature, marked also implements [GFM 321 | features][gfmf]. 322 | 323 | ## Benchmarks 324 | 325 | node v8.9.4 326 | 327 | ``` bash 328 | $ npm run bench 329 | marked completed in 3408ms. 330 | marked (gfm) completed in 3465ms. 331 | marked (pedantic) completed in 3032ms. 332 | showdown (reuse converter) completed in 21444ms. 333 | showdown (new converter) completed in 23058ms. 334 | markdown-it completed in 3364ms. 335 | markdown.js completed in 12090ms. 336 | ``` 337 | 338 | ### Pro level 339 | 340 | You also have direct access to the lexer and parser if you so desire. 341 | 342 | ``` js 343 | var tokens = marked.lexer(text, options); 344 | console.log(marked.parser(tokens)); 345 | ``` 346 | 347 | ``` js 348 | var lexer = new marked.Lexer(options); 349 | var tokens = lexer.lex(text); 350 | console.log(tokens); 351 | console.log(lexer.rules); 352 | ``` 353 | 354 | ``` bash 355 | $ node 356 | > require('marked').lexer('> i am using marked.') 357 | [ { type: 'blockquote_start' }, 358 | { type: 'paragraph', 359 | text: 'i am using marked.' }, 360 | { type: 'blockquote_end' }, 361 | links: {} ] 362 | ``` 363 | 364 | ## Running Tests & Contributing 365 | 366 | If you want to submit a pull request, make sure your changes pass the test 367 | suite. If you're adding a new feature, be sure to add your own test. 368 | 369 | The marked test suite is set up slightly strangely: `test/new` is for all tests 370 | that are not part of the original markdown.pl test suite (this is where your 371 | test should go if you make one). `test/original` is only for the original 372 | markdown.pl tests. 373 | 374 | In other words, if you have a test to add, add it to `test/new/`. If your test 375 | uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you 376 | can add [front-matter](https://www.npmjs.com/package/front-matter) to the top of 377 | your `.md` file 378 | 379 | ``` yml 380 | --- 381 | gfm: false 382 | --- 383 | ``` 384 | 385 | To run the tests: 386 | 387 | ``` bash 388 | npm run test 389 | ``` 390 | 391 | ### Contribution and License Agreement 392 | 393 | If you contribute code to this project, you are implicitly allowing your code 394 | to be distributed under the MIT license. You are also implicitly verifying that 395 | all code is your original work. `` 396 | 397 | ## License 398 | 399 | Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License) 400 | 401 | See LICENSE for more info. 402 | 403 | [gfm]: https://help.github.com/articles/github-flavored-markdown 404 | [gfmf]: http://github.github.com/github-flavored-markdown/ 405 | [pygmentize]: https://github.com/rvagg/node-pygmentize-bundled 406 | [highlight]: https://github.com/isagalaev/highlight.js 407 | [badge]: http://badge.fury.io/js/marked 408 | [tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables 409 | [breaks]: https://help.github.com/articles/github-flavored-markdown#newlines 410 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * marked tests 5 | * Copyright (c) 2011-2013, Christopher Jeffrey. (MIT Licensed) 6 | * https://github.com/chjj/marked 7 | */ 8 | 9 | /** 10 | * Modules 11 | */ 12 | 13 | var fs = require('fs') 14 | , path = require('path') 15 | , fm = require('front-matter') 16 | , g2r = require('glob-to-regexp') 17 | , marked = require('../'); 18 | 19 | /** 20 | * Load Tests 21 | */ 22 | 23 | function load(options) { 24 | var dir = __dirname + '/compiled_tests' 25 | , files = {} 26 | , list 27 | , file 28 | , name 29 | , content 30 | , regex 31 | , skip 32 | , glob = g2r(options.glob || "*", { extended: true }) 33 | , i 34 | , j 35 | , l; 36 | 37 | list = fs 38 | .readdirSync(dir) 39 | .filter(function(file) { 40 | return path.extname(file) !== '.html'; 41 | }) 42 | .sort(); 43 | 44 | l = list.length; 45 | 46 | for (i = 0; i < l; i++) { 47 | name = path.basename(list[i], ".md"); 48 | if (glob.test(name)) { 49 | file = path.join(dir, list[i]); 50 | content = fm(fs.readFileSync(file, 'utf8')); 51 | 52 | files[name] = { 53 | options: content.attributes, 54 | text: content.body, 55 | html: fs.readFileSync(file.replace(/[^.]+$/, 'html'), 'utf8') 56 | }; 57 | } 58 | } 59 | 60 | if (options.bench || options.time) { 61 | if (!options.glob) { 62 | // Change certain tests to allow 63 | // comparison to older benchmark times. 64 | fs.readdirSync(__dirname + '/new').forEach(function(name) { 65 | if (path.extname(name) === '.html') return; 66 | if (name === 'main.md') return; 67 | delete files[name]; 68 | }); 69 | } 70 | 71 | if (files['backslash_escapes.md']) { 72 | files['backslash_escapes.md'] = { 73 | text: 'hello world \\[how](are you) today' 74 | }; 75 | } 76 | 77 | if (files['main.md']) { 78 | files['main.md'].text = files['main.md'].text.replace('* * *\n\n', ''); 79 | } 80 | } 81 | 82 | return files; 83 | } 84 | 85 | /** 86 | * Test Runner 87 | */ 88 | 89 | function runTests(engine, options) { 90 | if (typeof engine !== 'function') { 91 | options = engine; 92 | engine = null; 93 | } 94 | 95 | var engine = engine || marked 96 | , options = options || {} 97 | , files = options.files || load(options) 98 | , complete = 0 99 | , failed = 0 100 | , failures = [] 101 | , keys = Object.keys(files) 102 | , i = 0 103 | , len = keys.length 104 | , filename 105 | , file 106 | , opts 107 | , text 108 | , html 109 | , j 110 | , l; 111 | 112 | if (options.marked) { 113 | marked.setOptions(options.marked); 114 | } 115 | 116 | main: 117 | for (; i < len; i++) { 118 | filename = keys[i]; 119 | file = files[filename]; 120 | opts = Object.keys(file.options); 121 | 122 | if (marked._original) { 123 | marked.defaults = marked._original; 124 | delete marked._original; 125 | } 126 | 127 | if (opts.length) { 128 | marked._original = marked.defaults; 129 | marked.defaults = {}; 130 | Object.keys(marked._original).forEach(function(key) { 131 | marked.defaults[key] = marked._original[key]; 132 | }); 133 | opts.forEach(function(key) { 134 | if (marked.defaults.hasOwnProperty(key)) { 135 | marked.defaults[key] = file.options[key]; 136 | } 137 | }); 138 | } 139 | 140 | try { 141 | text = engine(file.text).replace(/\s/g, ''); 142 | html = file.html.replace(/\s/g, ''); 143 | } catch (e) { 144 | console.log('%s failed.', filename); 145 | throw e; 146 | } 147 | 148 | j = 0; 149 | l = html.length; 150 | 151 | for (; j < l; j++) { 152 | if (text[j] !== html[j]) { 153 | failed++; 154 | failures.push(filename); 155 | 156 | text = text.substring( 157 | Math.max(j - 30, 0), 158 | Math.min(j + 30, text.length)); 159 | 160 | html = html.substring( 161 | Math.max(j - 30, 0), 162 | Math.min(j + 30, html.length)); 163 | 164 | console.log( 165 | '\n#%d. %s failed at offset %d. Near: "%s".\n', 166 | i + 1, filename, j, text); 167 | 168 | console.log('\nGot:\n%s\n', text.trim() || text); 169 | console.log('\nExpected:\n%s\n', html.trim() || html); 170 | 171 | if (options.stop) { 172 | break main; 173 | } 174 | 175 | continue main; 176 | } 177 | } 178 | 179 | complete++; 180 | console.log('#%d. %s completed.', i + 1, filename); 181 | } 182 | 183 | console.log('%d/%d tests completed successfully.', complete, len); 184 | if (failed) console.log('%d/%d tests failed.', failed, len); 185 | 186 | return !failed; 187 | } 188 | 189 | /** 190 | * Benchmark a function 191 | */ 192 | 193 | function bench(name, files, func) { 194 | var start = Date.now() 195 | , times = 1000 196 | , keys = Object.keys(files) 197 | , i 198 | , l = keys.length 199 | , filename 200 | , file; 201 | 202 | while (times--) { 203 | for (i = 0; i < l; i++) { 204 | filename = keys[i]; 205 | file = files[filename]; 206 | func(file.text); 207 | } 208 | } 209 | 210 | console.log('%s completed in %dms.', name, Date.now() - start); 211 | } 212 | 213 | /** 214 | * Benchmark all engines 215 | */ 216 | 217 | function runBench(options) { 218 | var options = options || {} 219 | , files = load(options); 220 | 221 | // Non-GFM, Non-pedantic 222 | marked.setOptions({ 223 | gfm: false, 224 | tables: false, 225 | breaks: false, 226 | pedantic: false, 227 | sanitize: false, 228 | smartLists: false 229 | }); 230 | if (options.marked) { 231 | marked.setOptions(options.marked); 232 | } 233 | bench('marked', files, marked); 234 | 235 | // GFM 236 | marked.setOptions({ 237 | gfm: true, 238 | tables: false, 239 | breaks: false, 240 | pedantic: false, 241 | sanitize: false, 242 | smartLists: false 243 | }); 244 | if (options.marked) { 245 | marked.setOptions(options.marked); 246 | } 247 | bench('marked (gfm)', files, marked); 248 | 249 | // Pedantic 250 | marked.setOptions({ 251 | gfm: false, 252 | tables: false, 253 | breaks: false, 254 | pedantic: true, 255 | sanitize: false, 256 | smartLists: false 257 | }); 258 | if (options.marked) { 259 | marked.setOptions(options.marked); 260 | } 261 | bench('marked (pedantic)', files, marked); 262 | 263 | // showdown 264 | try { 265 | bench('showdown (reuse converter)', files, (function() { 266 | var Showdown = require('showdown'); 267 | var convert = new Showdown.Converter(); 268 | return function(text) { 269 | return convert.makeHtml(text); 270 | }; 271 | })()); 272 | bench('showdown (new converter)', files, (function() { 273 | var Showdown = require('showdown'); 274 | return function(text) { 275 | var convert = new Showdown.Converter(); 276 | return convert.makeHtml(text); 277 | }; 278 | })()); 279 | } catch (e) { 280 | console.log('Could not bench showdown. (Error: %s)', e.message); 281 | } 282 | 283 | // markdown-it 284 | try { 285 | bench('markdown-it', files, (function() { 286 | var MarkdownIt = require('markdown-it'); 287 | var md = new MarkdownIt(); 288 | return function(text) { 289 | return md.render(text); 290 | }; 291 | })()); 292 | } catch (e) { 293 | console.log('Could not bench markdown-it. (Error: %s)', e.message); 294 | } 295 | 296 | // markdown.js 297 | try { 298 | bench('markdown.js', files, (function() { 299 | var markdown = require('markdown').markdown; 300 | return function(text) { 301 | return markdown.toHTML(text); 302 | }; 303 | })()); 304 | } catch (e) { 305 | console.log('Could not bench markdown.js. (Error: %s)', e.message); 306 | } 307 | 308 | return true; 309 | } 310 | 311 | /** 312 | * A simple one-time benchmark 313 | */ 314 | 315 | function time(options) { 316 | var options = options || {} 317 | , files = load(options); 318 | if (options.marked) { 319 | marked.setOptions(options.marked); 320 | } 321 | bench('marked', files, marked); 322 | 323 | return true; 324 | } 325 | 326 | /** 327 | * Markdown Test Suite Fixer 328 | * This function is responsible for "fixing" 329 | * the markdown test suite. There are 330 | * certain aspects of the suite that 331 | * are strange or might make tests 332 | * fail for reasons unrelated to 333 | * conformance. 334 | */ 335 | 336 | function fix() { 337 | ['compiled_tests', 'original', 'new'].forEach(function(dir) { 338 | try { 339 | fs.mkdirSync(path.resolve(__dirname, dir), 0o755); 340 | } catch (e) { 341 | ; 342 | } 343 | }); 344 | 345 | // rm -rf tests 346 | fs.readdirSync(path.resolve(__dirname, 'compiled_tests')).forEach(function(file) { 347 | fs.unlinkSync(path.resolve(__dirname, 'compiled_tests', file)); 348 | }); 349 | 350 | // cp -r original tests 351 | fs.readdirSync(path.resolve(__dirname, 'original')).forEach(function(file) { 352 | var text = fs.readFileSync(path.resolve(__dirname, 'original', file)); 353 | 354 | if (file === 'hard_wrapped_paragraphs_with_list_like_lines.md') { 355 | text = '---\ngfm: false\n---\n' + text; 356 | } 357 | 358 | fs.writeFileSync(path.resolve(__dirname, 'compiled_tests', file), text); 359 | }); 360 | 361 | // node fix.js 362 | var dir = __dirname + '/compiled_tests'; 363 | 364 | fs.readdirSync(dir).filter(function(file) { 365 | return path.extname(file) === '.html'; 366 | }).forEach(function(file) { 367 | var file = path.join(dir, file) 368 | , html = fs.readFileSync(file, 'utf8'); 369 | 370 | // fix unencoded quotes 371 | html = html 372 | .replace(/='([^\n']*)'(?=[^<>\n]*>)/g, '=&__APOS__;$1&__APOS__;') 373 | .replace(/="([^\n"]*)"(?=[^<>\n]*>)/g, '=&__QUOT__;$1&__QUOT__;') 374 | .replace(/"/g, '"') 375 | .replace(/'/g, ''') 376 | .replace(/&__QUOT__;/g, '"') 377 | .replace(/&__APOS__;/g, '\''); 378 | 379 | // add heading id's 380 | html = html.replace(/<(h[1-6])>([^<]+)<\/\1>/g, function(s, h, text) { 381 | var id = text 382 | .replace(/'/g, '\'') 383 | .replace(/"/g, '"') 384 | .replace(/>/g, '>') 385 | .replace(/</g, '<') 386 | .replace(/&/g, '&'); 387 | 388 | id = id.toLowerCase().replace(/[^\w]+/g, '-'); 389 | 390 | return '<' + h + ' id="' + id + '">' + text + ''; 391 | }); 392 | 393 | fs.writeFileSync(file, html); 394 | }); 395 | 396 | // turn
into
397 | fs.readdirSync(dir).forEach(function(file) { 398 | var file = path.join(dir, file) 399 | , text = fs.readFileSync(file, 'utf8'); 400 | 401 | text = text.replace(/(<|<)hr\s*\/(>|>)/g, '$1hr$2'); 402 | 403 | fs.writeFileSync(file, text); 404 | }); 405 | 406 | // markdown does some strange things. 407 | // it does not encode naked `>`, marked does. 408 | (function() { 409 | var file = dir + '/amps_and_angles_encoding.html'; 410 | var html = fs.readFileSync(file, 'utf8') 411 | .replace('6 > 5.', '6 > 5.'); 412 | 413 | fs.writeFileSync(file, html); 414 | })(); 415 | 416 | // cp new/* tests/ 417 | fs.readdirSync(path.resolve(__dirname, 'new')).forEach(function(file) { 418 | fs.writeFileSync(path.resolve(__dirname, 'compiled_tests', file), 419 | fs.readFileSync(path.resolve(__dirname, 'new', file))); 420 | }); 421 | } 422 | 423 | /** 424 | * Argument Parsing 425 | */ 426 | 427 | function parseArg(argv) { 428 | var argv = process.argv.slice(2) 429 | , options = {} 430 | , opt = "" 431 | , orphans = [] 432 | , arg; 433 | 434 | function getarg() { 435 | var arg = argv.shift(); 436 | 437 | if (arg.indexOf('--') === 0) { 438 | // e.g. --opt 439 | arg = arg.split('='); 440 | if (arg.length > 1) { 441 | // e.g. --opt=val 442 | argv.unshift(arg.slice(1).join('=')); 443 | } 444 | arg = arg[0]; 445 | } else if (arg[0] === '-') { 446 | if (arg.length > 2) { 447 | // e.g. -abc 448 | argv = arg.substring(1).split('').map(function(ch) { 449 | return '-' + ch; 450 | }).concat(argv); 451 | arg = argv.shift(); 452 | } else { 453 | // e.g. -a 454 | } 455 | } else { 456 | // e.g. foo 457 | } 458 | 459 | return arg; 460 | } 461 | 462 | while (argv.length) { 463 | arg = getarg(); 464 | switch (arg) { 465 | case '-f': 466 | case '--fix': 467 | case 'fix': 468 | if (options.fix !== false) { 469 | options.fix = true; 470 | } 471 | break; 472 | case '--no-fix': 473 | case 'no-fix': 474 | options.fix = false; 475 | break; 476 | case '-b': 477 | case '--bench': 478 | options.bench = true; 479 | break; 480 | case '-s': 481 | case '--stop': 482 | options.stop = true; 483 | break; 484 | case '-t': 485 | case '--time': 486 | options.time = true; 487 | break; 488 | case '--glob': 489 | arg = argv.shift(); 490 | options.glob = arg.replace(/^=/, ''); 491 | break; 492 | default: 493 | if (arg.indexOf('--') === 0) { 494 | opt = camelize(arg.replace(/^--(no-)?/, '')); 495 | if (!marked.defaults.hasOwnProperty(opt)) { 496 | continue; 497 | } 498 | options.marked = options.marked || {}; 499 | if (arg.indexOf('--no-') === 0) { 500 | options.marked[opt] = typeof marked.defaults[opt] !== 'boolean' 501 | ? null 502 | : false; 503 | } else { 504 | options.marked[opt] = typeof marked.defaults[opt] !== 'boolean' 505 | ? argv.shift() 506 | : true; 507 | } 508 | } else { 509 | orphans.push(arg); 510 | } 511 | break; 512 | } 513 | } 514 | 515 | return options; 516 | } 517 | 518 | /** 519 | * Helpers 520 | */ 521 | 522 | function camelize(text) { 523 | return text.replace(/(\w)-(\w)/g, function(_, a, b) { 524 | return a + b.toUpperCase(); 525 | }); 526 | } 527 | 528 | /** 529 | * Main 530 | */ 531 | 532 | function main(argv) { 533 | var opt = parseArg(); 534 | 535 | if (opt.fix !== false) { 536 | fix(); 537 | } 538 | 539 | if (opt.fix) { 540 | // only run fix 541 | return; 542 | } 543 | 544 | if (opt.bench) { 545 | return runBench(opt); 546 | } 547 | 548 | if (opt.time) { 549 | return time(opt); 550 | } 551 | 552 | return runTests(opt); 553 | } 554 | 555 | /** 556 | * Execute 557 | */ 558 | 559 | if (!module.parent) { 560 | process.title = 'marked'; 561 | process.exit(main(process.argv.slice()) ? 0 : 1); 562 | } else { 563 | exports = main; 564 | exports.main = main; 565 | exports.runTests = runTests; 566 | exports.runBench = runBench; 567 | exports.load = load; 568 | exports.bench = bench; 569 | module.exports = exports; 570 | } 571 | -------------------------------------------------------------------------------- /marked.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * marked - a markdown parser 3 | * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) 4 | * https://github.com/chjj/marked 5 | */ 6 | (function(){"use strict";function e(e){this.tokens=[],this.tokens.links={},this.options=e||p.defaults,this.rules=u.normal,this.options.gfm&&(this.options.tables?this.rules=u.tables:this.rules=u.gfm)}function t(e,t){if(this.options=t||p.defaults,this.links=e,this.rules=c.normal,this.renderer=this.options.renderer||new n,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.gfm?this.options.breaks?this.rules=c.breaks:this.rules=c.gfm:this.options.pedantic&&(this.rules=c.pedantic)}function n(e){this.options=e||{}}function r(e){this.tokens=[],this.token=null,this.options=e||p.defaults,this.options.renderer=this.options.renderer||new n,this.renderer=this.options.renderer,this.renderer.options=this.options}function s(e,t){return e.replace(t?/&/g:/&(?!#?\w+;)/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function i(e){return e.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,function(e,t){return t=t.toLowerCase(),"colon"===t?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""})}function l(e,t){return e=e.source,t=t||"",function n(r,s){return r?(s=s.source||s,s=s.replace(/(^|[^\[])\^/g,"$1"),e=e.replace(r,s),n):new RegExp(e,t)}}function o(e,t){return g[" "+e]||(/^[^:]+:\/*[^\/]*$/.test(e)?g[" "+e]=e+"/":g[" "+e]=e.replace(/[^\/]*$/,"")),e=g[" "+e],"//"===t.slice(0,2)?e.replace(/:[\s\S]*/,":")+t:"/"===t.charAt(0)?e.replace(/(:\/*[^\/]*)[\s\S]*/,"$1")+t:e+t}function h(){}function a(e){for(var t,n,r=1;rAn error occurred:

"+s(c.message+"",!0)+"
";throw c}}var u={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:h,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:h,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:h,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};u.bullet=/(?:[*+-]|\d+\.)/,u.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,u.item=l(u.item,"gm")(/bull/g,u.bullet)(),u.list=l(u.list)(/bull/g,u.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+u.def.source+")")(),u.blockquote=l(u.blockquote)("def",u.def)(),u._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",u.html=l(u.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/])*?>/)(/tag/g,u._tag)(),u.paragraph=l(u.paragraph)("hr",u.hr)("heading",u.heading)("lheading",u.lheading)("blockquote",u.blockquote)("tag","<"+u._tag)("def",u.def)(),u.normal=a({},u),u.gfm=a({},u.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/}),u.gfm.paragraph=l(u.paragraph)("(?!","(?!"+u.gfm.fences.source.replace("\\1","\\2")+"|"+u.list.source.replace("\\1","\\3")+"|")(),u.tables=a({},u.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/}),e.rules=u,e.lex=function(t,n){var r=new e(n);return r.lex(t)},e.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n"),this.token(e,!0)},e.prototype.token=function(e,t,n){for(var r,s,i,l,o,h,a,p,c,e=e.replace(/^ +$/gm,"");e;)if((i=this.rules.newline.exec(e))&&(e=e.substring(i[0].length),i[0].length>1&&this.tokens.push({type:"space"})),i=this.rules.code.exec(e))e=e.substring(i[0].length),i=i[0].replace(/^ {4}/gm,""),this.tokens.push({type:"code",text:this.options.pedantic?i:i.replace(/\n+$/,"")});else if(i=this.rules.fences.exec(e))e=e.substring(i[0].length),this.tokens.push({type:"code",lang:i[2],text:i[3]||""});else if(i=this.rules.heading.exec(e))e=e.substring(i[0].length),this.tokens.push({type:"heading",depth:i[1].length,text:i[2]});else if(t&&(i=this.rules.nptable.exec(e))){for(e=e.substring(i[0].length),h={type:"table",header:i[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:i[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:i[3].replace(/\n$/,"").split("\n")},p=0;p ?/gm,""),this.token(i,t,!0),this.tokens.push({type:"blockquote_end"});else if(i=this.rules.list.exec(e)){for(e=e.substring(i[0].length),l=i[2],this.tokens.push({type:"list_start",ordered:l.length>1}),i=i[0].match(this.rules.item),r=!1,c=i.length,p=0;p1&&o.length>1||(e=i.slice(p+1).join("\n")+e,p=c-1)),s=r||/\n\n(?!\s*$)/.test(h),p!==c-1&&(r="\n"===h.charAt(h.length-1),s||(s=r)),this.tokens.push({type:s?"loose_item_start":"list_item_start"}),this.token(h,!1,n),this.tokens.push({type:"list_item_end"});this.tokens.push({type:"list_end"})}else if(i=this.rules.html.exec(e))e=e.substring(i[0].length),this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:!this.options.sanitizer&&("pre"===i[1]||"script"===i[1]||"style"===i[1]),text:i[0]});else if(!n&&t&&(i=this.rules.def.exec(e)))e=e.substring(i[0].length),this.tokens.links[i[1].toLowerCase()]={href:i[2],title:i[3]};else if(t&&(i=this.rules.table.exec(e))){for(e=e.substring(i[0].length),h={type:"table",header:i[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:i[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:i[3].replace(/(?: *\| *)?\n$/,"").split("\n")},p=0;p])/,autolink:/^<([^ <>]+(@|:\/)[^ <>]+)>/,url:h,tag:/^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^<'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)([\s\S]*?[^`])\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:h,text:/^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/,c.link=l(c.link)("inside",c._inside)("href",c._href)(),c.reflink=l(c.reflink)("inside",c._inside)(),c.normal=a({},c),c.pedantic=a({},c.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/}),c.gfm=a({},c.normal,{escape:l(c.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:l(c.text)("]|","~]|")("|","|https?://|")()}),c.breaks=a({},c.gfm,{br:l(c.br)("{2,}","*")(),text:l(c.gfm.text)("{2,}","*")()}),t.rules=c,t.output=function(e,n,r){var s=new t(n,r);return s.output(e)},t.prototype.output=function(e){for(var t,n,r,i,l="";e;)if(i=this.rules.escape.exec(e))e=e.substring(i[0].length),l+=i[1];else if(i=this.rules.autolink.exec(e))e=e.substring(i[0].length),"@"===i[2]?(n=s(":"===i[1].charAt(6)?this.mangle(i[1].substring(7)):this.mangle(i[1])),r=this.mangle("mailto:")+n):(n=s(i[1]),r=n),l+=this.renderer.link(r,null,n);else if(this.inLink||!(i=this.rules.url.exec(e))){if(i=this.rules.tag.exec(e))!this.inLink&&/^/i.test(i[0])&&(this.inLink=!1),e=e.substring(i[0].length),l+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):s(i[0]):i[0];else if(i=this.rules.link.exec(e))e=e.substring(i[0].length),this.inLink=!0,l+=this.outputLink(i,{href:i[2],title:i[3]}),this.inLink=!1;else if((i=this.rules.reflink.exec(e))||(i=this.rules.nolink.exec(e))){if(e=e.substring(i[0].length),t=(i[2]||i[1]).replace(/\s+/g," "),t=this.links[t.toLowerCase()],!t||!t.href){l+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,l+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),l+=this.renderer.strong(this.output(i[2]||i[1]));else if(i=this.rules.em.exec(e))e=e.substring(i[0].length),l+=this.renderer.em(this.output(i[2]||i[1]));else if(i=this.rules.code.exec(e))e=e.substring(i[0].length),l+=this.renderer.codespan(s(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),l+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),l+=this.renderer.del(this.output(i[1]));else if(i=this.rules.text.exec(e))e=e.substring(i[0].length),l+=this.renderer.text(s(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else e=e.substring(i[0].length),n=s(i[1]),r=n,l+=this.renderer.link(r,null,n);return l},t.prototype.outputLink=function(e,t){var n=s(t.href),r=t.title?s(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,s(e[1]))},t.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014\/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014\/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},t.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;s.5&&(t="x"+t.toString(16)),n+="&#"+t+";";return n},n.prototype.code=function(e,t,n){if(this.options.highlight){var r=this.options.highlight(e,t);null!=r&&r!==e&&(n=!0,e=r)}return t?'
'+(n?e:s(e,!0))+"\n
\n":"
"+(n?e:s(e,!0))+"\n
"},n.prototype.blockquote=function(e){return"
\n"+e+"
\n"},n.prototype.html=function(e){return e},n.prototype.heading=function(e,t,n){return"'+e+"\n"},n.prototype.hr=function(){return this.options.xhtml?"
\n":"
\n"},n.prototype.list=function(e,t){var n=t?"ol":"ul";return"<"+n+">\n"+e+"\n"},n.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},n.prototype.paragraph=function(e){return"

    "+e+"

    \n"},n.prototype.table=function(e,t){return"\n\n"+e+"\n\n"+t+"\n
    \n"},n.prototype.tablerow=function(e){return"\n"+e+"\n"},n.prototype.tablecell=function(e,t){var n=t.header?"th":"td",r=t.align?"<"+n+' style="text-align:'+t.align+'">':"<"+n+">";return r+e+"\n"},n.prototype.strong=function(e){return""+e+""},n.prototype.em=function(e){return""+e+""},n.prototype.codespan=function(e){return""+e+""},n.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},n.prototype.del=function(e){return""+e+""},n.prototype.link=function(e,t,n){if(this.options.sanitize){try{var r=decodeURIComponent(i(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(s){return n}if(0===r.indexOf("javascript:")||0===r.indexOf("vbscript:")||0===r.indexOf("data:"))return n}this.options.baseUrl&&!f.test(e)&&(e=o(this.options.baseUrl,e));var l='
    "},n.prototype.image=function(e,t,n){this.options.baseUrl&&!f.test(e)&&(e=o(this.options.baseUrl,e));var r=''+n+'":">"},n.prototype.text=function(e){return e},r.parse=function(e,t,n){var s=new r(t,n);return s.parse(e)},r.prototype.parse=function(e){this.inline=new t(e.links,this.options,this.renderer),this.tokens=e.reverse();for(var n="";this.next();)n+=this.tok();return n},r.prototype.next=function(){return this.token=this.tokens.pop()},r.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},r.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},r.prototype.tok=function(){switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var e,t,n,r,s,i="",l="";for(n="",e=0;e 5 |
  • Main
  • 6 |
  • Basics
  • 7 |
  • Syntax
  • 8 |
  • License
  • 9 |
  • Dingus
  • 10 | 11 | 12 | 13 | * [Overview](#overview) 14 | * [Philosophy](#philosophy) 15 | * [Inline HTML](#html) 16 | * [Automatic Escaping for Special Characters](#autoescape) 17 | * [Block Elements](#block) 18 | * [Paragraphs and Line Breaks](#p) 19 | * [Headers](#header) 20 | * [Blockquotes](#blockquote) 21 | * [Lists](#list) 22 | * [Code Blocks](#precode) 23 | * [Horizontal Rules](#hr) 24 | * [Span Elements](#span) 25 | * [Links](#link) 26 | * [Emphasis](#em) 27 | * [Code](#code) 28 | * [Images](#img) 29 | * [Miscellaneous](#misc) 30 | * [Backslash Escapes](#backslash) 31 | * [Automatic Links](#autolink) 32 | 33 | 34 | **Note:** This document is itself written using Markdown; you 35 | can [see the source for it by adding '.text' to the URL][src]. 36 | 37 | [src]: /projects/markdown/syntax.text 38 | 39 | * * * 40 | 41 |

    Overview

    42 | 43 |

    Philosophy

    44 | 45 | Markdown is intended to be as easy-to-read and easy-to-write as is feasible. 46 | 47 | Readability, however, is emphasized above all else. A Markdown-formatted 48 | document should be publishable as-is, as plain text, without looking 49 | like it's been marked up with tags or formatting instructions. While 50 | Markdown's syntax has been influenced by several existing text-to-HTML 51 | filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4], 52 | [Grutatext] [5], and [EtText] [6] -- the single biggest source of 53 | inspiration for Markdown's syntax is the format of plain text email. 54 | 55 | [1]: http://docutils.sourceforge.net/mirror/setext.html 56 | [2]: http://www.aaronsw.com/2002/atx/ 57 | [3]: http://textism.com/tools/textile/ 58 | [4]: http://docutils.sourceforge.net/rst.html 59 | [5]: http://www.triptico.com/software/grutatxt.html 60 | [6]: http://ettext.taint.org/doc/ 61 | 62 | To this end, Markdown's syntax is comprised entirely of punctuation 63 | characters, which punctuation characters have been carefully chosen so 64 | as to look like what they mean. E.g., asterisks around a word actually 65 | look like \*emphasis\*. Markdown lists look like, well, lists. Even 66 | blockquotes look like quoted passages of text, assuming you've ever 67 | used email. 68 | 69 | 70 | 71 |

    Inline HTML

    72 | 73 | Markdown's syntax is intended for one purpose: to be used as a 74 | format for *writing* for the web. 75 | 76 | Markdown is not a replacement for HTML, or even close to it. Its 77 | syntax is very small, corresponding only to a very small subset of 78 | HTML tags. The idea is *not* to create a syntax that makes it easier 79 | to insert HTML tags. In my opinion, HTML tags are already easy to 80 | insert. The idea for Markdown is to make it easy to read, write, and 81 | edit prose. HTML is a *publishing* format; Markdown is a *writing* 82 | format. Thus, Markdown's formatting syntax only addresses issues that 83 | can be conveyed in plain text. 84 | 85 | For any markup that is not covered by Markdown's syntax, you simply 86 | use HTML itself. There's no need to preface it or delimit it to 87 | indicate that you're switching from Markdown to HTML; you just use 88 | the tags. 89 | 90 | The only restrictions are that block-level HTML elements -- e.g. `
    `, 91 | ``, `
    `, `

    `, etc. -- must be separated from surrounding 92 | content by blank lines, and the start and end tags of the block should 93 | not be indented with tabs or spaces. Markdown is smart enough not 94 | to add extra (unwanted) `

    ` tags around HTML block-level tags. 95 | 96 | For example, to add an HTML table to a Markdown article: 97 | 98 | This is a regular paragraph. 99 | 100 |

    101 | 102 | 103 | 104 |
    Foo
    105 | 106 | This is another regular paragraph. 107 | 108 | Note that Markdown formatting syntax is not processed within block-level 109 | HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an 110 | HTML block. 111 | 112 | Span-level HTML tags -- e.g. ``, ``, or `` -- can be 113 | used anywhere in a Markdown paragraph, list item, or header. If you 114 | want, you can even use HTML tags instead of Markdown formatting; e.g. if 115 | you'd prefer to use HTML `` or `` tags instead of Markdown's 116 | link or image syntax, go right ahead. 117 | 118 | Unlike block-level HTML tags, Markdown syntax *is* processed within 119 | span-level tags. 120 | 121 | 122 |

    Automatic Escaping for Special Characters

    123 | 124 | In HTML, there are two characters that demand special treatment: `<` 125 | and `&`. Left angle brackets are used to start tags; ampersands are 126 | used to denote HTML entities. If you want to use them as literal 127 | characters, you must escape them as entities, e.g. `<`, and 128 | `&`. 129 | 130 | Ampersands in particular are bedeviling for web writers. If you want to 131 | write about 'AT&T', you need to write '`AT&T`'. You even need to 132 | escape ampersands within URLs. Thus, if you want to link to: 133 | 134 | http://images.google.com/images?num=30&q=larry+bird 135 | 136 | you need to encode the URL as: 137 | 138 | http://images.google.com/images?num=30&q=larry+bird 139 | 140 | in your anchor tag `href` attribute. Needless to say, this is easy to 141 | forget, and is probably the single most common source of HTML validation 142 | errors in otherwise well-marked-up web sites. 143 | 144 | Markdown allows you to use these characters naturally, taking care of 145 | all the necessary escaping for you. If you use an ampersand as part of 146 | an HTML entity, it remains unchanged; otherwise it will be translated 147 | into `&`. 148 | 149 | So, if you want to include a copyright symbol in your article, you can write: 150 | 151 | © 152 | 153 | and Markdown will leave it alone. But if you write: 154 | 155 | AT&T 156 | 157 | Markdown will translate it to: 158 | 159 | AT&T 160 | 161 | Similarly, because Markdown supports [inline HTML](#html), if you use 162 | angle brackets as delimiters for HTML tags, Markdown will treat them as 163 | such. But if you write: 164 | 165 | 4 < 5 166 | 167 | Markdown will translate it to: 168 | 169 | 4 < 5 170 | 171 | However, inside Markdown code spans and blocks, angle brackets and 172 | ampersands are *always* encoded automatically. This makes it easy to use 173 | Markdown to write about HTML code. (As opposed to raw HTML, which is a 174 | terrible format for writing about HTML syntax, because every single `<` 175 | and `&` in your example code needs to be escaped.) 176 | 177 | 178 | * * * 179 | 180 | 181 |

    Block Elements

    182 | 183 | 184 |

    Paragraphs and Line Breaks

    185 | 186 | A paragraph is simply one or more consecutive lines of text, separated 187 | by one or more blank lines. (A blank line is any line that looks like a 188 | blank line -- a line containing nothing but spaces or tabs is considered 189 | blank.) Normal paragraphs should not be intended with spaces or tabs. 190 | 191 | The implication of the "one or more consecutive lines of text" rule is 192 | that Markdown supports "hard-wrapped" text paragraphs. This differs 193 | significantly from most other text-to-HTML formatters (including Movable 194 | Type's "Convert Line Breaks" option) which translate every line break 195 | character in a paragraph into a `
    ` tag. 196 | 197 | When you *do* want to insert a `
    ` break tag using Markdown, you 198 | end a line with two or more spaces, then type return. 199 | 200 | Yes, this takes a tad more effort to create a `
    `, but a simplistic 201 | "every line break is a `
    `" rule wouldn't work for Markdown. 202 | Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l] 203 | work best -- and look better -- when you format them with hard breaks. 204 | 205 | [bq]: #blockquote 206 | [l]: #list 207 | 208 | 209 | 210 | 211 | 212 | Markdown supports two styles of headers, [Setext] [1] and [atx] [2]. 213 | 214 | Setext-style headers are "underlined" using equal signs (for first-level 215 | headers) and dashes (for second-level headers). For example: 216 | 217 | This is an H1 218 | ============= 219 | 220 | This is an H2 221 | ------------- 222 | 223 | Any number of underlining `=`'s or `-`'s will work. 224 | 225 | Atx-style headers use 1-6 hash characters at the start of the line, 226 | corresponding to header levels 1-6. For example: 227 | 228 | # This is an H1 229 | 230 | ## This is an H2 231 | 232 | ###### This is an H6 233 | 234 | Optionally, you may "close" atx-style headers. This is purely 235 | cosmetic -- you can use this if you think it looks better. The 236 | closing hashes don't even need to match the number of hashes 237 | used to open the header. (The number of opening hashes 238 | determines the header level.) : 239 | 240 | # This is an H1 # 241 | 242 | ## This is an H2 ## 243 | 244 | ### This is an H3 ###### 245 | 246 | 247 |

    Blockquotes

    248 | 249 | Markdown uses email-style `>` characters for blockquoting. If you're 250 | familiar with quoting passages of text in an email message, then you 251 | know how to create a blockquote in Markdown. It looks best if you hard 252 | wrap the text and put a `>` before every line: 253 | 254 | > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 255 | > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 256 | > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 257 | > 258 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 259 | > id sem consectetuer libero luctus adipiscing. 260 | 261 | Markdown allows you to be lazy and only put the `>` before the first 262 | line of a hard-wrapped paragraph: 263 | 264 | > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 265 | consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 266 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 267 | 268 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 269 | id sem consectetuer libero luctus adipiscing. 270 | 271 | Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by 272 | adding additional levels of `>`: 273 | 274 | > This is the first level of quoting. 275 | > 276 | > > This is nested blockquote. 277 | > 278 | > Back to the first level. 279 | 280 | Blockquotes can contain other Markdown elements, including headers, lists, 281 | and code blocks: 282 | 283 | > ## This is a header. 284 | > 285 | > 1. This is the first list item. 286 | > 2. This is the second list item. 287 | > 288 | > Here's some example code: 289 | > 290 | > return shell_exec("echo $input | $markdown_script"); 291 | 292 | Any decent text editor should make email-style quoting easy. For 293 | example, with BBEdit, you can make a selection and choose Increase 294 | Quote Level from the Text menu. 295 | 296 | 297 |

    Lists

    298 | 299 | Markdown supports ordered (numbered) and unordered (bulleted) lists. 300 | 301 | Unordered lists use asterisks, pluses, and hyphens -- interchangably 302 | -- as list markers: 303 | 304 | * Red 305 | * Green 306 | * Blue 307 | 308 | is equivalent to: 309 | 310 | + Red 311 | + Green 312 | + Blue 313 | 314 | and: 315 | 316 | - Red 317 | - Green 318 | - Blue 319 | 320 | Ordered lists use numbers followed by periods: 321 | 322 | 1. Bird 323 | 2. McHale 324 | 3. Parish 325 | 326 | It's important to note that the actual numbers you use to mark the 327 | list have no effect on the HTML output Markdown produces. The HTML 328 | Markdown produces from the above list is: 329 | 330 |
      331 |
    1. Bird
    2. 332 |
    3. McHale
    4. 333 |
    5. Parish
    6. 334 |
    335 | 336 | If you instead wrote the list in Markdown like this: 337 | 338 | 1. Bird 339 | 1. McHale 340 | 1. Parish 341 | 342 | or even: 343 | 344 | 3. Bird 345 | 1. McHale 346 | 8. Parish 347 | 348 | you'd get the exact same HTML output. The point is, if you want to, 349 | you can use ordinal numbers in your ordered Markdown lists, so that 350 | the numbers in your source match the numbers in your published HTML. 351 | But if you want to be lazy, you don't have to. 352 | 353 | If you do use lazy list numbering, however, you should still start the 354 | list with the number 1. At some point in the future, Markdown may support 355 | starting ordered lists at an arbitrary number. 356 | 357 | List markers typically start at the left margin, but may be indented by 358 | up to three spaces. List markers must be followed by one or more spaces 359 | or a tab. 360 | 361 | To make lists look nice, you can wrap items with hanging indents: 362 | 363 | * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 364 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, 365 | viverra nec, fringilla in, laoreet vitae, risus. 366 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 367 | Suspendisse id sem consectetuer libero luctus adipiscing. 368 | 369 | But if you want to be lazy, you don't have to: 370 | 371 | * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 372 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, 373 | viverra nec, fringilla in, laoreet vitae, risus. 374 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 375 | Suspendisse id sem consectetuer libero luctus adipiscing. 376 | 377 | If list items are separated by blank lines, Markdown will wrap the 378 | items in `

    ` tags in the HTML output. For example, this input: 379 | 380 | * Bird 381 | * Magic 382 | 383 | will turn into: 384 | 385 |

      386 |
    • Bird
    • 387 |
    • Magic
    • 388 |
    389 | 390 | But this: 391 | 392 | * Bird 393 | 394 | * Magic 395 | 396 | will turn into: 397 | 398 |
      399 |
    • Bird

    • 400 |
    • Magic

    • 401 |
    402 | 403 | List items may consist of multiple paragraphs. Each subsequent 404 | paragraph in a list item must be intended by either 4 spaces 405 | or one tab: 406 | 407 | 1. This is a list item with two paragraphs. Lorem ipsum dolor 408 | sit amet, consectetuer adipiscing elit. Aliquam hendrerit 409 | mi posuere lectus. 410 | 411 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet 412 | vitae, risus. Donec sit amet nisl. Aliquam semper ipsum 413 | sit amet velit. 414 | 415 | 2. Suspendisse id sem consectetuer libero luctus adipiscing. 416 | 417 | It looks nice if you indent every line of the subsequent 418 | paragraphs, but here again, Markdown will allow you to be 419 | lazy: 420 | 421 | * This is a list item with two paragraphs. 422 | 423 | This is the second paragraph in the list item. You're 424 | only required to indent the first line. Lorem ipsum dolor 425 | sit amet, consectetuer adipiscing elit. 426 | 427 | * Another item in the same list. 428 | 429 | To put a blockquote within a list item, the blockquote's `>` 430 | delimiters need to be indented: 431 | 432 | * A list item with a blockquote: 433 | 434 | > This is a blockquote 435 | > inside a list item. 436 | 437 | To put a code block within a list item, the code block needs 438 | to be indented *twice* -- 8 spaces or two tabs: 439 | 440 | * A list item with a code block: 441 | 442 | 443 | 444 | 445 | It's worth noting that it's possible to trigger an ordered list by 446 | accident, by writing something like this: 447 | 448 | 1986. What a great season. 449 | 450 | In other words, a *number-period-space* sequence at the beginning of a 451 | line. To avoid this, you can backslash-escape the period: 452 | 453 | 1986\. What a great season. 454 | 455 | 456 | 457 |

    Code Blocks

    458 | 459 | Pre-formatted code blocks are used for writing about programming or 460 | markup source code. Rather than forming normal paragraphs, the lines 461 | of a code block are interpreted literally. Markdown wraps a code block 462 | in both `
    ` and `` tags.
    463 | 
    464 | To produce a code block in Markdown, simply indent every line of the
    465 | block by at least 4 spaces or 1 tab. For example, given this input:
    466 | 
    467 |     This is a normal paragraph:
    468 | 
    469 |         This is a code block.
    470 | 
    471 | Markdown will generate:
    472 | 
    473 |     

    This is a normal paragraph:

    474 | 475 |
    This is a code block.
    476 |     
    477 | 478 | One level of indentation -- 4 spaces or 1 tab -- is removed from each 479 | line of the code block. For example, this: 480 | 481 | Here is an example of AppleScript: 482 | 483 | tell application "Foo" 484 | beep 485 | end tell 486 | 487 | will turn into: 488 | 489 |

    Here is an example of AppleScript:

    490 | 491 |
    tell application "Foo"
    492 |         beep
    493 |     end tell
    494 |     
    495 | 496 | A code block continues until it reaches a line that is not indented 497 | (or the end of the article). 498 | 499 | Within a code block, ampersands (`&`) and angle brackets (`<` and `>`) 500 | are automatically converted into HTML entities. This makes it very 501 | easy to include example HTML source code using Markdown -- just paste 502 | it and indent it, and Markdown will handle the hassle of encoding the 503 | ampersands and angle brackets. For example, this: 504 | 505 | 508 | 509 | will turn into: 510 | 511 |
    <div class="footer">
    512 |         &copy; 2004 Foo Corporation
    513 |     </div>
    514 |     
    515 | 516 | Regular Markdown syntax is not processed within code blocks. E.g., 517 | asterisks are just literal asterisks within a code block. This means 518 | it's also easy to use Markdown to write about Markdown's own syntax. 519 | 520 | 521 | 522 |

    Horizontal Rules

    523 | 524 | You can produce a horizontal rule tag (`
    `) by placing three or 525 | more hyphens, asterisks, or underscores on a line by themselves. If you 526 | wish, you may use spaces between the hyphens or asterisks. Each of the 527 | following lines will produce a horizontal rule: 528 | 529 | * * * 530 | 531 | *** 532 | 533 | ***** 534 | 535 | - - - 536 | 537 | --------------------------------------- 538 | 539 | _ _ _ 540 | 541 | 542 | * * * 543 | 544 |

    Span Elements

    545 | 546 | 547 | 548 | Markdown supports two style of links: *inline* and *reference*. 549 | 550 | In both styles, the link text is delimited by [square brackets]. 551 | 552 | To create an inline link, use a set of regular parentheses immediately 553 | after the link text's closing square bracket. Inside the parentheses, 554 | put the URL where you want the link to point, along with an *optional* 555 | title for the link, surrounded in quotes. For example: 556 | 557 | This is [an example](http://example.com/ "Title") inline link. 558 | 559 | [This link](http://example.net/) has no title attribute. 560 | 561 | Will produce: 562 | 563 |

    This is 564 | an example inline link.

    565 | 566 |

    This link has no 567 | title attribute.

    568 | 569 | If you're referring to a local resource on the same server, you can 570 | use relative paths: 571 | 572 | See my [About](/about/) page for details. 573 | 574 | Reference-style links use a second set of square brackets, inside 575 | which you place a label of your choosing to identify the link: 576 | 577 | This is [an example][id] reference-style link. 578 | 579 | You can optionally use a space to separate the sets of brackets: 580 | 581 | This is [an example] [id] reference-style link. 582 | 583 | Then, anywhere in the document, you define your link label like this, 584 | on a line by itself: 585 | 586 | [id]: http://example.com/ "Optional Title Here" 587 | 588 | That is: 589 | 590 | * Square brackets containing the link identifier (optionally 591 | indented from the left margin using up to three spaces); 592 | * followed by a colon; 593 | * followed by one or more spaces (or tabs); 594 | * followed by the URL for the link; 595 | * optionally followed by a title attribute for the link, enclosed 596 | in double or single quotes. 597 | 598 | The link URL may, optionally, be surrounded by angle brackets: 599 | 600 | [id]: "Optional Title Here" 601 | 602 | You can put the title attribute on the next line and use extra spaces 603 | or tabs for padding, which tends to look better with longer URLs: 604 | 605 | [id]: http://example.com/longish/path/to/resource/here 606 | "Optional Title Here" 607 | 608 | Link definitions are only used for creating links during Markdown 609 | processing, and are stripped from your document in the HTML output. 610 | 611 | Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are *not* case sensitive. E.g. these two links: 612 | 613 | [link text][a] 614 | [link text][A] 615 | 616 | are equivalent. 617 | 618 | The *implicit link name* shortcut allows you to omit the name of the 619 | link, in which case the link text itself is used as the name. 620 | Just use an empty set of square brackets -- e.g., to link the word 621 | "Google" to the google.com web site, you could simply write: 622 | 623 | [Google][] 624 | 625 | And then define the link: 626 | 627 | [Google]: http://google.com/ 628 | 629 | Because link names may contain spaces, this shortcut even works for 630 | multiple words in the link text: 631 | 632 | Visit [Daring Fireball][] for more information. 633 | 634 | And then define the link: 635 | 636 | [Daring Fireball]: http://daringfireball.net/ 637 | 638 | Link definitions can be placed anywhere in your Markdown document. I 639 | tend to put them immediately after each paragraph in which they're 640 | used, but if you want, you can put them all at the end of your 641 | document, sort of like footnotes. 642 | 643 | Here's an example of reference links in action: 644 | 645 | I get 10 times more traffic from [Google] [1] than from 646 | [Yahoo] [2] or [MSN] [3]. 647 | 648 | [1]: http://google.com/ "Google" 649 | [2]: http://search.yahoo.com/ "Yahoo Search" 650 | [3]: http://search.msn.com/ "MSN Search" 651 | 652 | Using the implicit link name shortcut, you could instead write: 653 | 654 | I get 10 times more traffic from [Google][] than from 655 | [Yahoo][] or [MSN][]. 656 | 657 | [google]: http://google.com/ "Google" 658 | [yahoo]: http://search.yahoo.com/ "Yahoo Search" 659 | [msn]: http://search.msn.com/ "MSN Search" 660 | 661 | Both of the above examples will produce the following HTML output: 662 | 663 |

    I get 10 times more traffic from Google than from 665 | Yahoo 666 | or MSN.

    667 | 668 | For comparison, here is the same paragraph written using 669 | Markdown's inline link style: 670 | 671 | I get 10 times more traffic from [Google](http://google.com/ "Google") 672 | than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or 673 | [MSN](http://search.msn.com/ "MSN Search"). 674 | 675 | The point of reference-style links is not that they're easier to 676 | write. The point is that with reference-style links, your document 677 | source is vastly more readable. Compare the above examples: using 678 | reference-style links, the paragraph itself is only 81 characters 679 | long; with inline-style links, it's 176 characters; and as raw HTML, 680 | it's 234 characters. In the raw HTML, there's more markup than there 681 | is text. 682 | 683 | With Markdown's reference-style links, a source document much more 684 | closely resembles the final output, as rendered in a browser. By 685 | allowing you to move the markup-related metadata out of the paragraph, 686 | you can add links without interrupting the narrative flow of your 687 | prose. 688 | 689 | 690 |

    Emphasis

    691 | 692 | Markdown treats asterisks (`*`) and underscores (`_`) as indicators of 693 | emphasis. Text wrapped with one `*` or `_` will be wrapped with an 694 | HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML 695 | `` tag. E.g., this input: 696 | 697 | *single asterisks* 698 | 699 | _single underscores_ 700 | 701 | **double asterisks** 702 | 703 | __double underscores__ 704 | 705 | will produce: 706 | 707 | single asterisks 708 | 709 | single underscores 710 | 711 | double asterisks 712 | 713 | double underscores 714 | 715 | You can use whichever style you prefer; the lone restriction is that 716 | the same character must be used to open and close an emphasis span. 717 | 718 | Emphasis can be used in the middle of a word: 719 | 720 | un*fucking*believable 721 | 722 | But if you surround an `*` or `_` with spaces, it'll be treated as a 723 | literal asterisk or underscore. 724 | 725 | To produce a literal asterisk or underscore at a position where it 726 | would otherwise be used as an emphasis delimiter, you can backslash 727 | escape it: 728 | 729 | \*this text is surrounded by literal asterisks\* 730 | 731 | 732 | 733 |

    Code

    734 | 735 | To indicate a span of code, wrap it with backtick quotes (`` ` ``). 736 | Unlike a pre-formatted code block, a code span indicates code within a 737 | normal paragraph. For example: 738 | 739 | Use the `printf()` function. 740 | 741 | will produce: 742 | 743 |

    Use the printf() function.

    744 | 745 | To include a literal backtick character within a code span, you can use 746 | multiple backticks as the opening and closing delimiters: 747 | 748 | ``There is a literal backtick (`) here.`` 749 | 750 | which will produce this: 751 | 752 |

    There is a literal backtick (`) here.

    753 | 754 | The backtick delimiters surrounding a code span may include spaces -- 755 | one after the opening, one before the closing. This allows you to place 756 | literal backtick characters at the beginning or end of a code span: 757 | 758 | A single backtick in a code span: `` ` `` 759 | 760 | A backtick-delimited string in a code span: `` `foo` `` 761 | 762 | will produce: 763 | 764 |

    A single backtick in a code span: `

    765 | 766 |

    A backtick-delimited string in a code span: `foo`

    767 | 768 | With a code span, ampersands and angle brackets are encoded as HTML 769 | entities automatically, which makes it easy to include example HTML 770 | tags. Markdown will turn this: 771 | 772 | Please don't use any `` tags. 773 | 774 | into: 775 | 776 |

    Please don't use any <blink> tags.

    777 | 778 | You can write this: 779 | 780 | `—` is the decimal-encoded equivalent of `—`. 781 | 782 | to produce: 783 | 784 |

    &#8212; is the decimal-encoded 785 | equivalent of &mdash;.

    786 | 787 | 788 | 789 |

    Images

    790 | 791 | Admittedly, it's fairly difficult to devise a "natural" syntax for 792 | placing images into a plain text document format. 793 | 794 | Markdown uses an image syntax that is intended to resemble the syntax 795 | for links, allowing for two styles: *inline* and *reference*. 796 | 797 | Inline image syntax looks like this: 798 | 799 | ![Alt text](/path/to/img.jpg) 800 | 801 | ![Alt text](/path/to/img.jpg "Optional title") 802 | 803 | That is: 804 | 805 | * An exclamation mark: `!`; 806 | * followed by a set of square brackets, containing the `alt` 807 | attribute text for the image; 808 | * followed by a set of parentheses, containing the URL or path to 809 | the image, and an optional `title` attribute enclosed in double 810 | or single quotes. 811 | 812 | Reference-style image syntax looks like this: 813 | 814 | ![Alt text][id] 815 | 816 | Where "id" is the name of a defined image reference. Image references 817 | are defined using syntax identical to link references: 818 | 819 | [id]: url/to/image "Optional title attribute" 820 | 821 | As of this writing, Markdown has no syntax for specifying the 822 | dimensions of an image; if this is important to you, you can simply 823 | use regular HTML `` tags. 824 | 825 | 826 | * * * 827 | 828 | 829 |

    Miscellaneous

    830 | 831 | 832 | 833 | Markdown supports a shortcut style for creating "automatic" 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: 834 | 835 | 836 | 837 | Markdown will turn this into: 838 | 839 | http://example.com/ 840 | 841 | Automatic links for email addresses work similarly, except that 842 | Markdown will also perform a bit of randomized decimal and hex 843 | entity-encoding to help obscure your address from address-harvesting 844 | spambots. For example, Markdown will turn this: 845 | 846 | 847 | 848 | into something like this: 849 | 850 | address@exa 853 | mple.com 854 | 855 | which will render in a browser as a clickable link to "address@example.com". 856 | 857 | (This sort of entity-encoding trick will indeed fool many, if not 858 | most, address-harvesting bots, but it definitely won't fool all of 859 | them. It's better than nothing, but an address published in this way 860 | will probably eventually start receiving spam.) 861 | 862 | 863 | 864 |

    Backslash Escapes

    865 | 866 | Markdown allows you to use backslash escapes to generate literal 867 | characters which would otherwise have special meaning in Markdown's 868 | formatting syntax. For example, if you wanted to surround a word with 869 | literal asterisks (instead of an HTML `` tag), you can backslashes 870 | before the asterisks, like this: 871 | 872 | \*literal asterisks\* 873 | 874 | Markdown provides backslash escapes for the following characters: 875 | 876 | \ backslash 877 | ` backtick 878 | * asterisk 879 | _ underscore 880 | {} curly braces 881 | [] square brackets 882 | () parentheses 883 | # hash mark 884 | + plus sign 885 | - minus sign (hyphen) 886 | . dot 887 | ! exclamation mark 888 | 889 | -------------------------------------------------------------------------------- /test/original/markdown_documentation_syntax.html: -------------------------------------------------------------------------------- 1 |

    Markdown: Syntax

    2 | 3 | 10 | 11 | 40 | 41 |

    Note: This document is itself written using Markdown; you 42 | can see the source for it by adding '.text' to the URL.

    43 | 44 |
    45 | 46 |

    Overview

    47 | 48 |

    Philosophy

    49 | 50 |

    Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

    51 | 52 |

    Readability, however, is emphasized above all else. A Markdown-formatted 53 | document should be publishable as-is, as plain text, without looking 54 | like it's been marked up with tags or formatting instructions. While 55 | Markdown's syntax has been influenced by several existing text-to-HTML 56 | filters -- including Setext, atx, Textile, reStructuredText, 57 | Grutatext, and EtText -- the single biggest source of 58 | inspiration for Markdown's syntax is the format of plain text email.

    59 | 60 |

    To this end, Markdown's syntax is comprised entirely of punctuation 61 | characters, which punctuation characters have been carefully chosen so 62 | as to look like what they mean. E.g., asterisks around a word actually 63 | look like *emphasis*. Markdown lists look like, well, lists. Even 64 | blockquotes look like quoted passages of text, assuming you've ever 65 | used email.

    66 | 67 |

    Inline HTML

    68 | 69 |

    Markdown's syntax is intended for one purpose: to be used as a 70 | format for writing for the web.

    71 | 72 |

    Markdown is not a replacement for HTML, or even close to it. Its 73 | syntax is very small, corresponding only to a very small subset of 74 | HTML tags. The idea is not to create a syntax that makes it easier 75 | to insert HTML tags. In my opinion, HTML tags are already easy to 76 | insert. The idea for Markdown is to make it easy to read, write, and 77 | edit prose. HTML is a publishing format; Markdown is a writing 78 | format. Thus, Markdown's formatting syntax only addresses issues that 79 | can be conveyed in plain text.

    80 | 81 |

    For any markup that is not covered by Markdown's syntax, you simply 82 | use HTML itself. There's no need to preface it or delimit it to 83 | indicate that you're switching from Markdown to HTML; you just use 84 | the tags.

    85 | 86 |

    The only restrictions are that block-level HTML elements -- e.g. <div>, 87 | <table>, <pre>, <p>, etc. -- must be separated from surrounding 88 | content by blank lines, and the start and end tags of the block should 89 | not be indented with tabs or spaces. Markdown is smart enough not 90 | to add extra (unwanted) <p> tags around HTML block-level tags.

    91 | 92 |

    For example, to add an HTML table to a Markdown article:

    93 | 94 |
    This is a regular paragraph.
     95 | 
     96 | <table>
     97 |     <tr>
     98 |         <td>Foo</td>
     99 |     </tr>
    100 | </table>
    101 | 
    102 | This is another regular paragraph.
    103 | 
    104 | 105 |

    Note that Markdown formatting syntax is not processed within block-level 106 | HTML tags. E.g., you can't use Markdown-style *emphasis* inside an 107 | HTML block.

    108 | 109 |

    Span-level HTML tags -- e.g. <span>, <cite>, or <del> -- can be 110 | used anywhere in a Markdown paragraph, list item, or header. If you 111 | want, you can even use HTML tags instead of Markdown formatting; e.g. if 112 | you'd prefer to use HTML <a> or <img> tags instead of Markdown's 113 | link or image syntax, go right ahead.

    114 | 115 |

    Unlike block-level HTML tags, Markdown syntax is processed within 116 | span-level tags.

    117 | 118 |

    Automatic Escaping for Special Characters

    119 | 120 |

    In HTML, there are two characters that demand special treatment: < 121 | and &. Left angle brackets are used to start tags; ampersands are 122 | used to denote HTML entities. If you want to use them as literal 123 | characters, you must escape them as entities, e.g. &lt;, and 124 | &amp;.

    125 | 126 |

    Ampersands in particular are bedeviling for web writers. If you want to 127 | write about 'AT&T', you need to write 'AT&amp;T'. You even need to 128 | escape ampersands within URLs. Thus, if you want to link to:

    129 | 130 |
    http://images.google.com/images?num=30&q=larry+bird
    131 | 
    132 | 133 |

    you need to encode the URL as:

    134 | 135 |
    http://images.google.com/images?num=30&amp;q=larry+bird
    136 | 
    137 | 138 |

    in your anchor tag href attribute. Needless to say, this is easy to 139 | forget, and is probably the single most common source of HTML validation 140 | errors in otherwise well-marked-up web sites.

    141 | 142 |

    Markdown allows you to use these characters naturally, taking care of 143 | all the necessary escaping for you. If you use an ampersand as part of 144 | an HTML entity, it remains unchanged; otherwise it will be translated 145 | into &amp;.

    146 | 147 |

    So, if you want to include a copyright symbol in your article, you can write:

    148 | 149 |
    &copy;
    150 | 
    151 | 152 |

    and Markdown will leave it alone. But if you write:

    153 | 154 |
    AT&T
    155 | 
    156 | 157 |

    Markdown will translate it to:

    158 | 159 |
    AT&amp;T
    160 | 
    161 | 162 |

    Similarly, because Markdown supports inline HTML, if you use 163 | angle brackets as delimiters for HTML tags, Markdown will treat them as 164 | such. But if you write:

    165 | 166 |
    4 < 5
    167 | 
    168 | 169 |

    Markdown will translate it to:

    170 | 171 |
    4 &lt; 5
    172 | 
    173 | 174 |

    However, inside Markdown code spans and blocks, angle brackets and 175 | ampersands are always encoded automatically. This makes it easy to use 176 | Markdown to write about HTML code. (As opposed to raw HTML, which is a 177 | terrible format for writing about HTML syntax, because every single < 178 | and & in your example code needs to be escaped.)

    179 | 180 |
    181 | 182 |

    Block Elements

    183 | 184 |

    Paragraphs and Line Breaks

    185 | 186 |

    A paragraph is simply one or more consecutive lines of text, separated 187 | by one or more blank lines. (A blank line is any line that looks like a 188 | blank line -- a line containing nothing but spaces or tabs is considered 189 | blank.) Normal paragraphs should not be intended with spaces or tabs.

    190 | 191 |

    The implication of the "one or more consecutive lines of text" rule is 192 | that Markdown supports "hard-wrapped" text paragraphs. This differs 193 | significantly from most other text-to-HTML formatters (including Movable 194 | Type's "Convert Line Breaks" option) which translate every line break 195 | character in a paragraph into a <br /> tag.

    196 | 197 |

    When you do want to insert a <br /> break tag using Markdown, you 198 | end a line with two or more spaces, then type return.

    199 | 200 |

    Yes, this takes a tad more effort to create a <br />, but a simplistic 201 | "every line break is a <br />" rule wouldn't work for Markdown. 202 | Markdown's email-style blockquoting and multi-paragraph list items 203 | work best -- and look better -- when you format them with hard breaks.

    204 | 205 | 206 | 207 |

    Markdown supports two styles of headers, Setext and atx.

    208 | 209 |

    Setext-style headers are "underlined" using equal signs (for first-level 210 | headers) and dashes (for second-level headers). For example:

    211 | 212 |
    This is an H1
    213 | =============
    214 | 
    215 | This is an H2
    216 | -------------
    217 | 
    218 | 219 |

    Any number of underlining ='s or -'s will work.

    220 | 221 |

    Atx-style headers use 1-6 hash characters at the start of the line, 222 | corresponding to header levels 1-6. For example:

    223 | 224 |
    # This is an H1
    225 | 
    226 | ## This is an H2
    227 | 
    228 | ###### This is an H6
    229 | 
    230 | 231 |

    Optionally, you may "close" atx-style headers. This is purely 232 | cosmetic -- you can use this if you think it looks better. The 233 | closing hashes don't even need to match the number of hashes 234 | used to open the header. (The number of opening hashes 235 | determines the header level.) :

    236 | 237 |
    # This is an H1 #
    238 | 
    239 | ## This is an H2 ##
    240 | 
    241 | ### This is an H3 ######
    242 | 
    243 | 244 |

    Blockquotes

    245 | 246 |

    Markdown uses email-style > characters for blockquoting. If you're 247 | familiar with quoting passages of text in an email message, then you 248 | know how to create a blockquote in Markdown. It looks best if you hard 249 | wrap the text and put a > before every line:

    250 | 251 |
    > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
    252 | > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
    253 | > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
    254 | > 
    255 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
    256 | > id sem consectetuer libero luctus adipiscing.
    257 | 
    258 | 259 |

    Markdown allows you to be lazy and only put the > before the first 260 | line of a hard-wrapped paragraph:

    261 | 262 |
    > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
    263 | consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
    264 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
    265 | 
    266 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
    267 | id sem consectetuer libero luctus adipiscing.
    268 | 
    269 | 270 |

    Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by 271 | adding additional levels of >:

    272 | 273 |
    > This is the first level of quoting.
    274 | >
    275 | > > This is nested blockquote.
    276 | >
    277 | > Back to the first level.
    278 | 
    279 | 280 |

    Blockquotes can contain other Markdown elements, including headers, lists, 281 | and code blocks:

    282 | 283 |
    > ## This is a header.
    284 | > 
    285 | > 1.   This is the first list item.
    286 | > 2.   This is the second list item.
    287 | > 
    288 | > Here's some example code:
    289 | > 
    290 | >     return shell_exec("echo $input | $markdown_script");
    291 | 
    292 | 293 |

    Any decent text editor should make email-style quoting easy. For 294 | example, with BBEdit, you can make a selection and choose Increase 295 | Quote Level from the Text menu.

    296 | 297 |

    Lists

    298 | 299 |

    Markdown supports ordered (numbered) and unordered (bulleted) lists.

    300 | 301 |

    Unordered lists use asterisks, pluses, and hyphens -- interchangably 302 | -- as list markers:

    303 | 304 |
    *   Red
    305 | *   Green
    306 | *   Blue
    307 | 
    308 | 309 |

    is equivalent to:

    310 | 311 |
    +   Red
    312 | +   Green
    313 | +   Blue
    314 | 
    315 | 316 |

    and:

    317 | 318 |
    -   Red
    319 | -   Green
    320 | -   Blue
    321 | 
    322 | 323 |

    Ordered lists use numbers followed by periods:

    324 | 325 |
    1.  Bird
    326 | 2.  McHale
    327 | 3.  Parish
    328 | 
    329 | 330 |

    It's important to note that the actual numbers you use to mark the 331 | list have no effect on the HTML output Markdown produces. The HTML 332 | Markdown produces from the above list is:

    333 | 334 |
    <ol>
    335 | <li>Bird</li>
    336 | <li>McHale</li>
    337 | <li>Parish</li>
    338 | </ol>
    339 | 
    340 | 341 |

    If you instead wrote the list in Markdown like this:

    342 | 343 |
    1.  Bird
    344 | 1.  McHale
    345 | 1.  Parish
    346 | 
    347 | 348 |

    or even:

    349 | 350 |
    3. Bird
    351 | 1. McHale
    352 | 8. Parish
    353 | 
    354 | 355 |

    you'd get the exact same HTML output. The point is, if you want to, 356 | you can use ordinal numbers in your ordered Markdown lists, so that 357 | the numbers in your source match the numbers in your published HTML. 358 | But if you want to be lazy, you don't have to.

    359 | 360 |

    If you do use lazy list numbering, however, you should still start the 361 | list with the number 1. At some point in the future, Markdown may support 362 | starting ordered lists at an arbitrary number.

    363 | 364 |

    List markers typically start at the left margin, but may be indented by 365 | up to three spaces. List markers must be followed by one or more spaces 366 | or a tab.

    367 | 368 |

    To make lists look nice, you can wrap items with hanging indents:

    369 | 370 |
    *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    371 |     Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    372 |     viverra nec, fringilla in, laoreet vitae, risus.
    373 | *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    374 |     Suspendisse id sem consectetuer libero luctus adipiscing.
    375 | 
    376 | 377 |

    But if you want to be lazy, you don't have to:

    378 | 379 |
    *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    380 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    381 | viverra nec, fringilla in, laoreet vitae, risus.
    382 | *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    383 | Suspendisse id sem consectetuer libero luctus adipiscing.
    384 | 
    385 | 386 |

    If list items are separated by blank lines, Markdown will wrap the 387 | items in <p> tags in the HTML output. For example, this input:

    388 | 389 |
    *   Bird
    390 | *   Magic
    391 | 
    392 | 393 |

    will turn into:

    394 | 395 |
    <ul>
    396 | <li>Bird</li>
    397 | <li>Magic</li>
    398 | </ul>
    399 | 
    400 | 401 |

    But this:

    402 | 403 |
    *   Bird
    404 | 
    405 | *   Magic
    406 | 
    407 | 408 |

    will turn into:

    409 | 410 |
    <ul>
    411 | <li><p>Bird</p></li>
    412 | <li><p>Magic</p></li>
    413 | </ul>
    414 | 
    415 | 416 |

    List items may consist of multiple paragraphs. Each subsequent 417 | paragraph in a list item must be intended by either 4 spaces 418 | or one tab:

    419 | 420 |
    1.  This is a list item with two paragraphs. Lorem ipsum dolor
    421 |     sit amet, consectetuer adipiscing elit. Aliquam hendrerit
    422 |     mi posuere lectus.
    423 | 
    424 |     Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    425 |     vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
    426 |     sit amet velit.
    427 | 
    428 | 2.  Suspendisse id sem consectetuer libero luctus adipiscing.
    429 | 
    430 | 431 |

    It looks nice if you indent every line of the subsequent 432 | paragraphs, but here again, Markdown will allow you to be 433 | lazy:

    434 | 435 |
    *   This is a list item with two paragraphs.
    436 | 
    437 |     This is the second paragraph in the list item. You're
    438 | only required to indent the first line. Lorem ipsum dolor
    439 | sit amet, consectetuer adipiscing elit.
    440 | 
    441 | *   Another item in the same list.
    442 | 
    443 | 444 |

    To put a blockquote within a list item, the blockquote's > 445 | delimiters need to be indented:

    446 | 447 |
    *   A list item with a blockquote:
    448 | 
    449 |     > This is a blockquote
    450 |     > inside a list item.
    451 | 
    452 | 453 |

    To put a code block within a list item, the code block needs 454 | to be indented twice -- 8 spaces or two tabs:

    455 | 456 |
    *   A list item with a code block:
    457 | 
    458 |         <code goes here>
    459 | 
    460 | 461 |

    It's worth noting that it's possible to trigger an ordered list by 462 | accident, by writing something like this:

    463 | 464 |
    1986. What a great season.
    465 | 
    466 | 467 |

    In other words, a number-period-space sequence at the beginning of a 468 | line. To avoid this, you can backslash-escape the period:

    469 | 470 |
    1986\. What a great season.
    471 | 
    472 | 473 |

    Code Blocks

    474 | 475 |

    Pre-formatted code blocks are used for writing about programming or 476 | markup source code. Rather than forming normal paragraphs, the lines 477 | of a code block are interpreted literally. Markdown wraps a code block 478 | in both <pre> and <code> tags.

    479 | 480 |

    To produce a code block in Markdown, simply indent every line of the 481 | block by at least 4 spaces or 1 tab. For example, given this input:

    482 | 483 |
    This is a normal paragraph:
    484 | 
    485 |     This is a code block.
    486 | 
    487 | 488 |

    Markdown will generate:

    489 | 490 |
    <p>This is a normal paragraph:</p>
    491 | 
    492 | <pre><code>This is a code block.
    493 | </code></pre>
    494 | 
    495 | 496 |

    One level of indentation -- 4 spaces or 1 tab -- is removed from each 497 | line of the code block. For example, this:

    498 | 499 |
    Here is an example of AppleScript:
    500 | 
    501 |     tell application "Foo"
    502 |         beep
    503 |     end tell
    504 | 
    505 | 506 |

    will turn into:

    507 | 508 |
    <p>Here is an example of AppleScript:</p>
    509 | 
    510 | <pre><code>tell application "Foo"
    511 |     beep
    512 | end tell
    513 | </code></pre>
    514 | 
    515 | 516 |

    A code block continues until it reaches a line that is not indented 517 | (or the end of the article).

    518 | 519 |

    Within a code block, ampersands (&) and angle brackets (< and >) 520 | are automatically converted into HTML entities. This makes it very 521 | easy to include example HTML source code using Markdown -- just paste 522 | it and indent it, and Markdown will handle the hassle of encoding the 523 | ampersands and angle brackets. For example, this:

    524 | 525 |
        <div class="footer">
    526 |         &copy; 2004 Foo Corporation
    527 |     </div>
    528 | 
    529 | 530 |

    will turn into:

    531 | 532 |
    <pre><code>&lt;div class="footer"&gt;
    533 |     &amp;copy; 2004 Foo Corporation
    534 | &lt;/div&gt;
    535 | </code></pre>
    536 | 
    537 | 538 |

    Regular Markdown syntax is not processed within code blocks. E.g., 539 | asterisks are just literal asterisks within a code block. This means 540 | it's also easy to use Markdown to write about Markdown's own syntax.

    541 | 542 |

    Horizontal Rules

    543 | 544 |

    You can produce a horizontal rule tag (<hr />) by placing three or 545 | more hyphens, asterisks, or underscores on a line by themselves. If you 546 | wish, you may use spaces between the hyphens or asterisks. Each of the 547 | following lines will produce a horizontal rule:

    548 | 549 |
    * * *
    550 | 
    551 | ***
    552 | 
    553 | *****
    554 | 
    555 | - - -
    556 | 
    557 | ---------------------------------------
    558 | 
    559 | _ _ _
    560 | 
    561 | 562 |
    563 | 564 |

    Span Elements

    565 | 566 | 567 | 568 |

    Markdown supports two style of links: inline and reference.

    569 | 570 |

    In both styles, the link text is delimited by [square brackets].

    571 | 572 |

    To create an inline link, use a set of regular parentheses immediately 573 | after the link text's closing square bracket. Inside the parentheses, 574 | put the URL where you want the link to point, along with an optional 575 | title for the link, surrounded in quotes. For example:

    576 | 577 |
    This is [an example](http://example.com/ "Title") inline link.
    578 | 
    579 | [This link](http://example.net/) has no title attribute.
    580 | 
    581 | 582 |

    Will produce:

    583 | 584 |
    <p>This is <a href="http://example.com/" title="Title">
    585 | an example</a> inline link.</p>
    586 | 
    587 | <p><a href="http://example.net/">This link</a> has no
    588 | title attribute.</p>
    589 | 
    590 | 591 |

    If you're referring to a local resource on the same server, you can 592 | use relative paths:

    593 | 594 |
    See my [About](/about/) page for details.
    595 | 
    596 | 597 |

    Reference-style links use a second set of square brackets, inside 598 | which you place a label of your choosing to identify the link:

    599 | 600 |
    This is [an example][id] reference-style link.
    601 | 
    602 | 603 |

    You can optionally use a space to separate the sets of brackets:

    604 | 605 |
    This is [an example] [id] reference-style link.
    606 | 
    607 | 608 |

    Then, anywhere in the document, you define your link label like this, 609 | on a line by itself:

    610 | 611 |
    [id]: http://example.com/  "Optional Title Here"
    612 | 
    613 | 614 |

    That is:

    615 | 616 |
      617 |
    • Square brackets containing the link identifier (optionally 618 | indented from the left margin using up to three spaces);
    • 619 |
    • followed by a colon;
    • 620 |
    • followed by one or more spaces (or tabs);
    • 621 |
    • followed by the URL for the link;
    • 622 |
    • optionally followed by a title attribute for the link, enclosed 623 | in double or single quotes.
    • 624 |
    625 | 626 |

    The link URL may, optionally, be surrounded by angle brackets:

    627 | 628 |
    [id]: <http://example.com/>  "Optional Title Here"
    629 | 
    630 | 631 |

    You can put the title attribute on the next line and use extra spaces 632 | or tabs for padding, which tends to look better with longer URLs:

    633 | 634 |
    [id]: http://example.com/longish/path/to/resource/here
    635 |     "Optional Title Here"
    636 | 
    637 | 638 |

    Link definitions are only used for creating links during Markdown 639 | processing, and are stripped from your document in the HTML output.

    640 | 641 |

    Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are not case sensitive. E.g. these two links:

    642 | 643 |
    [link text][a]
    644 | [link text][A]
    645 | 
    646 | 647 |

    are equivalent.

    648 | 649 |

    The implicit link name shortcut allows you to omit the name of the 650 | link, in which case the link text itself is used as the name. 651 | Just use an empty set of square brackets -- e.g., to link the word 652 | "Google" to the google.com web site, you could simply write:

    653 | 654 |
    [Google][]
    655 | 
    656 | 657 |

    And then define the link:

    658 | 659 |
    [Google]: http://google.com/
    660 | 
    661 | 662 |

    Because link names may contain spaces, this shortcut even works for 663 | multiple words in the link text:

    664 | 665 |
    Visit [Daring Fireball][] for more information.
    666 | 
    667 | 668 |

    And then define the link:

    669 | 670 |
    [Daring Fireball]: http://daringfireball.net/
    671 | 
    672 | 673 |

    Link definitions can be placed anywhere in your Markdown document. I 674 | tend to put them immediately after each paragraph in which they're 675 | used, but if you want, you can put them all at the end of your 676 | document, sort of like footnotes.

    677 | 678 |

    Here's an example of reference links in action:

    679 | 680 |
    I get 10 times more traffic from [Google] [1] than from
    681 | [Yahoo] [2] or [MSN] [3].
    682 | 
    683 |   [1]: http://google.com/        "Google"
    684 |   [2]: http://search.yahoo.com/  "Yahoo Search"
    685 |   [3]: http://search.msn.com/    "MSN Search"
    686 | 
    687 | 688 |

    Using the implicit link name shortcut, you could instead write:

    689 | 690 |
    I get 10 times more traffic from [Google][] than from
    691 | [Yahoo][] or [MSN][].
    692 | 
    693 |   [google]: http://google.com/        "Google"
    694 |   [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
    695 |   [msn]:    http://search.msn.com/    "MSN Search"
    696 | 
    697 | 698 |

    Both of the above examples will produce the following HTML output:

    699 | 700 |
    <p>I get 10 times more traffic from <a href="http://google.com/"
    701 | title="Google">Google</a> than from
    702 | <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
    703 | or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
    704 | 
    705 | 706 |

    For comparison, here is the same paragraph written using 707 | Markdown's inline link style:

    708 | 709 |
    I get 10 times more traffic from [Google](http://google.com/ "Google")
    710 | than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
    711 | [MSN](http://search.msn.com/ "MSN Search").
    712 | 
    713 | 714 |

    The point of reference-style links is not that they're easier to 715 | write. The point is that with reference-style links, your document 716 | source is vastly more readable. Compare the above examples: using 717 | reference-style links, the paragraph itself is only 81 characters 718 | long; with inline-style links, it's 176 characters; and as raw HTML, 719 | it's 234 characters. In the raw HTML, there's more markup than there 720 | is text.

    721 | 722 |

    With Markdown's reference-style links, a source document much more 723 | closely resembles the final output, as rendered in a browser. By 724 | allowing you to move the markup-related metadata out of the paragraph, 725 | you can add links without interrupting the narrative flow of your 726 | prose.

    727 | 728 |

    Emphasis

    729 | 730 |

    Markdown treats asterisks (*) and underscores (_) as indicators of 731 | emphasis. Text wrapped with one * or _ will be wrapped with an 732 | HTML <em> tag; double *'s or _'s will be wrapped with an HTML 733 | <strong> tag. E.g., this input:

    734 | 735 |
    *single asterisks*
    736 | 
    737 | _single underscores_
    738 | 
    739 | **double asterisks**
    740 | 
    741 | __double underscores__
    742 | 
    743 | 744 |

    will produce:

    745 | 746 |
    <em>single asterisks</em>
    747 | 
    748 | <em>single underscores</em>
    749 | 
    750 | <strong>double asterisks</strong>
    751 | 
    752 | <strong>double underscores</strong>
    753 | 
    754 | 755 |

    You can use whichever style you prefer; the lone restriction is that 756 | the same character must be used to open and close an emphasis span.

    757 | 758 |

    Emphasis can be used in the middle of a word:

    759 | 760 |
    un*fucking*believable
    761 | 
    762 | 763 |

    But if you surround an * or _ with spaces, it'll be treated as a 764 | literal asterisk or underscore.

    765 | 766 |

    To produce a literal asterisk or underscore at a position where it 767 | would otherwise be used as an emphasis delimiter, you can backslash 768 | escape it:

    769 | 770 |
    \*this text is surrounded by literal asterisks\*
    771 | 
    772 | 773 |

    Code

    774 | 775 |

    To indicate a span of code, wrap it with backtick quotes (`). 776 | Unlike a pre-formatted code block, a code span indicates code within a 777 | normal paragraph. For example:

    778 | 779 |
    Use the `printf()` function.
    780 | 
    781 | 782 |

    will produce:

    783 | 784 |
    <p>Use the <code>printf()</code> function.</p>
    785 | 
    786 | 787 |

    To include a literal backtick character within a code span, you can use 788 | multiple backticks as the opening and closing delimiters:

    789 | 790 |
    ``There is a literal backtick (`) here.``
    791 | 
    792 | 793 |

    which will produce this:

    794 | 795 |
    <p><code>There is a literal backtick (`) here.</code></p>
    796 | 
    797 | 798 |

    The backtick delimiters surrounding a code span may include spaces -- 799 | one after the opening, one before the closing. This allows you to place 800 | literal backtick characters at the beginning or end of a code span:

    801 | 802 |
    A single backtick in a code span: `` ` ``
    803 | 
    804 | A backtick-delimited string in a code span: `` `foo` ``
    805 | 
    806 | 807 |

    will produce:

    808 | 809 |
    <p>A single backtick in a code span: <code>`</code></p>
    810 | 
    811 | <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
    812 | 
    813 | 814 |

    With a code span, ampersands and angle brackets are encoded as HTML 815 | entities automatically, which makes it easy to include example HTML 816 | tags. Markdown will turn this:

    817 | 818 |
    Please don't use any `<blink>` tags.
    819 | 
    820 | 821 |

    into:

    822 | 823 |
    <p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
    824 | 
    825 | 826 |

    You can write this:

    827 | 828 |
    `&#8212;` is the decimal-encoded equivalent of `&mdash;`.
    829 | 
    830 | 831 |

    to produce:

    832 | 833 |
    <p><code>&amp;#8212;</code> is the decimal-encoded
    834 | equivalent of <code>&amp;mdash;</code>.</p>
    835 | 
    836 | 837 |

    Images

    838 | 839 |

    Admittedly, it's fairly difficult to devise a "natural" syntax for 840 | placing images into a plain text document format.

    841 | 842 |

    Markdown uses an image syntax that is intended to resemble the syntax 843 | for links, allowing for two styles: inline and reference.

    844 | 845 |

    Inline image syntax looks like this:

    846 | 847 |
    ![Alt text](/path/to/img.jpg)
    848 | 
    849 | ![Alt text](/path/to/img.jpg "Optional title")
    850 | 
    851 | 852 |

    That is:

    853 | 854 |
      855 |
    • An exclamation mark: !;
    • 856 |
    • followed by a set of square brackets, containing the alt 857 | attribute text for the image;
    • 858 |
    • followed by a set of parentheses, containing the URL or path to 859 | the image, and an optional title attribute enclosed in double 860 | or single quotes.
    • 861 |
    862 | 863 |

    Reference-style image syntax looks like this:

    864 | 865 |
    ![Alt text][id]
    866 | 
    867 | 868 |

    Where "id" is the name of a defined image reference. Image references 869 | are defined using syntax identical to link references:

    870 | 871 |
    [id]: url/to/image  "Optional title attribute"
    872 | 
    873 | 874 |

    As of this writing, Markdown has no syntax for specifying the 875 | dimensions of an image; if this is important to you, you can simply 876 | use regular HTML <img> tags.

    877 | 878 |
    879 | 880 |

    Miscellaneous

    881 | 882 | 883 | 884 |

    Markdown supports a shortcut style for creating "automatic" 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:

    885 | 886 |
    <http://example.com/>
    887 | 
    888 | 889 |

    Markdown will turn this into:

    890 | 891 |
    <a href="http://example.com/">http://example.com/</a>
    892 | 
    893 | 894 |

    Automatic links for email addresses work similarly, except that 895 | Markdown will also perform a bit of randomized decimal and hex 896 | entity-encoding to help obscure your address from address-harvesting 897 | spambots. For example, Markdown will turn this:

    898 | 899 |
    <address@example.com>
    900 | 
    901 | 902 |

    into something like this:

    903 | 904 |
    <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
    905 | &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
    906 | &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
    907 | &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
    908 | 
    909 | 910 |

    which will render in a browser as a clickable link to "address@example.com".

    911 | 912 |

    (This sort of entity-encoding trick will indeed fool many, if not 913 | most, address-harvesting bots, but it definitely won't fool all of 914 | them. It's better than nothing, but an address published in this way 915 | will probably eventually start receiving spam.)

    916 | 917 |

    Backslash Escapes

    918 | 919 |

    Markdown allows you to use backslash escapes to generate literal 920 | characters which would otherwise have special meaning in Markdown's 921 | formatting syntax. For example, if you wanted to surround a word with 922 | literal asterisks (instead of an HTML <em> tag), you can backslashes 923 | before the asterisks, like this:

    924 | 925 |
    \*literal asterisks\*
    926 | 
    927 | 928 |

    Markdown provides backslash escapes for the following characters:

    929 | 930 |
    \   backslash
    931 | `   backtick
    932 | *   asterisk
    933 | _   underscore
    934 | {}  curly braces
    935 | []  square brackets
    936 | ()  parentheses
    937 | #   hash mark
    938 | +   plus sign
    939 | -   minus sign (hyphen)
    940 | .   dot
    941 | !   exclamation mark
    942 | 
    943 | --------------------------------------------------------------------------------