rdoc 4.3.0 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (248) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +13 -0
  3. data/.travis.yml +23 -0
  4. data/CONTRIBUTING.rdoc +4 -3
  5. data/Gemfile +3 -0
  6. data/History.rdoc +15 -4
  7. data/LEGAL.rdoc +2 -2
  8. data/README.rdoc +1 -0
  9. data/Rakefile +41 -79
  10. data/bin/console +7 -0
  11. data/bin/setup +6 -0
  12. data/{bin → exe}/rdoc +0 -0
  13. data/{bin → exe}/ri +0 -0
  14. data/lib/rdoc.rb +2 -1
  15. data/lib/rdoc/alias.rb +1 -0
  16. data/lib/rdoc/anon_class.rb +1 -0
  17. data/lib/rdoc/any_method.rb +1 -0
  18. data/lib/rdoc/attr.rb +1 -0
  19. data/lib/rdoc/class_module.rb +1 -0
  20. data/lib/rdoc/code_object.rb +1 -0
  21. data/lib/rdoc/code_objects.rb +1 -0
  22. data/lib/rdoc/comment.rb +1 -0
  23. data/lib/rdoc/constant.rb +1 -0
  24. data/lib/rdoc/context.rb +4 -1
  25. data/lib/rdoc/context/section.rb +7 -0
  26. data/lib/rdoc/cross_reference.rb +1 -0
  27. data/lib/rdoc/encoding.rb +14 -0
  28. data/lib/rdoc/erb_partial.rb +1 -0
  29. data/lib/rdoc/erbio.rb +1 -0
  30. data/lib/rdoc/extend.rb +1 -0
  31. data/lib/rdoc/generator.rb +1 -0
  32. data/lib/rdoc/generator/darkfish.rb +1 -0
  33. data/lib/rdoc/generator/json_index.rb +1 -0
  34. data/lib/rdoc/generator/markup.rb +1 -0
  35. data/lib/rdoc/generator/pot.rb +1 -0
  36. data/lib/rdoc/generator/pot/message_extractor.rb +1 -0
  37. data/lib/rdoc/generator/pot/po.rb +1 -0
  38. data/lib/rdoc/generator/pot/po_entry.rb +1 -0
  39. data/lib/rdoc/generator/ri.rb +1 -0
  40. data/lib/rdoc/generator/template/darkfish/_head.rhtml +2 -1
  41. data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
  42. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -7
  43. data/lib/rdoc/generator/template/json_index/js/searcher.js +1 -0
  44. data/lib/rdoc/ghost_method.rb +1 -0
  45. data/lib/rdoc/i18n.rb +1 -0
  46. data/lib/rdoc/i18n/locale.rb +1 -0
  47. data/lib/rdoc/i18n/text.rb +1 -0
  48. data/lib/rdoc/include.rb +1 -0
  49. data/lib/rdoc/known_classes.rb +1 -0
  50. data/lib/rdoc/markdown.kpeg +2 -6
  51. data/lib/rdoc/markdown.rb +2 -6
  52. data/lib/rdoc/markdown/entities.rb +1 -0
  53. data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +0 -0
  54. data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
  55. data/lib/rdoc/markup.rb +1 -0
  56. data/lib/rdoc/markup/attr_changer.rb +1 -0
  57. data/lib/rdoc/markup/attr_span.rb +1 -0
  58. data/lib/rdoc/markup/attribute_manager.rb +1 -0
  59. data/lib/rdoc/markup/attributes.rb +1 -0
  60. data/lib/rdoc/markup/blank_line.rb +1 -0
  61. data/lib/rdoc/markup/block_quote.rb +1 -0
  62. data/lib/rdoc/markup/document.rb +1 -0
  63. data/lib/rdoc/markup/formatter.rb +1 -0
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -4
  65. data/lib/rdoc/markup/hard_break.rb +1 -0
  66. data/lib/rdoc/markup/heading.rb +1 -0
  67. data/lib/rdoc/markup/include.rb +1 -0
  68. data/lib/rdoc/markup/indented_paragraph.rb +1 -0
  69. data/lib/rdoc/markup/inline.rb +1 -0
  70. data/lib/rdoc/markup/list.rb +1 -0
  71. data/lib/rdoc/markup/list_item.rb +1 -0
  72. data/lib/rdoc/markup/paragraph.rb +1 -0
  73. data/lib/rdoc/markup/parser.rb +1 -0
  74. data/lib/rdoc/markup/pre_process.rb +1 -0
  75. data/lib/rdoc/markup/raw.rb +1 -0
  76. data/lib/rdoc/markup/rule.rb +1 -0
  77. data/lib/rdoc/markup/special.rb +1 -0
  78. data/lib/rdoc/markup/text_formatter_test_case.rb +1 -0
  79. data/lib/rdoc/markup/to_ansi.rb +1 -0
  80. data/lib/rdoc/markup/to_bs.rb +1 -0
  81. data/lib/rdoc/markup/to_html.rb +1 -0
  82. data/lib/rdoc/markup/to_html_crossref.rb +1 -0
  83. data/lib/rdoc/markup/to_html_snippet.rb +1 -0
  84. data/lib/rdoc/markup/to_joined_paragraph.rb +1 -0
  85. data/lib/rdoc/markup/to_label.rb +1 -0
  86. data/lib/rdoc/markup/to_markdown.rb +1 -0
  87. data/lib/rdoc/markup/to_rdoc.rb +1 -0
  88. data/lib/rdoc/markup/to_table_of_contents.rb +1 -0
  89. data/lib/rdoc/markup/to_test.rb +1 -0
  90. data/lib/rdoc/markup/to_tt_only.rb +1 -0
  91. data/lib/rdoc/markup/verbatim.rb +1 -0
  92. data/lib/rdoc/meta_method.rb +1 -0
  93. data/lib/rdoc/method_attr.rb +1 -0
  94. data/lib/rdoc/mixin.rb +1 -0
  95. data/lib/rdoc/normal_class.rb +1 -0
  96. data/lib/rdoc/normal_module.rb +1 -0
  97. data/lib/rdoc/options.rb +1 -0
  98. data/lib/rdoc/parser.rb +1 -0
  99. data/lib/rdoc/parser/c.rb +76 -33
  100. data/lib/rdoc/parser/changelog.rb +7 -1
  101. data/lib/rdoc/parser/markdown.rb +1 -0
  102. data/lib/rdoc/parser/rd.rb +1 -0
  103. data/lib/rdoc/parser/ruby.rb +1 -0
  104. data/lib/rdoc/parser/ruby_tools.rb +1 -0
  105. data/lib/rdoc/parser/simple.rb +1 -0
  106. data/lib/rdoc/parser/text.rb +1 -0
  107. data/lib/rdoc/rd.rb +1 -0
  108. data/lib/rdoc/rd/inline.rb +1 -0
  109. data/lib/rdoc/rdoc.rb +2 -1
  110. data/lib/rdoc/require.rb +1 -0
  111. data/lib/rdoc/ri.rb +1 -0
  112. data/lib/rdoc/ri/driver.rb +5 -19
  113. data/lib/rdoc/ri/formatter.rb +1 -0
  114. data/lib/rdoc/ri/paths.rb +1 -0
  115. data/lib/rdoc/ri/store.rb +1 -0
  116. data/lib/rdoc/ri/task.rb +72 -0
  117. data/lib/rdoc/ruby_lex.rb +11 -17
  118. data/lib/rdoc/ruby_token.rb +1 -0
  119. data/lib/rdoc/rubygems_hook.rb +1 -0
  120. data/lib/rdoc/servlet.rb +4 -3
  121. data/lib/rdoc/single_class.rb +1 -0
  122. data/lib/rdoc/stats.rb +1 -0
  123. data/lib/rdoc/stats/normal.rb +1 -0
  124. data/lib/rdoc/stats/quiet.rb +1 -0
  125. data/lib/rdoc/stats/verbose.rb +1 -0
  126. data/lib/rdoc/store.rb +3 -9
  127. data/lib/rdoc/task.rb +1 -0
  128. data/lib/rdoc/test_case.rb +1 -10
  129. data/lib/rdoc/text.rb +1 -0
  130. data/lib/rdoc/token_stream.rb +1 -0
  131. data/lib/rdoc/tom_doc.rb +1 -0
  132. data/lib/rdoc/top_level.rb +1 -0
  133. data/rdoc.gemspec +60 -0
  134. metadata +32 -155
  135. data/Manifest.txt +0 -309
  136. data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
  137. data/lib/rdoc/markdown/literals_1_8.rb +0 -416
  138. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
  139. data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
  140. data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
  141. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
  142. data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
  143. data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
  144. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
  145. data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
  146. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
  147. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
  148. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
  149. data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
  150. data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
  151. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
  152. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
  153. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
  154. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
  155. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
  156. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
  157. data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
  158. data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
  159. data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
  160. data/test/README +0 -1
  161. data/test/binary.dat +0 -0
  162. data/test/hidden.zip.txt +0 -1
  163. data/test/test.ja.largedoc +0 -3
  164. data/test/test.ja.rdoc +0 -10
  165. data/test/test.ja.txt +0 -8
  166. data/test/test.txt +0 -1
  167. data/test/test_rdoc_alias.rb +0 -13
  168. data/test/test_rdoc_any_method.rb +0 -460
  169. data/test/test_rdoc_attr.rb +0 -190
  170. data/test/test_rdoc_class_module.rb +0 -1492
  171. data/test/test_rdoc_code_object.rb +0 -450
  172. data/test/test_rdoc_comment.rb +0 -504
  173. data/test/test_rdoc_constant.rb +0 -181
  174. data/test/test_rdoc_context.rb +0 -901
  175. data/test/test_rdoc_context_section.rb +0 -130
  176. data/test/test_rdoc_cross_reference.rb +0 -192
  177. data/test/test_rdoc_encoding.rb +0 -227
  178. data/test/test_rdoc_extend.rb +0 -94
  179. data/test/test_rdoc_generator_darkfish.rb +0 -229
  180. data/test/test_rdoc_generator_json_index.rb +0 -324
  181. data/test/test_rdoc_generator_markup.rb +0 -59
  182. data/test/test_rdoc_generator_pot.rb +0 -91
  183. data/test/test_rdoc_generator_pot_po.rb +0 -51
  184. data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
  185. data/test/test_rdoc_generator_ri.rb +0 -78
  186. data/test/test_rdoc_i18n_locale.rb +0 -73
  187. data/test/test_rdoc_i18n_text.rb +0 -123
  188. data/test/test_rdoc_include.rb +0 -108
  189. data/test/test_rdoc_markdown.rb +0 -980
  190. data/test/test_rdoc_markdown_test.rb +0 -1884
  191. data/test/test_rdoc_markup.rb +0 -95
  192. data/test/test_rdoc_markup_attribute_manager.rb +0 -364
  193. data/test/test_rdoc_markup_attributes.rb +0 -39
  194. data/test/test_rdoc_markup_document.rb +0 -207
  195. data/test/test_rdoc_markup_formatter.rb +0 -175
  196. data/test/test_rdoc_markup_hard_break.rb +0 -31
  197. data/test/test_rdoc_markup_heading.rb +0 -29
  198. data/test/test_rdoc_markup_include.rb +0 -19
  199. data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
  200. data/test/test_rdoc_markup_paragraph.rb +0 -32
  201. data/test/test_rdoc_markup_parser.rb +0 -1680
  202. data/test/test_rdoc_markup_pre_process.rb +0 -473
  203. data/test/test_rdoc_markup_raw.rb +0 -22
  204. data/test/test_rdoc_markup_to_ansi.rb +0 -369
  205. data/test/test_rdoc_markup_to_bs.rb +0 -366
  206. data/test/test_rdoc_markup_to_html.rb +0 -662
  207. data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
  208. data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
  209. data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
  210. data/test/test_rdoc_markup_to_label.rb +0 -112
  211. data/test/test_rdoc_markup_to_markdown.rb +0 -389
  212. data/test/test_rdoc_markup_to_rdoc.rb +0 -377
  213. data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
  214. data/test/test_rdoc_markup_to_tt_only.rb +0 -246
  215. data/test/test_rdoc_markup_verbatim.rb +0 -29
  216. data/test/test_rdoc_method_attr.rb +0 -193
  217. data/test/test_rdoc_normal_class.rb +0 -47
  218. data/test/test_rdoc_normal_module.rb +0 -42
  219. data/test/test_rdoc_options.rb +0 -766
  220. data/test/test_rdoc_parser.rb +0 -327
  221. data/test/test_rdoc_parser_c.rb +0 -1896
  222. data/test/test_rdoc_parser_changelog.rb +0 -315
  223. data/test/test_rdoc_parser_markdown.rb +0 -61
  224. data/test/test_rdoc_parser_rd.rb +0 -55
  225. data/test/test_rdoc_parser_ruby.rb +0 -3322
  226. data/test/test_rdoc_parser_simple.rb +0 -115
  227. data/test/test_rdoc_rd.rb +0 -30
  228. data/test/test_rdoc_rd_block_parser.rb +0 -535
  229. data/test/test_rdoc_rd_inline.rb +0 -63
  230. data/test/test_rdoc_rd_inline_parser.rb +0 -177
  231. data/test/test_rdoc_rdoc.rb +0 -455
  232. data/test/test_rdoc_require.rb +0 -25
  233. data/test/test_rdoc_ri_driver.rb +0 -1436
  234. data/test/test_rdoc_ri_paths.rb +0 -155
  235. data/test/test_rdoc_ruby_lex.rb +0 -421
  236. data/test/test_rdoc_ruby_token.rb +0 -19
  237. data/test/test_rdoc_rubygems_hook.rb +0 -251
  238. data/test/test_rdoc_servlet.rb +0 -534
  239. data/test/test_rdoc_single_class.rb +0 -20
  240. data/test/test_rdoc_stats.rb +0 -722
  241. data/test/test_rdoc_store.rb +0 -993
  242. data/test/test_rdoc_task.rb +0 -173
  243. data/test/test_rdoc_text.rb +0 -557
  244. data/test/test_rdoc_token_stream.rb +0 -42
  245. data/test/test_rdoc_tom_doc.rb +0 -520
  246. data/test/test_rdoc_top_level.rb +0 -287
  247. data/test/xref_data.rb +0 -76
  248. data/test/xref_test_case.rb +0 -67
@@ -1,1884 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'pp'
4
-
5
- require 'rdoc'
6
- require 'rdoc/markdown'
7
-
8
- class TestRDocMarkdownTest < RDoc::TestCase
9
-
10
- MARKDOWN_TEST_PATH = File.expand_path '../MarkdownTest_1.0.3/', __FILE__
11
-
12
- def setup
13
- super
14
-
15
- @parser = RDoc::Markdown.new
16
- end
17
-
18
- def test_amps_and_angle_encoding
19
- input = File.read "#{MARKDOWN_TEST_PATH}/Amps and angle encoding.text"
20
-
21
- doc = @parser.parse input
22
-
23
- expected =
24
- doc(
25
- para("AT&T has an ampersand in their name."),
26
- para("AT&T is another way to write it."),
27
- para("This & that."),
28
- para("4 < 5."),
29
- para("6 > 5."),
30
- para("Here's a {link}[http://example.com/?foo=1&bar=2] with " +
31
- "an ampersand in the URL."),
32
- para("Here's a link with an amersand in the link text: " +
33
- "{AT&T}[http://att.com/]."),
34
- para("Here's an inline {link}[/script?foo=1&bar=2]."),
35
- para("Here's an inline {link}[/script?foo=1&bar=2]."))
36
-
37
- assert_equal expected, doc
38
- end
39
-
40
- def test_auto_links
41
- input = File.read "#{MARKDOWN_TEST_PATH}/Auto links.text"
42
-
43
- doc = @parser.parse input
44
-
45
- # TODO verify rdoc auto-links too
46
- expected =
47
- doc(
48
- para("Link: http://example.com/."),
49
- para("With an ampersand: http://example.com/?foo=1&bar=2"),
50
- list(:BULLET,
51
- item(nil, para("In a list?")),
52
- item(nil, para("http://example.com/")),
53
- item(nil, para("It should."))),
54
- block(
55
- para("Blockquoted: http://example.com/")),
56
- para("Auto-links should not occur here: " +
57
- "<code><http://example.com/></code>"),
58
- verb("or here: <http://example.com/>\n"))
59
-
60
- assert_equal expected, doc
61
- end
62
-
63
- def test_backslash_escapes
64
- input = File.read "#{MARKDOWN_TEST_PATH}/Backslash escapes.text"
65
-
66
- doc = @parser.parse input
67
-
68
- expected =
69
- doc(
70
- para("These should all get escaped:"),
71
-
72
- para("Backslash: \\"),
73
- para("Backtick: `"),
74
- para("Asterisk: *"),
75
- para("Underscore: _"),
76
- para("Left brace: {"),
77
- para("Right brace: }"),
78
- para("Left bracket: ["),
79
- para("Right bracket: ]"),
80
- para("Left paren: ("),
81
- para("Right paren: )"),
82
- para("Greater-than: >"),
83
- para("Hash: #"),
84
- para("Period: ."),
85
- para("Bang: !"),
86
- para("Plus: +"),
87
- para("Minus: -"),
88
-
89
- para("These should not, because they occur within a code block:"),
90
-
91
- verb("Backslash: \\\\\n",
92
- "\n",
93
- "Backtick: \\`\n",
94
- "\n",
95
- "Asterisk: \\*\n",
96
- "\n",
97
- "Underscore: \\_\n",
98
- "\n",
99
- "Left brace: \\{\n",
100
- "\n",
101
- "Right brace: \\}\n",
102
- "\n",
103
- "Left bracket: \\[\n",
104
- "\n",
105
- "Right bracket: \\]\n",
106
- "\n",
107
- "Left paren: \\(\n",
108
- "\n",
109
- "Right paren: \\)\n",
110
- "\n",
111
- "Greater-than: \\>\n",
112
- "\n",
113
- "Hash: \\#\n",
114
- "\n",
115
- "Period: \\.\n",
116
- "\n",
117
- "Bang: \\!\n",
118
- "\n",
119
- "Plus: \\+\n",
120
- "\n",
121
- "Minus: \\-\n"),
122
-
123
- para("Nor should these, which occur in code spans:"),
124
-
125
- para("Backslash: <code>\\\\</code>"),
126
- para("Backtick: <code>\\`</code>"),
127
- para("Asterisk: <code>\\*</code>"),
128
- para("Underscore: <code>\\_</code>"),
129
- para("Left brace: <code>\\{</code>"),
130
- para("Right brace: <code>\\}</code>"),
131
- para("Left bracket: <code>\\[</code>"),
132
- para("Right bracket: <code>\\]</code>"),
133
- para("Left paren: <code>\\(</code>"),
134
- para("Right paren: <code>\\)</code>"),
135
- para("Greater-than: <code>\\></code>"),
136
- para("Hash: <code>\\#</code>"),
137
- para("Period: <code>\\.</code>"),
138
- para("Bang: <code>\\!</code>"),
139
- para("Plus: <code>\\+</code>"),
140
- para("Minus: <code>\\-</code>"),
141
-
142
- para("These should get escaped, even though they're matching pairs for\n" +
143
- "other Markdown constructs:"),
144
-
145
- para("\*asterisks\*"),
146
- para("\_underscores\_"),
147
- para("`backticks`"),
148
-
149
- para("This is a code span with a literal backslash-backtick " +
150
- "sequence: <code>\\`</code>"),
151
-
152
- para("This is a tag with unescaped backticks " +
153
- "<span attr='`ticks`'>bar</span>."),
154
-
155
- para("This is a tag with backslashes " +
156
- "<span attr='\\\\backslashes\\\\'>bar</span>."))
157
-
158
- assert_equal expected, doc
159
- end
160
-
161
- def test_blockquotes_with_code_blocks
162
- input = File.read "#{MARKDOWN_TEST_PATH}/Blockquotes with code blocks.text"
163
-
164
- doc = @parser.parse input
165
-
166
- expected =
167
- doc(
168
- block(
169
- para("Example:"),
170
- verb("sub status {\n",
171
- " print \"working\";\n",
172
- "}\n"),
173
- para("Or:"),
174
- verb("sub status {\n",
175
- " return \"working\";\n",
176
- "}\n")))
177
-
178
- assert_equal expected, doc
179
- end
180
-
181
- def test_code_blocks
182
- input = File.read "#{MARKDOWN_TEST_PATH}/Code Blocks.text"
183
-
184
- doc = @parser.parse input
185
-
186
- expected =
187
- doc(
188
- verb("code block on the first line\n"),
189
- para("Regular text."),
190
-
191
- verb("code block indented by spaces\n"),
192
- para("Regular text."),
193
-
194
- verb("the lines in this block \n",
195
- "all contain trailing spaces \n"),
196
- para("Regular Text."),
197
-
198
- verb("code block on the last line\n"))
199
-
200
- assert_equal expected, doc
201
- end
202
-
203
- def test_code_spans
204
- input = File.read "#{MARKDOWN_TEST_PATH}/Code Spans.text"
205
-
206
- doc = @parser.parse input
207
-
208
- expected = doc(
209
- para("<code><test a=\"</code> content of attribute <code>\"></code>"),
210
- para("Fix for backticks within HTML tag: " +
211
- "<span attr='`ticks`'>like this</span>"),
212
- para("Here's how you put <code>`backticks`</code> in a code span."))
213
-
214
- assert_equal expected, doc
215
- end
216
-
217
- def test_hard_wrapped_paragraphs_with_list_like_lines
218
- input = File.read "#{MARKDOWN_TEST_PATH}/Hard-wrapped paragraphs with list-like lines.text"
219
-
220
- doc = @parser.parse input
221
-
222
- expected =
223
- doc(
224
- para("In Markdown 1.0.0 and earlier. Version\n" +
225
- "8. This line turns into a list item.\n" +
226
- "Because a hard-wrapped line in the\n" +
227
- "middle of a paragraph looked like a\n" +
228
- "list item."),
229
- para("Here's one with a bullet.\n" +
230
- "* criminey."))
231
-
232
- assert_equal expected, doc
233
- end
234
-
235
- def test_horizontal_rules
236
- input = File.read "#{MARKDOWN_TEST_PATH}/Horizontal rules.text"
237
-
238
- doc = @parser.parse input
239
-
240
- expected =
241
- doc(
242
- para("Dashes:"),
243
-
244
- rule(1),
245
- rule(1),
246
- rule(1),
247
- rule(1),
248
- verb("---\n"),
249
-
250
- rule(1),
251
- rule(1),
252
- rule(1),
253
- rule(1),
254
- verb("- - -\n"),
255
-
256
- para("Asterisks:"),
257
-
258
- rule(1),
259
- rule(1),
260
- rule(1),
261
- rule(1),
262
- verb("***\n"),
263
-
264
- rule(1),
265
- rule(1),
266
- rule(1),
267
- rule(1),
268
- verb("* * *\n"),
269
-
270
- para("Underscores:"),
271
-
272
- rule(1),
273
- rule(1),
274
- rule(1),
275
- rule(1),
276
- verb("___\n"),
277
-
278
- rule(1),
279
- rule(1),
280
- rule(1),
281
- rule(1),
282
- verb("_ _ _\n"))
283
-
284
- assert_equal expected, doc
285
- end
286
-
287
- def test_inline_html_advanced
288
- input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML (Advanced).text"
289
-
290
- @parser.html = true
291
-
292
- doc = @parser.parse input
293
-
294
- expected =
295
- doc(
296
- para("Simple block on one line:"),
297
- raw("<div>foo</div>"),
298
- para("And nested without indentation:"),
299
- raw(<<-RAW.chomp))
300
- <div>
301
- <div>
302
- <div>
303
- foo
304
- </div>
305
- <div style=">"/>
306
- </div>
307
- <div>bar</div>
308
- </div>
309
- RAW
310
-
311
- assert_equal expected, doc
312
- end
313
-
314
- def test_inline_html_simple
315
- input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML (Simple).text"
316
-
317
- @parser.html = true
318
-
319
- doc = @parser.parse input
320
-
321
- expected =
322
- doc(
323
- para("Here's a simple block:"),
324
- raw("<div>\n\tfoo\n</div>"),
325
-
326
- para("This should be a code block, though:"),
327
- verb("<div>\n",
328
- "\tfoo\n",
329
- "</div>\n"),
330
-
331
- para("As should this:"),
332
- verb("<div>foo</div>\n"),
333
-
334
- para("Now, nested:"),
335
- raw("<div>\n\t<div>\n\t\t<div>\n\t\t\tfoo\n" +
336
- "\t\t</div>\n\t</div>\n</div>"),
337
-
338
- para("This should just be an HTML comment:"),
339
- raw("<!-- Comment -->"),
340
-
341
- para("Multiline:"),
342
- raw("<!--\nBlah\nBlah\n-->"),
343
-
344
- para("Code block:"),
345
- verb("<!-- Comment -->\n"),
346
-
347
- para("Just plain comment, with trailing spaces on the line:"),
348
- raw("<!-- foo -->"),
349
-
350
- para("Code:"),
351
- verb("<hr />\n"),
352
-
353
- para("Hr's:"),
354
- raw("<hr>"),
355
- raw("<hr/>"),
356
- raw("<hr />"),
357
-
358
- raw("<hr>"),
359
- raw("<hr/>"),
360
- raw("<hr />"),
361
-
362
- raw("<hr class=\"foo\" id=\"bar\" />"),
363
- raw("<hr class=\"foo\" id=\"bar\"/>"),
364
- raw("<hr class=\"foo\" id=\"bar\" >"))
365
-
366
- assert_equal expected, doc
367
- end
368
-
369
- def test_inline_html_comments
370
- input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML comments.text"
371
-
372
- doc = @parser.parse input
373
-
374
- expected =
375
- doc(
376
- para("Paragraph one."),
377
-
378
- raw("<!-- This is a simple comment -->"),
379
-
380
- raw("<!--\n\tThis is another comment.\n-->"),
381
-
382
- para("Paragraph two."),
383
-
384
- raw("<!-- one comment block -- -- with two comments -->"),
385
-
386
- para("The end."))
387
-
388
- assert_equal expected, doc
389
- end
390
-
391
- def test_links_inline_style
392
- input = File.read "#{MARKDOWN_TEST_PATH}/Links, inline style.text"
393
-
394
- doc = @parser.parse input
395
-
396
- expected =
397
- doc(
398
- para("Just a {URL}[/url/]."),
399
- para("{URL and title}[/url/]."),
400
- para("{URL and title}[/url/]."),
401
- para("{URL and title}[/url/]."),
402
- para("{URL and title}[/url/]."),
403
- para("{Empty}[]."))
404
-
405
- assert_equal expected, doc
406
- end
407
-
408
- def test_links_reference_style
409
- input = File.read "#{MARKDOWN_TEST_PATH}/Links, reference style.text"
410
-
411
- doc = @parser.parse input
412
-
413
- expected =
414
- doc(
415
- para("Foo {bar}[/url/]."),
416
- para("Foo {bar}[/url/]."),
417
- para("Foo {bar}[/url/]."),
418
-
419
- para("With {embedded [brackets]}[/url/]."),
420
-
421
- para("Indented {once}[/url]."),
422
- para("Indented {twice}[/url]."),
423
- para("Indented {thrice}[/url]."),
424
- para("Indented [four][] times."),
425
-
426
- verb("[four]: /url\n"),
427
-
428
- rule(1),
429
-
430
- para("{this}[foo] should work"),
431
- para("So should {this}[foo]."),
432
- para("And {this}[foo]."),
433
- para("And {this}[foo]."),
434
- para("And {this}[foo]."),
435
-
436
- para("But not [that] []."),
437
- para("Nor [that][]."),
438
- para("Nor [that]."),
439
-
440
- para("[Something in brackets like {this}[foo] should work]"),
441
- para("[Same with {this}[foo].]"),
442
-
443
- para("In this case, {this}[/somethingelse/] points to something else."),
444
- para("Backslashing should suppress [this] and [this]."),
445
-
446
- rule(1),
447
-
448
- para("Here's one where the {link breaks}[/url/] across lines."),
449
- para("Here's another where the {link breaks}[/url/] across lines, " +
450
- "but with a line-ending space."))
451
-
452
- assert_equal expected, doc
453
- end
454
-
455
- def test_links_shortcut_references
456
- input = File.read "#{MARKDOWN_TEST_PATH}/Links, shortcut references.text"
457
-
458
- doc = @parser.parse input
459
-
460
- expected =
461
- doc(
462
- para("This is the {simple case}[/simple]."),
463
- para("This one has a {line break}[/foo]."),
464
- para("This one has a {line break}[/foo] with a line-ending space."),
465
- para("{this}[/that] and the {other}[/other]"))
466
-
467
- assert_equal expected, doc
468
- end
469
-
470
- def test_literal_quotes_in_titles
471
- input = File.read "#{MARKDOWN_TEST_PATH}/Literal quotes in titles.text"
472
-
473
- doc = @parser.parse input
474
-
475
- # TODO support title attribute
476
- expected =
477
- doc(
478
- para("Foo {bar}[/url/]."),
479
- para("Foo {bar}[/url/]."))
480
-
481
- assert_equal expected, doc
482
- end
483
-
484
- def test_markdown_documentation_basics
485
- input = File.read "#{MARKDOWN_TEST_PATH}/Markdown Documentation - Basics.text"
486
-
487
- doc = @parser.parse input
488
-
489
- expected =
490
- doc(
491
- head(1, "Markdown: Basics"),
492
-
493
- raw(<<-RAW.chomp),
494
- <ul id="ProjectSubmenu">
495
- <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
496
- <li><a class="selected" title="Markdown Basics">Basics</a></li>
497
- <li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li>
498
- <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
499
- <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
500
- </ul>
501
- RAW
502
-
503
- head(2, "Getting the Gist of Markdown's Formatting Syntax"),
504
-
505
- para("This page offers a brief overview of what it's like to use Markdown.\n" +
506
- "The {syntax page}[/projects/markdown/syntax] provides complete, detailed documentation for\n" +
507
- "every feature, but Markdown should be very easy to pick up simply by\n" +
508
- "looking at a few examples of it in action. The examples on this page\n" +
509
- "are written in a before/after style, showing example syntax and the\n" +
510
- "HTML output produced by Markdown."),
511
-
512
- para("It's also helpful to simply try Markdown out; the {Dingus}[/projects/markdown/dingus] is a\n" +
513
- "web application that allows you type your own Markdown-formatted text\n" +
514
- "and translate it to XHTML."),
515
-
516
- para("<b>Note:</b> This document is itself written using Markdown; you\n" +
517
- "can {see the source for it by adding '.text' to the URL}[/projects/markdown/basics.text]."),
518
-
519
- head(2, "Paragraphs, Headers, Blockquotes"),
520
-
521
- para("A paragraph is simply one or more consecutive lines of text, separated\n" +
522
- "by one or more blank lines. (A blank line is any line that looks like a\n" +
523
- "blank line -- a line containing nothing spaces or tabs is considered\n" +
524
- "blank.) Normal paragraphs should not be intended with spaces or tabs."),
525
-
526
- para("Markdown offers two styles of headers: _Setext_ and _atx_.\n" +
527
- "Setext-style headers for <code><h1></code> and <code><h2></code> are created by\n" +
528
- "\"underlining\" with equal signs (<code>=</code>) and hyphens (<code>-</code>), respectively.\n" +
529
- "To create an atx-style header, you put 1-6 hash marks (<code>#</code>) at the\n" +
530
- "beginning of the line -- the number of hashes equals the resulting\n" +
531
- "HTML header level."),
532
-
533
- para("Blockquotes are indicated using email-style '<code>></code>' angle brackets."),
534
-
535
- para("Markdown:"),
536
-
537
- verb("A First Level Header\n",
538
- "====================\n",
539
- "\n",
540
- "A Second Level Header\n",
541
- "---------------------\n",
542
- "\n",
543
- "Now is the time for all good men to come to\n",
544
- "the aid of their country. This is just a\n",
545
- "regular paragraph.\n",
546
- "\n",
547
- "The quick brown fox jumped over the lazy\n",
548
- "dog's back.\n",
549
- "\n",
550
- "### Header 3\n",
551
- "\n",
552
- "> This is a blockquote.\n",
553
- "> \n",
554
- "> This is the second paragraph in the blockquote.\n",
555
- ">\n",
556
- "> ## This is an H2 in a blockquote\n"),
557
-
558
- para("Output:"),
559
-
560
- verb("<h1>A First Level Header</h1>\n",
561
- "\n",
562
- "<h2>A Second Level Header</h2>\n",
563
- "\n",
564
- "<p>Now is the time for all good men to come to\n",
565
- "the aid of their country. This is just a\n",
566
- "regular paragraph.</p>\n",
567
- "\n",
568
- "<p>The quick brown fox jumped over the lazy\n",
569
- "dog's back.</p>\n",
570
- "\n",
571
- "<h3>Header 3</h3>\n",
572
- "\n",
573
- "<blockquote>\n",
574
- " <p>This is a blockquote.</p>\n",
575
- "\n",
576
- " <p>This is the second paragraph in the blockquote.</p>\n",
577
- "\n",
578
- " <h2>This is an H2 in a blockquote</h2>\n",
579
- "</blockquote>\n"),
580
-
581
- head(3, "Phrase Emphasis"),
582
- para("Markdown uses asterisks and underscores to indicate spans of emphasis."),
583
-
584
- para("Markdown:"),
585
-
586
- verb("Some of these words *are emphasized*.\n",
587
- "Some of these words _are emphasized also_.\n",
588
- "\n",
589
- "Use two asterisks for **strong emphasis**.\n",
590
- "Or, if you prefer, __use two underscores instead__.\n"),
591
-
592
- para("Output:"),
593
-
594
- verb("<p>Some of these words <em>are emphasized</em>.\n",
595
- "Some of these words <em>are emphasized also</em>.</p>\n",
596
- "\n",
597
- "<p>Use two asterisks for <strong>strong emphasis</strong>.\n",
598
- "Or, if you prefer, <strong>use two underscores instead</strong>.</p>\n"),
599
-
600
- head(2, "Lists"),
601
-
602
- para("Unordered (bulleted) lists use asterisks, pluses, and hyphens (<code>*</code>,\n" +
603
- "<code>+</code>, and <code>-</code>) as list markers. These three markers are\n" +
604
- "interchangable; this:"),
605
-
606
- verb("* Candy.\n",
607
- "* Gum.\n",
608
- "* Booze.\n"),
609
-
610
- para("this:"),
611
-
612
- verb("+ Candy.\n",
613
- "+ Gum.\n",
614
- "+ Booze.\n"),
615
-
616
- para("and this:"),
617
-
618
- verb("- Candy.\n",
619
- "- Gum.\n",
620
- "- Booze.\n"),
621
-
622
- para("all produce the same output:"),
623
-
624
- verb("<ul>\n",
625
- "<li>Candy.</li>\n",
626
- "<li>Gum.</li>\n",
627
- "<li>Booze.</li>\n",
628
- "</ul>\n"),
629
-
630
- para("Ordered (numbered) lists use regular numbers, followed by periods, as\n" +
631
- "list markers:"),
632
-
633
- verb("1. Red\n",
634
- "2. Green\n",
635
- "3. Blue\n"),
636
-
637
- para("Output:"),
638
-
639
- verb("<ol>\n",
640
- "<li>Red</li>\n",
641
- "<li>Green</li>\n",
642
- "<li>Blue</li>\n",
643
- "</ol>\n"),
644
-
645
- para("If you put blank lines between items, you'll get <code><p></code> tags for the\n" +
646
- "list item text. You can create multi-paragraph list items by indenting\n" +
647
- "the paragraphs by 4 spaces or 1 tab:"),
648
-
649
- verb("* A list item.\n",
650
- "\n",
651
- " With multiple paragraphs.\n",
652
- "\n",
653
- "* Another item in the list.\n"),
654
-
655
- para("Output:"),
656
-
657
- verb("<ul>\n",
658
- "<li><p>A list item.</p>\n",
659
- "<p>With multiple paragraphs.</p></li>\n",
660
- "<li><p>Another item in the list.</p></li>\n",
661
- "</ul>\n"),
662
-
663
- head(3, "Links"),
664
-
665
- para("Markdown supports two styles for creating links: _inline_ and\n" +
666
- "_reference_. With both styles, you use square brackets to delimit the\n" +
667
- "text you want to turn into a link."),
668
-
669
- para("Inline-style links use parentheses immediately after the link text.\n" +
670
- "For example:"),
671
-
672
- verb("This is an [example link](http://example.com/).\n"),
673
-
674
- para("Output:"),
675
-
676
- verb("<p>This is an <a href=\"http://example.com/\">\n",
677
- "example link</a>.</p>\n"),
678
-
679
- para("Optionally, you may include a title attribute in the parentheses:"),
680
-
681
- verb("This is an [example link](http://example.com/ \"With a Title\").\n"),
682
-
683
- para("Output:"),
684
-
685
- verb("<p>This is an <a href=\"http://example.com/\" title=\"With a Title\">\n",
686
- "example link</a>.</p>\n"),
687
-
688
- para("Reference-style links allow you to refer to your links by names, which\n" +
689
- "you define elsewhere in your document:"),
690
-
691
- verb("I get 10 times more traffic from [Google][1] than from\n",
692
- "[Yahoo][2] or [MSN][3].\n",
693
- "\n",
694
- "[1]: http://google.com/ \"Google\"\n",
695
- "[2]: http://search.yahoo.com/ \"Yahoo Search\"\n",
696
- "[3]: http://search.msn.com/ \"MSN Search\"\n"),
697
-
698
- para("Output:"),
699
-
700
- verb("<p>I get 10 times more traffic from <a href=\"http://google.com/\"\n",
701
- "title=\"Google\">Google</a> than from <a href=\"http://search.yahoo.com/\"\n",
702
- "title=\"Yahoo Search\">Yahoo</a> or <a href=\"http://search.msn.com/\"\n",
703
- "title=\"MSN Search\">MSN</a>.</p>\n"),
704
-
705
- para("The title attribute is optional. Link names may contain letters,\n" +
706
- "numbers and spaces, but are _not_ case sensitive:"),
707
-
708
- verb("I start my morning with a cup of coffee and\n",
709
- "[The New York Times][NY Times].\n",
710
- "\n",
711
- "[ny times]: http://www.nytimes.com/\n"),
712
-
713
- para("Output:"),
714
-
715
- verb("<p>I start my morning with a cup of coffee and\n",
716
- "<a href=\"http://www.nytimes.com/\">The New York Times</a>.</p>\n"),
717
-
718
- head(3, "Images"),
719
-
720
- para("Image syntax is very much like link syntax."),
721
-
722
- para("Inline (titles are optional):"),
723
-
724
- verb("![alt text](/path/to/img.jpg \"Title\")\n"),
725
-
726
- para("Reference-style:"),
727
-
728
- verb("![alt text][id]\n",
729
- "\n",
730
- "[id]: /path/to/img.jpg \"Title\"\n"),
731
-
732
- para("Both of the above examples produce the same output:"),
733
-
734
- verb("<img src=\"/path/to/img.jpg\" alt=\"alt text\" title=\"Title\" />\n"),
735
-
736
- head(3, "Code"),
737
-
738
- para("In a regular paragraph, you can create code span by wrapping text in\n" +
739
- "backtick quotes. Any ampersands (<code>&</code>) and angle brackets (<code><</code> or\n" +
740
- "<code>></code>) will automatically be translated into HTML entities. This makes\n" +
741
- "it easy to use Markdown to write about HTML example code:"),
742
-
743
- verb(
744
- "I strongly recommend against using any `<blink>` tags.\n",
745
- "\n",
746
- "I wish SmartyPants used named entities like `&mdash;`\n",
747
- "instead of decimal-encoded entites like `&#8212;`.\n"),
748
-
749
- para("Output:"),
750
-
751
- verb("<p>I strongly recommend against using any\n",
752
- "<code>&lt;blink&gt;</code> tags.</p>\n",
753
- "\n",
754
- "<p>I wish SmartyPants used named entities like\n",
755
- "<code>&amp;mdash;</code> instead of decimal-encoded\n",
756
- "entites like <code>&amp;#8212;</code>.</p>\n"),
757
-
758
- para("To specify an entire block of pre-formatted code, indent every line of\n" +
759
- "the block by 4 spaces or 1 tab. Just like with code spans, <code>&</code>, <code><</code>,\n" +
760
- "and <code>></code> characters will be escaped automatically."),
761
-
762
- para("Markdown:"),
763
-
764
- verb("If you want your page to validate under XHTML 1.0 Strict,\n",
765
- "you've got to put paragraph tags in your blockquotes:\n",
766
- "\n",
767
- " <blockquote>\n",
768
- " <p>For example.</p>\n",
769
- " </blockquote>\n"),
770
-
771
- para("Output:"),
772
-
773
- verb("<p>If you want your page to validate under XHTML 1.0 Strict,\n",
774
- "you've got to put paragraph tags in your blockquotes:</p>\n",
775
- "\n",
776
- "<pre><code>&lt;blockquote&gt;\n",
777
- " &lt;p&gt;For example.&lt;/p&gt;\n",
778
- "&lt;/blockquote&gt;\n",
779
- "</code></pre>\n"))
780
-
781
- assert_equal expected, doc
782
- end
783
-
784
- def test_markdown_documentation_syntax
785
- input = File.read "#{MARKDOWN_TEST_PATH}/Markdown Documentation - Syntax.text"
786
-
787
- doc = @parser.parse input
788
-
789
- expected =
790
- doc(
791
- head(1, "Markdown: Syntax"),
792
-
793
- raw(<<-RAW.chomp),
794
- <ul id="ProjectSubmenu">
795
- <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
796
- <li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
797
- <li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
798
- <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
799
- <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
800
- </ul>
801
- RAW
802
-
803
- list(:BULLET,
804
- item(nil,
805
- para("{Overview}[#overview]"),
806
- list(:BULLET,
807
- item(nil,
808
- para("{Philosophy}[#philosophy]")),
809
- item(nil,
810
- para("{Inline HTML}[#html]")),
811
- item(nil,
812
- para("{Automatic Escaping for Special Characters}[#autoescape]")))),
813
- item(nil,
814
- para("{Block Elements}[#block]"),
815
- list(:BULLET,
816
- item(nil,
817
- para("{Paragraphs and Line Breaks}[#p]")),
818
- item(nil,
819
- para("{Headers}[#header]")),
820
- item(nil,
821
- para("{Blockquotes}[#blockquote]")),
822
- item(nil,
823
- para("{Lists}[#list]")),
824
- item(nil,
825
- para("{Code Blocks}[#precode]")),
826
- item(nil,
827
- para("{Horizontal Rules}[#hr]")))),
828
- item(nil,
829
- para("{Span Elements}[#span]"),
830
- list(:BULLET,
831
- item(nil,
832
- para("{Links}[#link]")),
833
- item(nil,
834
- para("{Emphasis}[#em]")),
835
- item(nil,
836
- para("{Code}[#code]")),
837
- item(nil,
838
- para("{Images}[#img]")))),
839
- item(nil,
840
- para("{Miscellaneous}[#misc]"),
841
- list(:BULLET,
842
- item(nil,
843
- para("{Backslash Escapes}[#backslash]")),
844
- item(nil,
845
- para("{Automatic Links}[#autolink]"))))),
846
-
847
- para("<b>Note:</b> This document is itself written using Markdown; you\n" +
848
- "can {see the source for it by adding '.text' to the URL}[/projects/markdown/syntax.text]."),
849
-
850
- rule(1),
851
-
852
- raw("<h2 id=\"overview\">Overview</h2>"),
853
-
854
- raw("<h3 id=\"philosophy\">Philosophy</h3>"),
855
-
856
- para("Markdown is intended to be as easy-to-read and easy-to-write as is feasible."),
857
-
858
- para("Readability, however, is emphasized above all else. A Markdown-formatted\n" +
859
- "document should be publishable as-is, as plain text, without looking\n" +
860
- "like it's been marked up with tags or formatting instructions. While\n" +
861
- "Markdown's syntax has been influenced by several existing text-to-HTML\n" +
862
- "filters -- including {Setext}[http://docutils.sourceforge.net/mirror/setext.html], {atx}[http://www.aaronsw.com/2002/atx/], {Textile}[http://textism.com/tools/textile/], {reStructuredText}[http://docutils.sourceforge.net/rst.html],\n" +
863
- "{Grutatext}[http://www.triptico.com/software/grutatxt.html], and {EtText}[http://ettext.taint.org/doc/] -- the single biggest source of\n" +
864
- "inspiration for Markdown's syntax is the format of plain text email."),
865
-
866
- para("To this end, Markdown's syntax is comprised entirely of punctuation\n" +
867
- "characters, which punctuation characters have been carefully chosen so\n" +
868
- "as to look like what they mean. E.g., asterisks around a word actually\n" +
869
- "look like \*emphasis\*. Markdown lists look like, well, lists. Even\n" +
870
- "blockquotes look like quoted passages of text, assuming you've ever\n" +
871
- "used email."),
872
-
873
- raw("<h3 id=\"html\">Inline HTML</h3>"),
874
-
875
- para("Markdown's syntax is intended for one purpose: to be used as a\n" +
876
- "format for _writing_ for the web."),
877
-
878
- para("Markdown is not a replacement for HTML, or even close to it. Its\n" +
879
- "syntax is very small, corresponding only to a very small subset of\n" +
880
- "HTML tags. The idea is _not_ to create a syntax that makes it easier\n" +
881
- "to insert HTML tags. In my opinion, HTML tags are already easy to\n" +
882
- "insert. The idea for Markdown is to make it easy to read, write, and\n" +
883
- "edit prose. HTML is a _publishing_ format; Markdown is a _writing_\n" +
884
- "format. Thus, Markdown's formatting syntax only addresses issues that\n" +
885
- "can be conveyed in plain text."),
886
-
887
- para("For any markup that is not covered by Markdown's syntax, you simply\n" +
888
- "use HTML itself. There's no need to preface it or delimit it to\n" +
889
- "indicate that you're switching from Markdown to HTML; you just use\n" +
890
- "the tags."),
891
-
892
- para("The only restrictions are that block-level HTML elements -- e.g. <code><div></code>,\n" +
893
- "<code><table></code>, <code><pre></code>, <code><p></code>, etc. -- must be separated from surrounding\n" +
894
- "content by blank lines, and the start and end tags of the block should\n" +
895
- "not be indented with tabs or spaces. Markdown is smart enough not\n" +
896
- "to add extra (unwanted) <code><p></code> tags around HTML block-level tags."),
897
-
898
- para("For example, to add an HTML table to a Markdown article:"),
899
-
900
- verb("This is a regular paragraph.\n",
901
- "\n",
902
- "<table>\n",
903
- " <tr>\n",
904
- " <td>Foo</td>\n",
905
- " </tr>\n",
906
- "</table>\n",
907
- "\n",
908
- "This is another regular paragraph.\n"),
909
-
910
- para("Note that Markdown formatting syntax is not processed within block-level\n" +
911
- "HTML tags. E.g., you can't use Markdown-style <code>*emphasis*</code> inside an\n" +
912
- "HTML block."),
913
-
914
- para("Span-level HTML tags -- e.g. <code><span></code>, <code><cite></code>, or <code><del></code> -- can be\n" +
915
- "used anywhere in a Markdown paragraph, list item, or header. If you\n" +
916
- "want, you can even use HTML tags instead of Markdown formatting; e.g. if\n" +
917
- "you'd prefer to use HTML <code><a></code> or <code><img></code> tags instead of Markdown's\n" +
918
- "link or image syntax, go right ahead."),
919
-
920
- para("Unlike block-level HTML tags, Markdown syntax _is_ processed within\n" +
921
- "span-level tags."),
922
-
923
- raw("<h3 id=\"autoescape\">Automatic Escaping for Special Characters</h3>"),
924
-
925
- para("In HTML, there are two characters that demand special treatment: <code><</code>\n" +
926
- "and <code>&</code>. Left angle brackets are used to start tags; ampersands are\n" +
927
- "used to denote HTML entities. If you want to use them as literal\n" +
928
- "characters, you must escape them as entities, e.g. <code>&lt;</code>, and\n" +
929
- "<code>&amp;</code>."),
930
-
931
- para("Ampersands in particular are bedeviling for web writers. If you want to\n" +
932
- "write about 'AT&T', you need to write '<code>AT&amp;T</code>'. You even need to\n" +
933
- "escape ampersands within URLs. Thus, if you want to link to:"),
934
-
935
- verb("http://images.google.com/images?num=30&q=larry+bird\n"),
936
-
937
- para("you need to encode the URL as:"),
938
-
939
- verb("http://images.google.com/images?num=30&amp;q=larry+bird\n"),
940
-
941
- para("in your anchor tag <code>href</code> attribute. Needless to say, this is easy to\n" +
942
- "forget, and is probably the single most common source of HTML validation\n" +
943
- "errors in otherwise well-marked-up web sites."),
944
-
945
- para("Markdown allows you to use these characters naturally, taking care of\n" +
946
- "all the necessary escaping for you. If you use an ampersand as part of\n" +
947
- "an HTML entity, it remains unchanged; otherwise it will be translated\n" +
948
- "into <code>&amp;</code>."),
949
-
950
- para("So, if you want to include a copyright symbol in your article, you can write:"),
951
-
952
- verb("&copy;\n"),
953
-
954
- para("and Markdown will leave it alone. But if you write:"),
955
-
956
- verb("AT&T\n"),
957
-
958
- para("Markdown will translate it to:"),
959
-
960
- verb("AT&amp;T\n"),
961
-
962
- para("Similarly, because Markdown supports {inline HTML}[#html], if you use\n" +
963
- "angle brackets as delimiters for HTML tags, Markdown will treat them as\n" +
964
- "such. But if you write:"),
965
-
966
- verb("4 < 5\n"),
967
-
968
- para("Markdown will translate it to:"),
969
-
970
- verb("4 &lt; 5\n"),
971
-
972
- para("However, inside Markdown code spans and blocks, angle brackets and\n" +
973
- "ampersands are _always_ encoded automatically. This makes it easy to use\n" +
974
- "Markdown to write about HTML code. (As opposed to raw HTML, which is a\n" +
975
- "terrible format for writing about HTML syntax, because every single <code><</code>\n" +
976
- "and <code>&</code> in your example code needs to be escaped.)"),
977
-
978
- rule(1),
979
-
980
- raw("<h2 id=\"block\">Block Elements</h2>"),
981
-
982
- raw("<h3 id=\"p\">Paragraphs and Line Breaks</h3>"),
983
-
984
- para("A paragraph is simply one or more consecutive lines of text, separated\n" +
985
- "by one or more blank lines. (A blank line is any line that looks like a\n" +
986
- "blank line -- a line containing nothing but spaces or tabs is considered\n" +
987
- "blank.) Normal paragraphs should not be intended with spaces or tabs."),
988
-
989
- para("The implication of the \"one or more consecutive lines of text\" rule is\n" +
990
- "that Markdown supports \"hard-wrapped\" text paragraphs. This differs\n" +
991
- "significantly from most other text-to-HTML formatters (including Movable\n" +
992
- "Type's \"Convert Line Breaks\" option) which translate every line break\n" +
993
- "character in a paragraph into a <code><br /></code> tag."),
994
-
995
- para("When you _do_ want to insert a <code><br /></code> break tag using Markdown, you\n" +
996
- "end a line with two or more spaces, then type return."),
997
-
998
- para("Yes, this takes a tad more effort to create a <code><br /></code>, but a simplistic\n" +
999
- "\"every line break is a <code><br /></code>\" rule wouldn't work for Markdown.\n" +
1000
- "Markdown's email-style {blockquoting}[#blockquote] and multi-paragraph {list items}[#list]\n" +
1001
- "work best -- and look better -- when you format them with hard breaks."),
1002
-
1003
- raw("<h3 id=\"header\">Headers</h3>"),
1004
-
1005
- para("Markdown supports two styles of headers, {Setext}[http://docutils.sourceforge.net/mirror/setext.html] and {atx}[http://www.aaronsw.com/2002/atx/]."),
1006
-
1007
- para("Setext-style headers are \"underlined\" using equal signs (for first-level\n" +
1008
- "headers) and dashes (for second-level headers). For example:"),
1009
-
1010
- verb("This is an H1\n",
1011
- "=============\n",
1012
- "\n",
1013
- "This is an H2\n",
1014
- "-------------\n"),
1015
-
1016
- para("Any number of underlining <code>=</code>'s or <code>-</code>'s will work."),
1017
-
1018
- para("Atx-style headers use 1-6 hash characters at the start of the line,\n" +
1019
- "corresponding to header levels 1-6. For example:"),
1020
-
1021
- verb("# This is an H1\n",
1022
- "\n",
1023
- "## This is an H2\n",
1024
- "\n",
1025
- "###### This is an H6\n"),
1026
-
1027
- para("Optionally, you may \"close\" atx-style headers. This is purely\n" +
1028
- "cosmetic -- you can use this if you think it looks better. The\n" +
1029
- "closing hashes don't even need to match the number of hashes\n" +
1030
- "used to open the header. (The number of opening hashes\n" +
1031
- "determines the header level.) :"),
1032
-
1033
- verb("# This is an H1 #\n",
1034
- "\n",
1035
- "## This is an H2 ##\n",
1036
- "\n",
1037
- "### This is an H3 ######\n"),
1038
-
1039
- raw("<h3 id=\"blockquote\">Blockquotes</h3>"),
1040
-
1041
- para(
1042
- "Markdown uses email-style <code>></code> characters for blockquoting. If you're\n" +
1043
- "familiar with quoting passages of text in an email message, then you\n" +
1044
- "know how to create a blockquote in Markdown. It looks best if you hard\n" +
1045
- "wrap the text and put a <code>></code> before every line:"),
1046
-
1047
- verb("> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,\n",
1048
- "> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.\n",
1049
- "> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.\n",
1050
- "> \n",
1051
- "> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse\n",
1052
- "> id sem consectetuer libero luctus adipiscing.\n"),
1053
-
1054
- para("Markdown allows you to be lazy and only put the <code>></code> before the first\n" +
1055
- "line of a hard-wrapped paragraph:"),
1056
-
1057
- verb("> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,\n",
1058
- "consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.\n",
1059
- "Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.\n",
1060
- "\n",
1061
- "> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse\n",
1062
- "id sem consectetuer libero luctus adipiscing.\n"),
1063
-
1064
- para("Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by\n" +
1065
- "adding additional levels of <code>></code>:"),
1066
-
1067
- verb("> This is the first level of quoting.\n",
1068
- ">\n",
1069
- "> > This is nested blockquote.\n",
1070
- ">\n",
1071
- "> Back to the first level.\n"),
1072
-
1073
- para("Blockquotes can contain other Markdown elements, including headers, lists,\n" +
1074
- "and code blocks:"),
1075
-
1076
- verb("> ## This is a header.\n",
1077
- "> \n",
1078
- "> 1. This is the first list item.\n",
1079
- "> 2. This is the second list item.\n",
1080
- "> \n",
1081
- "> Here's some example code:\n",
1082
- "> \n",
1083
- "> return shell_exec(\"echo $input | $markdown_script\");\n"),
1084
-
1085
- para("Any decent text editor should make email-style quoting easy. For\n" +
1086
- "example, with BBEdit, you can make a selection and choose Increase\n" +
1087
- "Quote Level from the Text menu."),
1088
-
1089
- raw("<h3 id=\"list\">Lists</h3>"),
1090
-
1091
- para("Markdown supports ordered (numbered) and unordered (bulleted) lists."),
1092
-
1093
- para("Unordered lists use asterisks, pluses, and hyphens -- interchangably\n" +
1094
- "-- as list markers:"),
1095
-
1096
- verb("* Red\n",
1097
- "* Green\n",
1098
- "* Blue\n"),
1099
-
1100
- para("is equivalent to:"),
1101
-
1102
- verb("+ Red\n",
1103
- "+ Green\n",
1104
- "+ Blue\n"),
1105
-
1106
- para("and:"),
1107
-
1108
- verb("- Red\n",
1109
- "- Green\n",
1110
- "- Blue\n"),
1111
-
1112
- para("Ordered lists use numbers followed by periods:"),
1113
-
1114
- verb("1. Bird\n",
1115
- "2. McHale\n",
1116
- "3. Parish\n"),
1117
-
1118
- para("It's important to note that the actual numbers you use to mark the\n" +
1119
- "list have no effect on the HTML output Markdown produces. The HTML\n" +
1120
- "Markdown produces from the above list is:"),
1121
-
1122
- verb("<ol>\n",
1123
- "<li>Bird</li>\n",
1124
- "<li>McHale</li>\n",
1125
- "<li>Parish</li>\n",
1126
- "</ol>\n"),
1127
-
1128
- para("If you instead wrote the list in Markdown like this:"),
1129
-
1130
- verb("1. Bird\n",
1131
- "1. McHale\n",
1132
- "1. Parish\n"),
1133
-
1134
- para("or even:"),
1135
-
1136
- verb("3. Bird\n",
1137
- "1. McHale\n",
1138
- "8. Parish\n"),
1139
-
1140
- para("you'd get the exact same HTML output. The point is, if you want to,\n" +
1141
- "you can use ordinal numbers in your ordered Markdown lists, so that\n" +
1142
- "the numbers in your source match the numbers in your published HTML.\n" +
1143
- "But if you want to be lazy, you don't have to."),
1144
-
1145
- para("If you do use lazy list numbering, however, you should still start the\n" +
1146
- "list with the number 1. At some point in the future, Markdown may support\n" +
1147
- "starting ordered lists at an arbitrary number."),
1148
-
1149
- para("List markers typically start at the left margin, but may be indented by\n" +
1150
- "up to three spaces. List markers must be followed by one or more spaces\n" +
1151
- "or a tab."),
1152
-
1153
- para("To make lists look nice, you can wrap items with hanging indents:"),
1154
-
1155
- verb("* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n",
1156
- " Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,\n",
1157
- " viverra nec, fringilla in, laoreet vitae, risus.\n",
1158
- "* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.\n",
1159
- " Suspendisse id sem consectetuer libero luctus adipiscing.\n"),
1160
-
1161
- para("But if you want to be lazy, you don't have to:"),
1162
-
1163
- verb("* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n",
1164
- "Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,\n",
1165
- "viverra nec, fringilla in, laoreet vitae, risus.\n",
1166
- "* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.\n",
1167
- "Suspendisse id sem consectetuer libero luctus adipiscing.\n"),
1168
-
1169
- para("If list items are separated by blank lines, Markdown will wrap the\n" +
1170
- "items in <code><p></code> tags in the HTML output. For example, this input:"),
1171
-
1172
- verb("* Bird\n",
1173
- "* Magic\n"),
1174
-
1175
- para("will turn into:"),
1176
-
1177
- verb("<ul>\n",
1178
- "<li>Bird</li>\n",
1179
- "<li>Magic</li>\n",
1180
- "</ul>\n"),
1181
-
1182
- para("But this:"),
1183
-
1184
- verb("* Bird\n",
1185
- "\n",
1186
- "* Magic\n"),
1187
-
1188
- para("will turn into:"),
1189
-
1190
- verb("<ul>\n",
1191
- "<li><p>Bird</p></li>\n",
1192
- "<li><p>Magic</p></li>\n",
1193
- "</ul>\n"),
1194
-
1195
- para("List items may consist of multiple paragraphs. Each subsequent\n" +
1196
- "paragraph in a list item must be intended by either 4 spaces\n" +
1197
- "or one tab:"),
1198
-
1199
- verb("1. This is a list item with two paragraphs. Lorem ipsum dolor\n",
1200
- " sit amet, consectetuer adipiscing elit. Aliquam hendrerit\n",
1201
- " mi posuere lectus.\n",
1202
- "\n",
1203
- " Vestibulum enim wisi, viverra nec, fringilla in, laoreet\n",
1204
- " vitae, risus. Donec sit amet nisl. Aliquam semper ipsum\n",
1205
- " sit amet velit.\n",
1206
- "\n",
1207
- "2. Suspendisse id sem consectetuer libero luctus adipiscing.\n"),
1208
-
1209
- para("It looks nice if you indent every line of the subsequent\n" +
1210
- "paragraphs, but here again, Markdown will allow you to be\n" +
1211
- "lazy:"),
1212
-
1213
- verb("* This is a list item with two paragraphs.\n",
1214
- "\n",
1215
- " This is the second paragraph in the list item. You're\n",
1216
- "only required to indent the first line. Lorem ipsum dolor\n",
1217
- "sit amet, consectetuer adipiscing elit.\n",
1218
- "\n",
1219
- "* Another item in the same list.\n"),
1220
-
1221
- para("To put a blockquote within a list item, the blockquote's <code>></code>\n" +
1222
- "delimiters need to be indented:"),
1223
-
1224
- verb("* A list item with a blockquote:\n",
1225
- "\n",
1226
- " > This is a blockquote\n",
1227
- " > inside a list item.\n"),
1228
-
1229
- para(
1230
- "To put a code block within a list item, the code block needs\n" +
1231
- "to be indented _twice_ -- 8 spaces or two tabs:"),
1232
-
1233
- verb("* A list item with a code block:\n",
1234
- "\n",
1235
- " <code goes here>\n"),
1236
-
1237
- para("It's worth noting that it's possible to trigger an ordered list by\n" +
1238
- "accident, by writing something like this:"),
1239
-
1240
- verb("1986. What a great season.\n"),
1241
-
1242
- para("In other words, a <em>number-period-space</em> sequence at the beginning of a\n" +
1243
- "line. To avoid this, you can backslash-escape the period:"),
1244
-
1245
- verb("1986\\. What a great season.\n"),
1246
-
1247
- raw("<h3 id=\"precode\">Code Blocks</h3>"),
1248
-
1249
- para("Pre-formatted code blocks are used for writing about programming or\n" +
1250
- "markup source code. Rather than forming normal paragraphs, the lines\n" +
1251
- "of a code block are interpreted literally. Markdown wraps a code block\n" +
1252
- "in both <code><pre></code> and <code><code></code> tags."),
1253
-
1254
- para("To produce a code block in Markdown, simply indent every line of the\n" +
1255
- "block by at least 4 spaces or 1 tab. For example, given this input:"),
1256
-
1257
- verb("This is a normal paragraph:\n",
1258
- "\n",
1259
- " This is a code block.\n"),
1260
-
1261
- para("Markdown will generate:"),
1262
-
1263
- verb("<p>This is a normal paragraph:</p>\n",
1264
- "\n",
1265
- "<pre><code>This is a code block.\n",
1266
- "</code></pre>\n"),
1267
-
1268
- para("One level of indentation -- 4 spaces or 1 tab -- is removed from each\n" +
1269
- "line of the code block. For example, this:"),
1270
-
1271
- verb("Here is an example of AppleScript:\n",
1272
- "\n",
1273
- " tell application \"Foo\"\n",
1274
- " beep\n",
1275
- " end tell\n"),
1276
-
1277
- para("will turn into:"),
1278
-
1279
- verb("<p>Here is an example of AppleScript:</p>\n",
1280
- "\n",
1281
- "<pre><code>tell application \"Foo\"\n",
1282
- " beep\n",
1283
- "end tell\n",
1284
- "</code></pre>\n"),
1285
-
1286
- para("A code block continues until it reaches a line that is not indented\n" +
1287
- "(or the end of the article)."),
1288
-
1289
- para("Within a code block, ampersands (<code>&</code>) and angle brackets (<code><</code> and <code>></code>)\n" +
1290
- "are automatically converted into HTML entities. This makes it very\n" +
1291
- "easy to include example HTML source code using Markdown -- just paste\n" +
1292
- "it and indent it, and Markdown will handle the hassle of encoding the\n" +
1293
- "ampersands and angle brackets. For example, this:"),
1294
-
1295
- verb(" <div class=\"footer\">\n",
1296
- " &copy; 2004 Foo Corporation\n",
1297
- " </div>\n"),
1298
-
1299
- para("will turn into:"),
1300
-
1301
- verb("<pre><code>&lt;div class=\"footer\"&gt;\n",
1302
- " &amp;copy; 2004 Foo Corporation\n",
1303
- "&lt;/div&gt;\n",
1304
- "</code></pre>\n"),
1305
-
1306
- para("Regular Markdown syntax is not processed within code blocks. E.g.,\n" +
1307
- "asterisks are just literal asterisks within a code block. This means\n" +
1308
- "it's also easy to use Markdown to write about Markdown's own syntax."),
1309
-
1310
- raw("<h3 id=\"hr\">Horizontal Rules</h3>"),
1311
-
1312
- para("You can produce a horizontal rule tag (<code><hr /></code>) by placing three or\n" +
1313
- "more hyphens, asterisks, or underscores on a line by themselves. If you\n" +
1314
- "wish, you may use spaces between the hyphens or asterisks. Each of the\n" +
1315
- "following lines will produce a horizontal rule:"),
1316
-
1317
- verb("* * *\n",
1318
- "\n",
1319
- "***\n",
1320
- "\n",
1321
- "*****\n",
1322
- "\n",
1323
- "- - -\n",
1324
- "\n",
1325
- "---------------------------------------\n",
1326
- "\n",
1327
- "_ _ _\n"),
1328
-
1329
- rule(1),
1330
-
1331
- raw("<h2 id=\"span\">Span Elements</h2>"),
1332
-
1333
- raw("<h3 id=\"link\">Links</h3>"),
1334
-
1335
- para("Markdown supports two style of links: _inline_ and _reference_."),
1336
-
1337
- para("In both styles, the link text is delimited by [square brackets]."),
1338
-
1339
- para("To create an inline link, use a set of regular parentheses immediately\n" +
1340
- "after the link text's closing square bracket. Inside the parentheses,\n" +
1341
- "put the URL where you want the link to point, along with an _optional_\n" +
1342
- "title for the link, surrounded in quotes. For example:"),
1343
-
1344
- verb("This is [an example](http://example.com/ \"Title\") inline link.\n",
1345
- "\n",
1346
- "[This link](http://example.net/) has no title attribute.\n"),
1347
-
1348
- para("Will produce:"),
1349
-
1350
- verb("<p>This is <a href=\"http://example.com/\" title=\"Title\">\n",
1351
- "an example</a> inline link.</p>\n",
1352
- "\n",
1353
- "<p><a href=\"http://example.net/\">This link</a> has no\n",
1354
- "title attribute.</p>\n"),
1355
-
1356
- para("If you're referring to a local resource on the same server, you can\n" +
1357
- "use relative paths:"),
1358
-
1359
- verb("See my [About](/about/) page for details.\n"),
1360
-
1361
- para("Reference-style links use a second set of square brackets, inside\n" +
1362
- "which you place a label of your choosing to identify the link:"),
1363
-
1364
- verb("This is [an example][id] reference-style link.\n"),
1365
-
1366
- para("You can optionally use a space to separate the sets of brackets:"),
1367
-
1368
- verb("This is [an example] [id] reference-style link.\n"),
1369
-
1370
- para("Then, anywhere in the document, you define your link label like this,\n" +
1371
- "on a line by itself:"),
1372
-
1373
- verb("[id]: http://example.com/ \"Optional Title Here\"\n"),
1374
-
1375
- para("That is:"),
1376
-
1377
- list(:BULLET,
1378
- item(nil,
1379
- para("Square brackets containing the link identifier (optionally\n" +
1380
- "indented from the left margin using up to three spaces);")),
1381
- item(nil,
1382
- para("followed by a colon;")),
1383
- item(nil,
1384
- para("followed by one or more spaces (or tabs);")),
1385
- item(nil,
1386
- para("followed by the URL for the link;")),
1387
- item(nil,
1388
- para("optionally followed by a title attribute for the link, enclosed\n" +
1389
- "in double or single quotes."))),
1390
-
1391
- para("The link URL may, optionally, be surrounded by angle brackets:"),
1392
-
1393
- verb("[id]: <http://example.com/> \"Optional Title Here\"\n"),
1394
-
1395
- para("You can put the title attribute on the next line and use extra spaces\n" +
1396
- "or tabs for padding, which tends to look better with longer URLs:"),
1397
-
1398
- verb("[id]: http://example.com/longish/path/to/resource/here\n",
1399
- " \"Optional Title Here\"\n"),
1400
-
1401
- para("Link definitions are only used for creating links during Markdown\n" +
1402
- "processing, and are stripped from your document in the HTML output."),
1403
-
1404
- para("Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are _not_ case sensitive. E.g. these two links:"),
1405
-
1406
- verb("[link text][a]\n",
1407
- "[link text][A]\n"),
1408
-
1409
- para("are equivalent."),
1410
-
1411
- para("The <em>implicit link name</em> shortcut allows you to omit the name of the\n" +
1412
- "link, in which case the link text itself is used as the name.\n" +
1413
- "Just use an empty set of square brackets -- e.g., to link the word\n" +
1414
- "\"Google\" to the google.com web site, you could simply write:"),
1415
-
1416
- verb("[Google][]\n"),
1417
-
1418
- para("And then define the link:"),
1419
-
1420
- verb("[Google]: http://google.com/\n"),
1421
-
1422
- para("Because link names may contain spaces, this shortcut even works for\n" +
1423
- "multiple words in the link text:"),
1424
-
1425
-
1426
- verb("Visit [Daring Fireball][] for more information.\n"),
1427
-
1428
- para("And then define the link:"),
1429
-
1430
- verb("[Daring Fireball]: http://daringfireball.net/\n"),
1431
-
1432
- para("Link definitions can be placed anywhere in your Markdown document. I\n" +
1433
- "tend to put them immediately after each paragraph in which they're\n" +
1434
- "used, but if you want, you can put them all at the end of your\n" +
1435
- "document, sort of like footnotes."),
1436
-
1437
- para("Here's an example of reference links in action:"),
1438
-
1439
- verb("I get 10 times more traffic from [Google] [1] than from\n",
1440
- "[Yahoo] [2] or [MSN] [3].\n",
1441
- "\n",
1442
- " [1]: http://google.com/ \"Google\"\n",
1443
- " [2]: http://search.yahoo.com/ \"Yahoo Search\"\n",
1444
- " [3]: http://search.msn.com/ \"MSN Search\"\n"),
1445
-
1446
- para("Using the implicit link name shortcut, you could instead write:"),
1447
-
1448
- verb("I get 10 times more traffic from [Google][] than from\n",
1449
- "[Yahoo][] or [MSN][].\n",
1450
- "\n",
1451
- " [google]: http://google.com/ \"Google\"\n",
1452
- " [yahoo]: http://search.yahoo.com/ \"Yahoo Search\"\n",
1453
- " [msn]: http://search.msn.com/ \"MSN Search\"\n"),
1454
-
1455
- para("Both of the above examples will produce the following HTML output:"),
1456
-
1457
- verb("<p>I get 10 times more traffic from <a href=\"http://google.com/\"\n",
1458
- "title=\"Google\">Google</a> than from\n",
1459
- "<a href=\"http://search.yahoo.com/\" title=\"Yahoo Search\">Yahoo</a>\n",
1460
- "or <a href=\"http://search.msn.com/\" title=\"MSN Search\">MSN</a>.</p>\n"),
1461
-
1462
- para("For comparison, here is the same paragraph written using\n" +
1463
- "Markdown's inline link style:"),
1464
-
1465
- verb("I get 10 times more traffic from [Google](http://google.com/ \"Google\")\n",
1466
- "than from [Yahoo](http://search.yahoo.com/ \"Yahoo Search\") or\n",
1467
- "[MSN](http://search.msn.com/ \"MSN Search\").\n"),
1468
-
1469
- para("The point of reference-style links is not that they're easier to\n" +
1470
- "write. The point is that with reference-style links, your document\n" +
1471
- "source is vastly more readable. Compare the above examples: using\n" +
1472
- "reference-style links, the paragraph itself is only 81 characters\n" +
1473
- "long; with inline-style links, it's 176 characters; and as raw HTML,\n" +
1474
- "it's 234 characters. In the raw HTML, there's more markup than there\n" +
1475
- "is text."),
1476
-
1477
- para("With Markdown's reference-style links, a source document much more\n" +
1478
- "closely resembles the final output, as rendered in a browser. By\n" +
1479
- "allowing you to move the markup-related metadata out of the paragraph,\n" +
1480
- "you can add links without interrupting the narrative flow of your\n" +
1481
- "prose."),
1482
-
1483
- raw("<h3 id=\"em\">Emphasis</h3>"),
1484
-
1485
- para("Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of\n" +
1486
- "emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an\n" +
1487
- "HTML <code><em></code> tag; double <code>*</code>'s or <code>_</code>'s will be wrapped with an HTML\n" +
1488
- "<code><strong></code> tag. E.g., this input:"),
1489
-
1490
- verb("*single asterisks*\n",
1491
- "\n",
1492
- "_single underscores_\n",
1493
- "\n",
1494
- "**double asterisks**\n",
1495
- "\n",
1496
- "__double underscores__\n"),
1497
-
1498
- para("will produce:"),
1499
-
1500
- verb("<em>single asterisks</em>\n",
1501
- "\n",
1502
- "<em>single underscores</em>\n",
1503
- "\n",
1504
- "<strong>double asterisks</strong>\n",
1505
- "\n",
1506
- "<strong>double underscores</strong>\n"),
1507
-
1508
- para("You can use whichever style you prefer; the lone restriction is that\n" +
1509
- "the same character must be used to open and close an emphasis span."),
1510
-
1511
- para("Emphasis can be used in the middle of a word:"),
1512
-
1513
- verb("un*fucking*believable\n"),
1514
-
1515
- para("But if you surround an <code>*</code> or <code>_</code> with spaces, it'll be treated as a\n" +
1516
- "literal asterisk or underscore."),
1517
-
1518
- para("To produce a literal asterisk or underscore at a position where it\n" +
1519
- "would otherwise be used as an emphasis delimiter, you can backslash\n" +
1520
- "escape it:"),
1521
-
1522
- verb("\\*this text is surrounded by literal asterisks\\*\n"),
1523
-
1524
- raw("<h3 id=\"code\">Code</h3>"),
1525
-
1526
- para("To indicate a span of code, wrap it with backtick quotes (<code>`</code>).\n" +
1527
- "Unlike a pre-formatted code block, a code span indicates code within a\n" +
1528
- "normal paragraph. For example:"),
1529
-
1530
- verb("Use the `printf()` function.\n"),
1531
-
1532
- para("will produce:"),
1533
-
1534
- verb("<p>Use the <code>printf()</code> function.</p>\n"),
1535
-
1536
- para("To include a literal backtick character within a code span, you can use\n" +
1537
- "multiple backticks as the opening and closing delimiters:"),
1538
-
1539
- verb("``There is a literal backtick (`) here.``\n"),
1540
-
1541
- para("which will produce this:"),
1542
-
1543
- verb("<p><code>There is a literal backtick (`) here.</code></p>\n"),
1544
-
1545
- para("The backtick delimiters surrounding a code span may include spaces --\n" +
1546
- "one after the opening, one before the closing. This allows you to place\n" +
1547
- "literal backtick characters at the beginning or end of a code span:"),
1548
-
1549
- verb("A single backtick in a code span: `` ` ``\n",
1550
- "\n",
1551
- "A backtick-delimited string in a code span: `` `foo` ``\n"),
1552
-
1553
- para("will produce:"),
1554
-
1555
- verb("<p>A single backtick in a code span: <code>`</code></p>\n",
1556
- "\n",
1557
- "<p>A backtick-delimited string in a code span: <code>`foo`</code></p>\n"),
1558
-
1559
- para("With a code span, ampersands and angle brackets are encoded as HTML\n" +
1560
- "entities automatically, which makes it easy to include example HTML\n" +
1561
- "tags. Markdown will turn this:"),
1562
-
1563
- verb("Please don't use any `<blink>` tags.\n"),
1564
-
1565
- para("into:"),
1566
-
1567
- verb("<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>\n"),
1568
-
1569
- para("You can write this:"),
1570
-
1571
- verb("`&#8212;` is the decimal-encoded equivalent of `&mdash;`.\n"),
1572
-
1573
- para("to produce:"),
1574
-
1575
- verb( "<p><code>&amp;#8212;</code> is the decimal-encoded\n",
1576
- "equivalent of <code>&amp;mdash;</code>.</p>\n"),
1577
-
1578
- raw("<h3 id=\"img\">Images</h3>"),
1579
-
1580
- para("Admittedly, it's fairly difficult to devise a \"natural\" syntax for\n" +
1581
- "placing images into a plain text document format."),
1582
-
1583
- para("Markdown uses an image syntax that is intended to resemble the syntax\n" +
1584
- "for links, allowing for two styles: _inline_ and _reference_."),
1585
-
1586
- para("Inline image syntax looks like this:"),
1587
-
1588
- verb("![Alt text](/path/to/img.jpg)\n",
1589
- "\n",
1590
- "![Alt text](/path/to/img.jpg \"Optional title\")\n"),
1591
-
1592
- para("That is:"),
1593
-
1594
- list(:BULLET,
1595
- item(nil,
1596
- para("An exclamation mark: <code>!</code>;")),
1597
- item(nil,
1598
- para("followed by a set of square brackets, containing the <code>alt</code>\n" +
1599
- "attribute text for the image;")),
1600
- item(nil,
1601
- para("followed by a set of parentheses, containing the URL or path to\n" +
1602
- "the image, and an optional <code>title</code> attribute enclosed in double\n" +
1603
- "or single quotes."))),
1604
-
1605
- para("Reference-style image syntax looks like this:"),
1606
-
1607
- verb("![Alt text][id]\n"),
1608
-
1609
- para("Where \"id\" is the name of a defined image reference. Image references\n" +
1610
- "are defined using syntax identical to link references:"),
1611
-
1612
- verb("[id]: url/to/image \"Optional title attribute\"\n"),
1613
-
1614
- para("As of this writing, Markdown has no syntax for specifying the\n" +
1615
- "dimensions of an image; if this is important to you, you can simply\n" +
1616
- "use regular HTML <code><img></code> tags."),
1617
-
1618
- rule(1),
1619
-
1620
- raw("<h2 id=\"misc\">Miscellaneous</h2>"),
1621
-
1622
- raw("<h3 id=\"autolink\">Automatic Links</h3>"),
1623
-
1624
- para("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:"),
1625
-
1626
- verb("<http://example.com/>\n"),
1627
-
1628
- para("Markdown will turn this into:"),
1629
-
1630
- verb("<a href=\"http://example.com/\">http://example.com/</a>\n"),
1631
-
1632
- para("Automatic links for email addresses work similarly, except that\n" +
1633
- "Markdown will also perform a bit of randomized decimal and hex\n" +
1634
- "entity-encoding to help obscure your address from address-harvesting\n" +
1635
- "spambots. For example, Markdown will turn this:"),
1636
-
1637
- verb("<address@example.com>\n"),
1638
-
1639
- para("into something like this:"),
1640
-
1641
- verb("<a href=\"&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;\n",
1642
- "&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;\n",
1643
- "&#109;\">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;\n",
1644
- "&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>\n"),
1645
-
1646
- para("which will render in a browser as a clickable link to \"address@example.com\"."),
1647
-
1648
- para("(This sort of entity-encoding trick will indeed fool many, if not\n" +
1649
- "most, address-harvesting bots, but it definitely won't fool all of\n" +
1650
- "them. It's better than nothing, but an address published in this way\n" +
1651
- "will probably eventually start receiving spam.)"),
1652
-
1653
- raw("<h3 id=\"backslash\">Backslash Escapes</h3>"),
1654
-
1655
- para("Markdown allows you to use backslash escapes to generate literal\n" +
1656
- "characters which would otherwise have special meaning in Markdown's\n" +
1657
- "formatting syntax. For example, if you wanted to surround a word with\n" +
1658
- "literal asterisks (instead of an HTML <code><em></code> tag), you can backslashes\n" +
1659
- "before the asterisks, like this:"),
1660
-
1661
- verb("\\*literal asterisks\\*\n"),
1662
-
1663
- para("Markdown provides backslash escapes for the following characters:"),
1664
-
1665
- verb("\\ backslash\n",
1666
- "` backtick\n",
1667
- "* asterisk\n",
1668
- "_ underscore\n",
1669
- "{} curly braces\n",
1670
- "[] square brackets\n",
1671
- "() parentheses\n",
1672
- "# hash mark\n",
1673
- "+ plus sign\n",
1674
- "- minus sign (hyphen)\n",
1675
- ". dot\n",
1676
- "! exclamation mark\n"))
1677
-
1678
- assert_equal expected, doc
1679
- end
1680
-
1681
- def test_nested_blockquotes
1682
- input = File.read "#{MARKDOWN_TEST_PATH}/Nested blockquotes.text"
1683
-
1684
- doc = @parser.parse input
1685
-
1686
- expected =
1687
- doc(
1688
- block(
1689
- para("foo"),
1690
- block(
1691
- para("bar")),
1692
- para("foo")))
1693
-
1694
- assert_equal expected, doc
1695
- end
1696
-
1697
- def test_ordered_and_unordered_lists
1698
- input = File.read "#{MARKDOWN_TEST_PATH}/Ordered and unordered lists.text"
1699
-
1700
- doc = @parser.parse input
1701
-
1702
- expected =
1703
- doc(
1704
- head(2, 'Unordered'),
1705
-
1706
- para('Asterisks tight:'),
1707
- list(:BULLET,
1708
- item(nil, para("asterisk 1")),
1709
- item(nil, para("asterisk 2")),
1710
- item(nil, para("asterisk 3"))),
1711
- para('Asterisks loose:'),
1712
- list(:BULLET,
1713
- item(nil, para("asterisk 1")),
1714
- item(nil, para("asterisk 2")),
1715
- item(nil, para("asterisk 3"))),
1716
-
1717
- rule(1),
1718
-
1719
- para("Pluses tight:"),
1720
- list(:BULLET,
1721
- item(nil, para("Plus 1")),
1722
- item(nil, para("Plus 2")),
1723
- item(nil, para("Plus 3"))),
1724
- para("Pluses loose:"),
1725
- list(:BULLET,
1726
- item(nil, para("Plus 1")),
1727
- item(nil, para("Plus 2")),
1728
- item(nil, para("Plus 3"))),
1729
-
1730
- rule(1),
1731
-
1732
- para("Minuses tight:"),
1733
- list(:BULLET,
1734
- item(nil, para("Minus 1")),
1735
- item(nil, para("Minus 2")),
1736
- item(nil, para("Minus 3"))),
1737
- para("Minuses loose:"),
1738
- list(:BULLET,
1739
- item(nil, para("Minus 1")),
1740
- item(nil, para("Minus 2")),
1741
- item(nil, para("Minus 3"))),
1742
-
1743
- head(2, "Ordered"),
1744
-
1745
- para("Tight:"),
1746
- list(:NUMBER,
1747
- item(nil, para("First")),
1748
- item(nil, para("Second")),
1749
- item(nil, para("Third"))),
1750
- para("and:"),
1751
- list(:NUMBER,
1752
- item(nil, para("One")),
1753
- item(nil, para("Two")),
1754
- item(nil, para("Three"))),
1755
-
1756
- para("Loose using tabs:"),
1757
- list(:NUMBER,
1758
- item(nil, para("First")),
1759
- item(nil, para("Second")),
1760
- item(nil, para("Third"))),
1761
- para("and using spaces:"),
1762
- list(:NUMBER,
1763
- item(nil, para("One")),
1764
- item(nil, para("Two")),
1765
- item(nil, para("Three"))),
1766
-
1767
- para("Multiple paragraphs:"),
1768
- list(:NUMBER,
1769
- item(nil,
1770
- para("Item 1, graf one."),
1771
- para("Item 2. graf two. The quick brown fox " +
1772
- "jumped over the lazy dog's\nback.")),
1773
- item(nil, para("Item 2.")),
1774
- item(nil, para("Item 3."))),
1775
-
1776
- head(2, "Nested"),
1777
- list(:BULLET,
1778
- item(nil,
1779
- para("Tab"),
1780
- list(:BULLET,
1781
- item(nil,
1782
- para("Tab"),
1783
- list(:BULLET,
1784
- item(nil,
1785
- para("Tab"))))))),
1786
-
1787
- para("Here's another:"),
1788
- list(:NUMBER,
1789
- item(nil, para("First")),
1790
- item(nil, para("Second:"),
1791
- list(:BULLET,
1792
- item(nil, para("Fee")),
1793
- item(nil, para("Fie")),
1794
- item(nil, para("Foe")))),
1795
- item(nil, para("Third"))),
1796
-
1797
- para("Same thing but with paragraphs:"),
1798
- list(:NUMBER,
1799
- item(nil, para("First")),
1800
- item(nil, para("Second:"),
1801
- list(:BULLET,
1802
- item(nil, para("Fee")),
1803
- item(nil, para("Fie")),
1804
- item(nil, para("Foe")))),
1805
- item(nil, para("Third"))),
1806
-
1807
- para("This was an error in Markdown 1.0.1:"),
1808
- list(:BULLET,
1809
- item(nil,
1810
- para("this"),
1811
- list(:BULLET,
1812
- item(nil, para("sub"))),
1813
- para("that"))))
1814
-
1815
- assert_equal expected, doc
1816
- end
1817
-
1818
- def test_strong_and_em_together
1819
- input = File.read "#{MARKDOWN_TEST_PATH}/Strong and em together.text"
1820
-
1821
- doc = @parser.parse input
1822
-
1823
- expected =
1824
- doc(
1825
- para("<b><em>This is strong and em.</em></b>"),
1826
- para("So is <b>_this_</b> word."),
1827
- para("<b><em>This is strong and em.</em></b>"),
1828
- para("So is <b>_this_</b> word."))
1829
-
1830
- assert_equal expected, doc
1831
- end
1832
-
1833
- def test_tabs
1834
- input = File.read "#{MARKDOWN_TEST_PATH}/Tabs.text"
1835
-
1836
- doc = @parser.parse input
1837
-
1838
- expected =
1839
- doc(
1840
- list(:BULLET,
1841
- item(nil,
1842
- para("this is a list item\nindented with tabs")),
1843
- item(nil,
1844
- para("this is a list item\nindented with spaces"))),
1845
-
1846
- para("Code:"),
1847
-
1848
- verb("this code block is indented by one tab\n"),
1849
-
1850
- para("And:"),
1851
-
1852
- verb("\tthis code block is indented by two tabs\n"),
1853
-
1854
- para("And:"),
1855
-
1856
- verb(
1857
- "+\tthis is an example list item\n",
1858
- "\tindented with tabs\n",
1859
- "\n",
1860
- "+ this is an example list item\n",
1861
- " indented with spaces\n"))
1862
-
1863
- assert_equal expected, doc
1864
- end
1865
-
1866
- def test_tidyness
1867
- input = File.read "#{MARKDOWN_TEST_PATH}/Tidyness.text"
1868
-
1869
- doc = @parser.parse input
1870
-
1871
- expected =
1872
- doc(
1873
- block(
1874
- para("A list within a blockquote:"),
1875
- list(:BULLET,
1876
- item(nil, para("asterisk 1")),
1877
- item(nil, para("asterisk 2")),
1878
- item(nil, para("asterisk 3")))))
1879
-
1880
- assert_equal expected, doc
1881
- end
1882
-
1883
- end
1884
-