kramdown 0.1.0

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

Potentially problematic release.


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

Files changed (201) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +24 -0
  3. data/ChangeLog +1416 -0
  4. data/GPL +674 -0
  5. data/README +20 -0
  6. data/Rakefile +300 -0
  7. data/VERSION +1 -0
  8. data/benchmark/benchmark.rb +33 -0
  9. data/benchmark/mdbasics.text +306 -0
  10. data/benchmark/mdsyntax.text +888 -0
  11. data/benchmark/testing.sh +9 -0
  12. data/benchmark/timing.sh +10 -0
  13. data/bin/kramdown +26 -0
  14. data/doc/default.css +293 -0
  15. data/doc/default.template +78 -0
  16. data/doc/index.page +89 -0
  17. data/doc/installation.page +90 -0
  18. data/doc/news.feed +10 -0
  19. data/doc/news.page +27 -0
  20. data/doc/quickref.page +474 -0
  21. data/doc/syntax.page +1089 -0
  22. data/doc/tests.page +44 -0
  23. data/doc/virtual +2 -0
  24. data/lib/kramdown.rb +23 -0
  25. data/lib/kramdown/converter.rb +215 -0
  26. data/lib/kramdown/document.rb +150 -0
  27. data/lib/kramdown/error.rb +27 -0
  28. data/lib/kramdown/extension.rb +73 -0
  29. data/lib/kramdown/parser.rb +1056 -0
  30. data/lib/kramdown/parser/registry.rb +62 -0
  31. data/setup.rb +1585 -0
  32. data/test/run_tests.rb +58 -0
  33. data/test/test_files.rb +39 -0
  34. data/test/testcases/block/01_blank_line/spaces.html +1 -0
  35. data/test/testcases/block/01_blank_line/spaces.text +3 -0
  36. data/test/testcases/block/01_blank_line/tabs.html +1 -0
  37. data/test/testcases/block/01_blank_line/tabs.text +6 -0
  38. data/test/testcases/block/02_eob/beginning.html +1 -0
  39. data/test/testcases/block/02_eob/beginning.text +3 -0
  40. data/test/testcases/block/02_eob/end.html +1 -0
  41. data/test/testcases/block/02_eob/end.text +3 -0
  42. data/test/testcases/block/02_eob/middle.html +1 -0
  43. data/test/testcases/block/02_eob/middle.text +5 -0
  44. data/test/testcases/block/03_paragraph/indented.html +18 -0
  45. data/test/testcases/block/03_paragraph/indented.text +19 -0
  46. data/test/testcases/block/03_paragraph/no_newline_at_end.html +5 -0
  47. data/test/testcases/block/03_paragraph/no_newline_at_end.text +5 -0
  48. data/test/testcases/block/03_paragraph/one_para.html +1 -0
  49. data/test/testcases/block/03_paragraph/one_para.text +1 -0
  50. data/test/testcases/block/03_paragraph/two_para.html +4 -0
  51. data/test/testcases/block/03_paragraph/two_para.text +4 -0
  52. data/test/testcases/block/04_header/atx_header.html +26 -0
  53. data/test/testcases/block/04_header/atx_header.text +24 -0
  54. data/test/testcases/block/04_header/atx_header_no_newline_at_end.html +1 -0
  55. data/test/testcases/block/04_header/atx_header_no_newline_at_end.text +1 -0
  56. data/test/testcases/block/04_header/setext_header.html +25 -0
  57. data/test/testcases/block/04_header/setext_header.text +27 -0
  58. data/test/testcases/block/04_header/setext_header_no_newline_at_end.html +1 -0
  59. data/test/testcases/block/04_header/setext_header_no_newline_at_end.text +2 -0
  60. data/test/testcases/block/04_header/with_auto_ids.html +17 -0
  61. data/test/testcases/block/04_header/with_auto_ids.options +1 -0
  62. data/test/testcases/block/04_header/with_auto_ids.text +19 -0
  63. data/test/testcases/block/05_blockquote/indented.html +25 -0
  64. data/test/testcases/block/05_blockquote/indented.text +14 -0
  65. data/test/testcases/block/05_blockquote/nested.html +9 -0
  66. data/test/testcases/block/05_blockquote/nested.text +5 -0
  67. data/test/testcases/block/05_blockquote/no_newline_at_end.html +4 -0
  68. data/test/testcases/block/05_blockquote/no_newline_at_end.text +2 -0
  69. data/test/testcases/block/05_blockquote/only_first_quoted.html +8 -0
  70. data/test/testcases/block/05_blockquote/only_first_quoted.text +4 -0
  71. data/test/testcases/block/05_blockquote/with_code_blocks.html +15 -0
  72. data/test/testcases/block/05_blockquote/with_code_blocks.text +11 -0
  73. data/test/testcases/block/06_codeblock/error.html +4 -0
  74. data/test/testcases/block/06_codeblock/error.text +4 -0
  75. data/test/testcases/block/06_codeblock/no_newline_at_end.html +2 -0
  76. data/test/testcases/block/06_codeblock/no_newline_at_end.text +1 -0
  77. data/test/testcases/block/06_codeblock/normal.html +13 -0
  78. data/test/testcases/block/06_codeblock/normal.text +10 -0
  79. data/test/testcases/block/06_codeblock/tilde_syntax.html +7 -0
  80. data/test/testcases/block/06_codeblock/tilde_syntax.text +9 -0
  81. data/test/testcases/block/06_codeblock/whitespace.html +3 -0
  82. data/test/testcases/block/06_codeblock/whitespace.text +3 -0
  83. data/test/testcases/block/06_codeblock/with_blank_line.html +13 -0
  84. data/test/testcases/block/06_codeblock/with_blank_line.text +11 -0
  85. data/test/testcases/block/06_codeblock/with_eob_marker.html +6 -0
  86. data/test/testcases/block/06_codeblock/with_eob_marker.text +5 -0
  87. data/test/testcases/block/07_horizontal_rule/error.html +7 -0
  88. data/test/testcases/block/07_horizontal_rule/error.text +7 -0
  89. data/test/testcases/block/07_horizontal_rule/normal.html +19 -0
  90. data/test/testcases/block/07_horizontal_rule/normal.text +19 -0
  91. data/test/testcases/block/08_list/escaping.html +17 -0
  92. data/test/testcases/block/08_list/escaping.text +17 -0
  93. data/test/testcases/block/08_list/list_and_hr.html +9 -0
  94. data/test/testcases/block/08_list/list_and_hr.text +5 -0
  95. data/test/testcases/block/08_list/list_and_others.html +38 -0
  96. data/test/testcases/block/08_list/list_and_others.text +25 -0
  97. data/test/testcases/block/08_list/mixed.html +111 -0
  98. data/test/testcases/block/08_list/mixed.text +66 -0
  99. data/test/testcases/block/08_list/nested.html +17 -0
  100. data/test/testcases/block/08_list/nested.text +7 -0
  101. data/test/testcases/block/08_list/other_first_element.html +39 -0
  102. data/test/testcases/block/08_list/other_first_element.text +18 -0
  103. data/test/testcases/block/08_list/simple_ol.html +19 -0
  104. data/test/testcases/block/08_list/simple_ol.text +13 -0
  105. data/test/testcases/block/08_list/simple_ul.html +61 -0
  106. data/test/testcases/block/08_list/simple_ul.text +43 -0
  107. data/test/testcases/block/08_list/single_item.html +3 -0
  108. data/test/testcases/block/08_list/single_item.text +1 -0
  109. data/test/testcases/block/08_list/special_cases.html +29 -0
  110. data/test/testcases/block/08_list/special_cases.text +19 -0
  111. data/test/testcases/block/09_html/auto_parse_block_html.html +17 -0
  112. data/test/testcases/block/09_html/auto_parse_block_html.options +1 -0
  113. data/test/testcases/block/09_html/auto_parse_block_html.text +14 -0
  114. data/test/testcases/block/09_html/comment.html +12 -0
  115. data/test/testcases/block/09_html/comment.text +12 -0
  116. data/test/testcases/block/09_html/filtered_html.html +1 -0
  117. data/test/testcases/block/09_html/filtered_html.options +1 -0
  118. data/test/testcases/block/09_html/filtered_html.text +1 -0
  119. data/test/testcases/block/09_html/html_and_codeblocks.html +15 -0
  120. data/test/testcases/block/09_html/html_and_codeblocks.options +1 -0
  121. data/test/testcases/block/09_html/html_and_codeblocks.text +13 -0
  122. data/test/testcases/block/09_html/invalid_html_1.html +5 -0
  123. data/test/testcases/block/09_html/invalid_html_1.text +5 -0
  124. data/test/testcases/block/09_html/invalid_html_2.html +6 -0
  125. data/test/testcases/block/09_html/invalid_html_2.text +5 -0
  126. data/test/testcases/block/09_html/parse_as_raw.html +26 -0
  127. data/test/testcases/block/09_html/parse_as_raw.text +16 -0
  128. data/test/testcases/block/09_html/parse_as_span.html +12 -0
  129. data/test/testcases/block/09_html/parse_as_span.text +7 -0
  130. data/test/testcases/block/09_html/processing_instruction.html +12 -0
  131. data/test/testcases/block/09_html/processing_instruction.text +12 -0
  132. data/test/testcases/block/09_html/simple.html +78 -0
  133. data/test/testcases/block/09_html/simple.text +56 -0
  134. data/test/testcases/block/10_ald/simple.html +2 -0
  135. data/test/testcases/block/10_ald/simple.text +8 -0
  136. data/test/testcases/block/11_ial/simple.html +17 -0
  137. data/test/testcases/block/11_ial/simple.text +25 -0
  138. data/test/testcases/block/12_extension/comment.html +5 -0
  139. data/test/testcases/block/12_extension/comment.text +11 -0
  140. data/test/testcases/block/12_extension/ignored.html +6 -0
  141. data/test/testcases/block/12_extension/ignored.text +11 -0
  142. data/test/testcases/block/12_extension/kdoptions.html +15 -0
  143. data/test/testcases/block/12_extension/kdoptions.text +18 -0
  144. data/test/testcases/block/12_extension/kdoptions2.html +10 -0
  145. data/test/testcases/block/12_extension/kdoptions2.text +5 -0
  146. data/test/testcases/block/12_extension/nokramdown.html +6 -0
  147. data/test/testcases/block/12_extension/nokramdown.text +11 -0
  148. data/test/testcases/span/01_link/empty.html +3 -0
  149. data/test/testcases/span/01_link/empty.text +3 -0
  150. data/test/testcases/span/01_link/image_in_a.html +5 -0
  151. data/test/testcases/span/01_link/image_in_a.text +5 -0
  152. data/test/testcases/span/01_link/imagelinks.html +12 -0
  153. data/test/testcases/span/01_link/imagelinks.text +14 -0
  154. data/test/testcases/span/01_link/inline.html +40 -0
  155. data/test/testcases/span/01_link/inline.text +42 -0
  156. data/test/testcases/span/01_link/link_defs.html +8 -0
  157. data/test/testcases/span/01_link/link_defs.text +22 -0
  158. data/test/testcases/span/01_link/links_with_angle_brackets.html +3 -0
  159. data/test/testcases/span/01_link/links_with_angle_brackets.text +3 -0
  160. data/test/testcases/span/01_link/reference.html +32 -0
  161. data/test/testcases/span/01_link/reference.text +42 -0
  162. data/test/testcases/span/02_emphasis/empty.html +3 -0
  163. data/test/testcases/span/02_emphasis/empty.text +3 -0
  164. data/test/testcases/span/02_emphasis/errors.html +9 -0
  165. data/test/testcases/span/02_emphasis/errors.text +9 -0
  166. data/test/testcases/span/02_emphasis/nesting.html +34 -0
  167. data/test/testcases/span/02_emphasis/nesting.text +30 -0
  168. data/test/testcases/span/02_emphasis/normal.html +42 -0
  169. data/test/testcases/span/02_emphasis/normal.text +42 -0
  170. data/test/testcases/span/03_codespan/empty.html +5 -0
  171. data/test/testcases/span/03_codespan/empty.text +5 -0
  172. data/test/testcases/span/03_codespan/errors.html +1 -0
  173. data/test/testcases/span/03_codespan/errors.text +1 -0
  174. data/test/testcases/span/03_codespan/normal.html +16 -0
  175. data/test/testcases/span/03_codespan/normal.text +16 -0
  176. data/test/testcases/span/04_footnote/definitions.html +14 -0
  177. data/test/testcases/span/04_footnote/definitions.text +18 -0
  178. data/test/testcases/span/04_footnote/footnote_nr.html +12 -0
  179. data/test/testcases/span/04_footnote/footnote_nr.options +1 -0
  180. data/test/testcases/span/04_footnote/footnote_nr.text +4 -0
  181. data/test/testcases/span/04_footnote/markers.html +46 -0
  182. data/test/testcases/span/04_footnote/markers.text +26 -0
  183. data/test/testcases/span/05_html/normal.html +17 -0
  184. data/test/testcases/span/05_html/normal.text +17 -0
  185. data/test/testcases/span/autolinks/url_links.html +9 -0
  186. data/test/testcases/span/autolinks/url_links.text +9 -0
  187. data/test/testcases/span/escaped_chars/normal.html +33 -0
  188. data/test/testcases/span/escaped_chars/normal.text +33 -0
  189. data/test/testcases/span/ial/simple.html +5 -0
  190. data/test/testcases/span/ial/simple.text +5 -0
  191. data/test/testcases/span/line_breaks/normal.html +11 -0
  192. data/test/testcases/span/line_breaks/normal.text +11 -0
  193. data/test/testcases/span/text_substitutions/entities.html +4 -0
  194. data/test/testcases/span/text_substitutions/entities.text +4 -0
  195. data/test/testcases/span/text_substitutions/greaterthan.html +1 -0
  196. data/test/testcases/span/text_substitutions/greaterthan.text +1 -0
  197. data/test/testcases/span/text_substitutions/lowerthan.html +1 -0
  198. data/test/testcases/span/text_substitutions/lowerthan.text +1 -0
  199. data/test/testcases/span/text_substitutions/typography.html +3 -0
  200. data/test/testcases/span/text_substitutions/typography.text +3 -0
  201. metadata +259 -0
@@ -0,0 +1,1089 @@
1
+ ---
2
+ title: Syntax
3
+ in_menu: true
4
+ sort_info: 10
5
+ ---
6
+
7
+ Table of Contents:
8
+
9
+ {::nokramdown:}
10
+ {menu: {used_nodes: fragments, min_levels: 3}}
11
+ {::nokramdown:}
12
+
13
+ # kramdown Syntax
14
+
15
+ The kramdown syntax is based on the Markdown syntax and has been enhanced with features that are
16
+ found in other Markdown implementations like [Maruku], [PHP Markdown Extra] and [Pandoc]. However,
17
+ it strives to provide a strict syntax with definite rules and therefore isn't completely compatible
18
+ with Markdown. Nonetheless, most Markdown documents should work fine when parsed with kramdown. All
19
+ places where the kramdown syntax differes from the Markdown syntax are highlighted.
20
+
21
+ Following is the complete syntax definition so that you know what you will get when a kramdown
22
+ document is converted to HTML. There are basically two types of elements: block level elements
23
+ (paragraphs, blockquotes, ...) and span level elements (emphasis, links, ...). Each has its own
24
+ section.
25
+
26
+ [Maruku]: http://maruku.rubyforge.org
27
+ [PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
28
+ [Pandoc]: http://johnmacfarlane.net/pandoc/
29
+
30
+
31
+ ## Tabs
32
+
33
+ kramdown assumes that tab stops are set at multiples of four. This is especially important when
34
+ using tabs for indentation in lists. Also, tabs may only be used at the beginning of a line when
35
+ indenting text and must not be preceded by spaces. Otherwise the results may be unexpected.
36
+
37
+
38
+ ## Automatic Escaping and Escaping
39
+
40
+ There are three characters in HTML syntax that need special treatment: `<`, `>` and `&`. When these
41
+ characters are used inside a code block or code span, they are always automatically escaped to their
42
+ HTML entity counterparts.
43
+
44
+ When used inside the normal text flow:
45
+
46
+ * `<` and `>` are always escaped except if they are part of an HTML tag, an XML processing
47
+ instruction/comment or an autolink.
48
+ * `&` is escaped if it is not part of an HTML entity.
49
+
50
+ For example, the following fragment:
51
+
52
+ This is the A&O. &copy; 2008 by me
53
+ 0 < 1 < 2 and 2 > 1 > 0
54
+
55
+ will be converted to:
56
+
57
+ <p>This is the A&amp;O. &copy; 2008 by me
58
+ 0 &lt; 1 &lt; 2 and 2 &gt; 1 &gt; 0</p>
59
+
60
+ Since kramdown also uses some characters to mark-up the text, there need to be a way to escape these
61
+ special characters sothat they can have their normal meaning. This can be done by using backslash
62
+ escapes. For example, you can use a literal backtick like this:
63
+
64
+ This \`is not a code\` span!
65
+
66
+ Following is a list of all those characters (character sequences) that can be escaped:
67
+
68
+ \ backslash
69
+ . period
70
+ * asterisk
71
+ _ underscore
72
+ + plus
73
+ - minus
74
+ ` backtick
75
+ ()[]{} parens/brackets/braces
76
+ # hash
77
+ ! bang
78
+ << left guillemet
79
+ >> right guillemet
80
+
81
+
82
+ ## Typographic Symbols
83
+
84
+ kramdown converts the following plain ASCII character into their corresponding typographic symbols:
85
+
86
+ * `---` will become an em-dash (like this ---)
87
+ * `--` will become an en-dash (like this --)
88
+ * `...` will become an ellipsis (like this ...)
89
+ * `<<` will become a left guillemet (like this <<) -- an optional following space will become a
90
+ non-breakable space
91
+ * `>>` will become a right guillemet (like this >>) -- an optional leading space will become a
92
+ non-breakable space
93
+
94
+ > The original Markdown program does not do this transformations.
95
+ {: .markdown-difference}
96
+
97
+
98
+ # Block Level Elements
99
+
100
+ Block level elements are used to structure the content. They can mark up some text, for example, as
101
+ code, as a quote or as list items.
102
+
103
+ You will often find references to the "first column" or "first character" of a line in the block
104
+ level element descriptions. Such a reference is always to be taken relative to the current
105
+ indentation level because some block level elements open up a new indentation level (e.g.
106
+ blockquotes). The beginning of a kramdown document opens up the default indentation level which
107
+ begins at the first column of the text.
108
+
109
+
110
+ ## Blank lines
111
+
112
+ Any line that just contains white space characters such as spaces and tabs is considered a blank
113
+ line by kramdown. One or more consecutive blank lines are handled as one empty blank line. Blank
114
+ lines are mostly used to visually separate block level elements from each other and in this case
115
+ they don't have semantic meaning. However, there are some cases where blank lines do have a semantic
116
+ meaning:
117
+
118
+ * When used in paragraphs -- see the [paragraphs section](#paragraphs)
119
+ * When used in headers -- see the [headers section](#headers)
120
+ * When used in lists -- see the [lists section](#lists)
121
+
122
+
123
+
124
+ ## End-Of-Block Marker
125
+
126
+ The End-Of-Block (EOB) marker -- a `^` as first character on an otherwise empty line -- can be used
127
+ to specify the end of a block level element even if the block level element, after which it is used,
128
+ would continue otherwise. If there is no block to end, the EOB marker is simply ignored and the line
129
+ is considered a blank line.
130
+
131
+ You won't find an EOB marker in most kramdown documents but sometimes it is necessary to use it to
132
+ achieve the wanted results which would be impossible otherwise.
133
+
134
+ For example, the following gives you one list with two items:
135
+
136
+ * list item one
137
+
138
+ * list item two
139
+
140
+ By using an EOB marker, you can make two lists with each one item:
141
+
142
+ * list one
143
+ ^
144
+ * list two
145
+
146
+ > The EOB marker is not part of the standard Markdown syntax.
147
+ {: .markdown-difference}
148
+
149
+
150
+ ## Paragraphs
151
+
152
+ Paragraphs are the most used block level elements. One or more consecutive lines of text are
153
+ interpreted as one paragraph. Every line of a paragraph may be indented up to three spaces. You can
154
+ separate two consecutive paragraphs from each other by using one or more blank lines. Notice that a
155
+ line break in the source does not mean a line break in the output. If you want to have an explicit
156
+ line break (ie. a `<br />` tag) you need to end a line with two or more spaces or two backslashes!
157
+ Note, however, that a line break on the last text line of a paragraph is not possible and will be
158
+ ignored.
159
+
160
+ The following gives you an example of how paragraphs look like:
161
+
162
+ This para line starts at the first column. However,
163
+ the lines can be indented up to three spaces.
164
+ The para continues here.
165
+
166
+ This is another paragraph, not connected to the above one. But
167
+ with a hard line break. \\
168
+ and another one.
169
+ {: .show-whitespaces .ws-lr}
170
+
171
+
172
+ ## Headers
173
+
174
+ kramdown supports Setext style and atx style headers.
175
+
176
+ Setext style headers are specified by a blank line (except at the beginning of a document), a line
177
+ of text (the header text) followed by a line with only equal signs (for a first level header) or
178
+ dashes (for a second level header). The header text may be indented up to three spaces, any leading
179
+ or trailing spaces are stripped from the header text. The amount of equal signs or dashes is not
180
+ significant, just one is enough but more may look better. The equal signs or dashes have to begin at
181
+ the first column. For example:
182
+
183
+ First level header
184
+ ==================
185
+
186
+ Second level header
187
+ ------
188
+
189
+ Other first level header
190
+ =
191
+
192
+ As mentioned you need to insert a blank line before a Setext header:
193
+
194
+ This is a normal
195
+ paragraph.
196
+
197
+ And A Header
198
+ ------------
199
+ And a paragraph
200
+
201
+ > This is a blockquote.
202
+
203
+ And A Header
204
+ ------------
205
+
206
+ However, it is generally a good idea to also use a blank line after a Setext header because it looks
207
+ more approriate.
208
+
209
+ > The original Markdown syntax allows one to omit the blank line before a Setext header. However,
210
+ > this makes reading the document harder than necessary and is therefore not allowed in a kramdown
211
+ > document.
212
+ {: .markdown-difference}
213
+
214
+ An edge case worth mentioning is the following:
215
+
216
+ header
217
+ ---
218
+ para
219
+
220
+ One might ask if this represents two paragraphs separated by a horizontal line or a second level
221
+ header and a paragraph. As suggested by the wording in the example, the latter is the case. The
222
+ general rule is that Setext headers are processed before horizontal rules.
223
+
224
+ atx style headers can be specified by a blank line (except at the beginning of a document), a line
225
+ with one or more hash characters and then the header text. No spaces are allowed before the hash
226
+ characters. The number of hash characters specifies the heading level: one hash character gives you
227
+ a first level heading, two a second level heading and so on till the maximum of six hash characters
228
+ for a sixth level heading. You may optionally use any number of hashes at the end of the line to
229
+ close the header. Any leading or trailing spaces are stripped from the header text. For example:
230
+
231
+ # First level header
232
+
233
+ ### Third level header ###
234
+
235
+ ## Second level header ######
236
+
237
+ > Again, the original Markdown syntax allows one to omit the blank line before an atx style header.
238
+ {: .markdown-difference}
239
+
240
+ kramdown supports the automatic generation of header IDs if the option `:auto_ids` is set to `true`.
241
+ This is done by converting the untransformed, ie. plain, header text via the following steps:
242
+
243
+ * All characters except letters, numbers, spaces and dashes are removed.
244
+ * All characters from the start of the line till the first letter are removed.
245
+ * Everything except letters and numbers is converted to dashes.
246
+ * Everything is downcased.
247
+ * If nothing is left, the identifier `section` is used.
248
+ * If a such created identifier already exists, a dash and a sequential number is added (first `-1`,
249
+ then `-2` and so on).
250
+
251
+ Following are some examples of header texts and their respective generated IDs:
252
+
253
+ # This is a header
254
+ auto_id: this-is-a-header
255
+
256
+ ## 12. Another one 1 here
257
+ auto_id: another-one-1-here
258
+
259
+ ### Do ^& it now
260
+ auto_id: do--it-now
261
+
262
+ Hallo
263
+ =====
264
+ auto_id: hallo
265
+
266
+ Not now
267
+ -------
268
+ auto_id: not-now
269
+
270
+ # Hallo
271
+ auto_id: hallo-1
272
+
273
+ # 123456789
274
+ auto_id: section
275
+
276
+ > The automatic creation of header IDs is not part of standard Markdown. The rules on how header
277
+ > text is converted to an identifier are based on the rules specified by [Pandoc].
278
+ {: .markdown-difference}
279
+
280
+
281
+ ## Blockquotes
282
+
283
+ A blockquote is started using the `>` marker followed by an optional space. The marker itself may be
284
+ indented up to three spaces. All following lines that are also started with the blockquote marker
285
+ belong to the blockquote. The contents of a blockquote are block level elements. This means that if
286
+ you are just using text as content that it will be wrapped in a paragraph. For example, the
287
+ following gives you one blockquote with two paragraphs in it:
288
+
289
+ > This is a blockquote.
290
+ >on multiple lines.
291
+ >
292
+ > This is the second paragraph.
293
+
294
+ Since the contents of a blockquote are block level elements, you can nest blockquotes and use other
295
+ block level elements:
296
+
297
+ > This is a paragraph.
298
+ > > A nested blockquote.
299
+ >
300
+ > ## Headers work
301
+ >
302
+ > * lists too
303
+ >
304
+ > and all other block level elements
305
+
306
+ Note that the first space character after the `>` marker does *not* count when counting spaces for
307
+ the indentation of the block level elements inside the blockquote! So code blocks will have to be
308
+ indented with five spaces or one space and one tab, like this:
309
+
310
+ > A code block:
311
+ >
312
+ > ruby -e 'puts :works'
313
+
314
+ > The original Markdown syntax allowed "lazy" blockquotes, ie. blockquotes where only the first line
315
+ > needs a blockquote marker. This is disallowed in kramdown, you always need to use a blockquote
316
+ > marker! The rational behind this is that most email programs and good text editors put the `>`
317
+ > maker automatically before every quoted line and that things like the following work like
318
+ > expected:
319
+ >
320
+ > > > This is some quoted text.
321
+ > > > Spanning multiple lines.
322
+ > > This is the answer to the quoted text above.
323
+ > This is just a normal paragraph, with the answer to the above.
324
+ {: .markdown-difference}
325
+
326
+
327
+ ## Code Blocks
328
+
329
+ Code blocks can be used to represent verbatim text like markup, HTML or a program fragment. No
330
+ syntax is parsed within a code block, only `<`, `>` and `&` are substituted by their respective HTML
331
+ counterparts. A code block is wrapped in both `<pre>` and `<code>` tags.
332
+
333
+ A code block can be started by using four spaces or one tab and then the text of the code block. All
334
+ following lines that adhere to this syntax belong to the same code block. The indentation (four
335
+ spaces or one tab) is stripped from the text. Note that blank lines don't separate consecutive code
336
+ blocks:
337
+
338
+ Here comes some code
339
+
340
+ This text belongs to the same code block.
341
+
342
+ If you want to have one code block directly after another one, you need to use an EOB marker to
343
+ separate the two:
344
+
345
+ Here comes some code
346
+ ^
347
+ This one is separate.
348
+
349
+ kramdown also supports an alternative syntax for code blocks which does not use indented blocks but
350
+ delimiting lines. The starting line needs to begin with three or more tilde characters (`~`) and the
351
+ closing line needs to have at least the number of tildes the starting line has. Everything between
352
+ is taken literally as with the other syntax but there is no need for indenting the text. For
353
+ example:
354
+
355
+ ~~~~~~~~
356
+ Here comes some code.
357
+ ~~~~~~~~
358
+
359
+ If you need lines of tildes in such a code block, just start the code block with more tildes. For
360
+ example:
361
+
362
+ ~~~~~~~~~~~~
363
+ ~~~~~~~
364
+ code with tildes
365
+ ~~~~~~~~
366
+ ~~~~~~~~~~~~~~~~~~
367
+
368
+ This type of code block is especially useful for copy-pasted code since you don't need to indent the
369
+ code.
370
+
371
+ > The alternative syntax is not part of the original Markdown syntax. The idea and syntax comes from
372
+ > the [PHP Markdown Extra] package.
373
+ {: .markdown-difference}
374
+
375
+ If you add the class `show-whitespaces` to a code block (using a [block
376
+ IAL](#block_inline_attribute_lists)), all spaces are replaced with `&sdot;` and additionally spaces
377
+ and tabs in the code block are marked up using HTML `span` tags and the CSS classes:
378
+
379
+ * `ws-space-l`, `ws-tab-l`: leading spaces/tabs
380
+ * `ws-space-r`, `ws-tab-r`: trailing spaces/tabs
381
+ * `ws-space`, `ws-tab`: spaces/tabs in between
382
+
383
+ Here is an example:
384
+
385
+ leading tab and space
386
+ trailing tab and space
387
+ {: .show-whitespaces}
388
+
389
+
390
+ ## Horizontal Rules
391
+
392
+ A horizontal rule is created by using three or more asterisks, dashes or underscores, optionally
393
+ separated by spaces or tabs, on an otherwise blank line. The first asterisk, dash or underscore may
394
+ optionally be indented up to three spaces. The following examples show different possibilities to
395
+ create a horizontal rule:
396
+
397
+ * * *
398
+
399
+ ---
400
+
401
+ _ _ _ _
402
+
403
+ ---------------
404
+
405
+
406
+ ## Lists
407
+
408
+ Both ordered and unordered lists follow the same rules.
409
+
410
+ A list is started with a list marker (in case of unordered lists one of `+`, `-` or `*` -- you can
411
+ mix them -- and in case of ordered lists a number followed by a period) followed by one tab or at
412
+ least one space and then the first part of the content of the list item. The leading tabs or spaces
413
+ are stripped away from this first line of content to allow for a nice alignment with the following
414
+ content of a list item (see below). All following list items with the same marker type (unordered or
415
+ ordered) are put into the same list. The numbers used for ordered lists are irrelevant, an ordered
416
+ list always starts at 1.
417
+
418
+ The following gives you an unordered list and an ordered list:
419
+
420
+ * kram
421
+ + down
422
+ - now
423
+
424
+ 1. kram
425
+ 2. down
426
+ 3. now
427
+
428
+ > The original Markdown syntax allows the markers of ordered and unordered lists to be mixed, the
429
+ > first marker specifying the list type (ordered or unordered). This is not allowed in kramdown. As
430
+ > stated, the above example will give you two lists (an unordered and an ordered) in kramdown and
431
+ > only one unordered list in Markdown.
432
+ {: .markdown-difference}
433
+
434
+ The first list marker in a list may be indented up to three spaces. The column number of the first
435
+ non-space character which appears after the list item marker on the same line specifies the
436
+ indentation that has to be used for the following lines of content of the list item. If there is no
437
+ such character, the indentation that needs to be used is four spaces or one tab. If a line does not
438
+ have the needed amount of indentation, it is not treated as list item content. The indentation is
439
+ stripped from the content and the content (note that the content naturally also contains the content
440
+ of the line with the item marker) is processed as text containing block level elements. All other
441
+ list markers in the list may be indented up to three spaces or the number of spaces used for the
442
+ indentation of the last list item minus one, whichever number is smaller. For example:
443
+
444
+ * This is the first line. Since the first non-space characters appears in column 3, all other
445
+ lines have to be indented 2 spaces sothat they first characters align. This tells kramdown
446
+ that the lines belong to the list item.
447
+ * This is the another item of the list. It uses a different number of spaces for
448
+ indentation which is okay but should generally be avoided.
449
+ * The list item marker is indented 3 spaces which is allowed but should also be avoided.
450
+
451
+ So, while the above is possible and creates one list with three items, it is not advised to use
452
+ different (marker and list content) indents for same level list items!
453
+
454
+ > The original Markdown syntax also allows you to indent the marker, however, the behaviour of what
455
+ > happens with the list items is not clearly specified and may surprise you.
456
+ >
457
+ > Also, Markdown uses a fixed number of spaces/tabs to indent the lines that belong to a list item!
458
+ {: .markdown-difference}
459
+
460
+ When using tabs for indenting the content of a list item, remember that tab stops occur at multiples
461
+ of four. Tabs are converted to spaces for calculating the indentation. For example:
462
+
463
+ * Using a tab to indent this line, the tab only counts as three spaces and therefore the
464
+ overall indentation is four spaces.
465
+
466
+ 1. The tab after the marker counts here as two spaces. Since the indentation of the marker
467
+ is three spaces and the marker itself takes two characters, the overall indentation
468
+ needed for the following lines is eight spaces or two tabs.
469
+
470
+ It is clear that you might get unexpected results if you mix tabs and spaces and don't have the tab
471
+ stops set to multiples of four! Therefore this should be avoided!
472
+
473
+ The content of a list item is made up of either text or block level elements. Simple list items only
474
+ contain text like in the above examples. They are not even wrapped in a paragraph tag. If the first
475
+ list text is followed by one or more blank lines, it will be wrapped in a paragraph tag:
476
+
477
+ * kram
478
+
479
+ * down
480
+
481
+ In the above example, the first list item text will be wrapped in a paragraph tag since it is
482
+ followed by a blank line. There is obviously a problem for doing this with the last list item when
483
+ it contains only text. You can circumvent this by leaving a blank line after the last list item and
484
+ using an EOB marker:
485
+
486
+ * Not wrapped in a paragraph
487
+ * Wrapped in a paragraph due to the following blank line.
488
+
489
+ * Also wrapped in a paragraph due to the
490
+ following blank line and the EOB marker.
491
+
492
+ ^
493
+
494
+ > The original Markdown syntax page specifies that list items which are separated by one or more
495
+ > blank lines are wrapped in paragraph tags. This means that the first text will also be wrapped in
496
+ > a paragraph if you have block level elements in a list which are separated by blank lines. The
497
+ > above rule is easy to remember and lets you exactly specify when the first list text should be
498
+ > wrapped in a paragraph. The idea for the above rule comes from the [pandoc] package.
499
+ {: .markdown-difference}
500
+
501
+ As seen in the examples above, blank lines between list items are allowed.
502
+
503
+ Since the content of a list item can contain block level elements, you can do the following:
504
+
505
+ * First item
506
+
507
+ A second paragraph
508
+
509
+ * nested list
510
+ > blockquote
511
+
512
+ * Second item
513
+
514
+ However, there is a problem when you want to follow a list item with an indentation of four or less
515
+ immediately with a code block. You can use an EOB marker to circumvent this problem:
516
+
517
+ * This is a list item.
518
+
519
+ The second para of the list item.
520
+ ^
521
+ A code block following the list item.
522
+
523
+ You can have any block level element as first element in a list item. However, as described above,
524
+ the leading tabs or spaces of the line with the list item marker are stripped away. This leads to a
525
+ problem when you want to have a code block as first element. The solution to this problem is the
526
+ following construct:
527
+
528
+ *
529
+ This is a code block (indentation needs to be 4(1)+4(1) spaces (tabs)).
530
+ {: .show-whitespaces .ws-lr}
531
+
532
+ Note that the list marker needs to be followed with at least one space or tab! Otherwise the line is
533
+ not recognized as the start of a list item but interpreted as a paragraph containing the list
534
+ marker.
535
+
536
+ > The original Markdown syntax allows you to be lazy when you just use text for a list item. So the
537
+ > following is possible with Markdown:
538
+ >
539
+ > * First list item
540
+ > continued here
541
+ > * Second list item
542
+ > continued here.
543
+ >
544
+ > This kind of syntax is disallowed in kramdown.
545
+ {: .markdown-difference}
546
+
547
+ If you want to have one list directly after another one (both with the same list type, ie. ordered
548
+ or unordered), you need to use an EOB marker to separate the two:
549
+
550
+ * List one
551
+ ^
552
+ * List two
553
+
554
+ It is possible that a line gets parsed as ordered or unordered list although it shouldn't. This
555
+ would be the case in the following example:
556
+
557
+ I have read the book
558
+ 1984. It was great
559
+ - others say that, too!
560
+
561
+ Therefore you have to insert a blank line after a paragraph if you want to follow the paragraph with
562
+ a list. The only exception to this rule is when you want to create a compact nested list, i.e. a
563
+ list where the text is not wrapped in paragraphs:
564
+
565
+ * This is just text.
566
+ * this is a sub list item
567
+ * this is a sub sub list item
568
+ * This is just text,
569
+ spanning two lines
570
+ * this is a nested list item.
571
+
572
+ Another way to remedy the problem with the list item marker appearing in plain text is by escaping
573
+ the period in an ordered list or the list item marker in an unordered list (this is especially
574
+ useful when the paragraph starts with something looking like a list item marker):
575
+
576
+ 1984\. It was great
577
+ \- others say that, too!
578
+
579
+
580
+ ## HTML Blocks
581
+
582
+ There is no problem mixing HTML tags into a kramdown document. An HTML block is started when
583
+ kramdown encounters a line beginning with a block level HTML tag (`div`, `p`, `pre`, ...) -- or with
584
+ a general XML tag -- which may be indented up to three spaces. The line may contain multiple block
585
+ level HTML tags (no span level HTML tags) but each tag must appear completely on the line! The HTML
586
+ block continues till the matching end tag of the first HTML tag is encountered (i.e. till an HTML
587
+ block line with the matching end tag is found). kramdown syntax is processed in HTML blocks. Note
588
+ that only correct XHTML is supported! This means that you have to use, for example, `<br/>` instead
589
+ of `<br>`.
590
+
591
+ > The original Markdown syntax specifies that an HTML block must start at the left margin, ie. no
592
+ > indentation is allowed. Also, the HTML block has to be surrounded by blank lines. Both
593
+ > restrictions are lifted for kramdown documents. Additionally, the original syntax does not allow
594
+ > you to use Markdown syntax in HTML blocks.
595
+ {: .markdown-difference}
596
+
597
+ Here is a simple example:
598
+
599
+ This is a para.
600
+ <div>
601
+ Something in here.
602
+ </div>
603
+ Other para.
604
+ ^
605
+ <p>This is a para.</p>
606
+ <div>
607
+ <p>Something in here.</p>
608
+ </div>
609
+ <p>Other para.</p>
610
+
611
+ See how the content of the `div` tag is wrapped in a paragraph!
612
+
613
+ You can also use several HTML tags at once:
614
+
615
+ <div id="content"><div id="layers"><div id="layer1">
616
+ This is a para in the `layer1` div.
617
+ </div>
618
+ This is a para in the `layers` div.
619
+ </div></div>
620
+ This is a para outside the HTML block.
621
+
622
+ When you specify an HTML block don't forget that the first column does not change:
623
+
624
+ This is a para.
625
+ <div><h1>some header</h1>
626
+ code block (indented four spaces)
627
+ <div>
628
+ also a code block
629
+ </div>
630
+ </div>
631
+
632
+ If you don't use valid XHTML tags, you won't get expected result (note the invalid `<br>` tag):
633
+
634
+ This is a para.
635
+ <div>
636
+ Something is<br>
637
+ broken here.
638
+ </div>
639
+ This won't be a para.
640
+ ^
641
+ <p>This is a para.</p>
642
+ <div>
643
+ <p>Something is&lt;br&gt;
644
+ broken here.</p>
645
+ </div>
646
+ This won't be a para.
647
+
648
+ Unclosed block level HTML tags are correctly closed at the end of the document to ensure correct
649
+ nesting and invalidly used end tags are escaped:
650
+
651
+ This is a para.
652
+ <div><div class="clear"/>
653
+ Another para.
654
+ </p>
655
+ ^
656
+ <p>This is a para.</p>
657
+ <div><div class="clear"/>
658
+ <p>Another para.</p>
659
+ &lt;/p&gt;
660
+ </div>
661
+
662
+ The content of a HTML tag is either parsed as block level elements, span level elements or is not
663
+ parsed at all depending on the tag encountered. For example, a `<div>` tag contains block level
664
+ elements, a `<p>` tag contains span level elements and the contents of a `<script>` tag is not
665
+ parsed at all.
666
+
667
+ The parsing of processing instructions and XML comments is also supported. The content of both, PIs
668
+ and XML comments, may span multiple lines. The start of a PI/XML comment may only appear at the
669
+ beginning of a line, optionally indented up to three spaces. All characters from the end of a PI/XML
670
+ comment till the end of the line are ignored. kramdown syntax in PIs/XML comments is not processed:
671
+
672
+ This is a para.
673
+ <!-- a *comment* -->
674
+ <? a processing `instruction`
675
+ spanning multiple lines
676
+ ?>
677
+ Another para.
678
+
679
+
680
+
681
+ ## Attribute List Definitions
682
+
683
+ > This syntax feature is not part of the original Markdown syntax. The idea and syntax comes from
684
+ > the [Maruku] package.
685
+ {: .markdown-difference}
686
+
687
+ This is an implementation of [Maruku]'s feature for adding attributes to block and span level
688
+ elements (the naming is also taken from Maruku). This block level element is used to define
689
+ attributes which can be referenced later. The [Block Inline Attribute
690
+ List](#block_inline_attribute_lists) is used to attach attributes to a block level element and the
691
+ [Span Inline Attribute List](#span_inline_attribute_lists) is used to attach attributes to a span
692
+ level element.
693
+
694
+ Following are some examples of attribute list definitions (ALDs) and afterwards comes the syntax
695
+ explanation:
696
+
697
+ {:ref-name: #myid .my-class}
698
+ {:other: ref-name #id-of-other title="hallo you"}
699
+ {:test: key="value \" with quote" and other='quote brace \}'}
700
+
701
+ An ALD line has the following structure:
702
+
703
+ * a left brace, optionally preceded by up to three spaces,
704
+ * followed by a colon, the reference name and another colon,
705
+ * followed by attribute definitions (allowed characters are backslash-escaped closing braces or any
706
+ character except an unescaped closing brace),
707
+ * followed by a closing brace and optional spaces till the end of the line.
708
+
709
+ The reference name needs to start with a word character or a digit, optionally followed by other word
710
+ characters, digits or dashes.
711
+
712
+ There are four different types of attribute definitions which have to be separated by one or more
713
+ spaces:
714
+
715
+ * references
716
+
717
+ This must be a valid reference name. It is used to reference an other ALD sothat the attributes
718
+ of the other ALD are also included in this one. The reference name is ignored when collecting the
719
+ attributes if no attribute definition list with this reference name exists. For example, a
720
+ simple reference looks like `id`.
721
+
722
+ * key-value pairs
723
+
724
+ A key-value pair is defined by a key name, which must follow the rules for reference names, then
725
+ an equal sign and then the value in single or double quotes. If you need to use the value
726
+ delimiter (a single or a double quote) inside the value, you need to escape it with a backslash.
727
+ Key-value pairs can be used to specify arbitray attributes for block or span level elements. For
728
+ example, a key-value pair looks like `key1="bef \"quoted\" aft"` or `title='This is a title'`.
729
+
730
+ * ID name
731
+
732
+ An ID name is defined by using a hash and then the identifier name which must follow the rules
733
+ for reference names. This is a short hand for the key-value pair `id="IDNAME"` since this is
734
+ often used. The ID name specifies the unique ID of a block or span level element. For example,
735
+ an ID name looks like `#myid`.
736
+
737
+ * class names
738
+
739
+ A class name is definied by using a dot and then the class name. This is (almost, but not quite)
740
+ a short hand for the key-value pair `class="class-name"`. Almost because it actually means that
741
+ the class name should be appended to the current value of the `class` attribute. The following
742
+ ALDs are all equivalent:
743
+
744
+ {:id: .cls1 .cls2}
745
+ {:id: class="cls1" .cls2}
746
+ {:id: class="something" class="cls1" .cls2}
747
+ {:id: class="cls1 cls2}
748
+
749
+ As can be seen from the example of the class names, attributes that are defined earlier are
750
+ overwritten by ones with the same name defined later. Also, everything in the attribute definitions
751
+ part that does not match one of the above four types is ignored.
752
+
753
+ If there is more than one ALD with the same reference name, the attribute definitions of all the
754
+ ALDs are processed like they are defined in one ALD.
755
+
756
+
757
+ ## Block Inline Attribute Lists
758
+
759
+ > This syntax feature is not part of the original Markdown syntax. The idea and syntax comes from
760
+ > the [Maruku] package.
761
+ {: .markdown-difference}
762
+
763
+ This block level element is used to attach attributes to a block level element. A block inline
764
+ attribute list (block IAL) has the same structure as an [ALD](#attribute_list_definitions) except
765
+ that the colon/reference name/colon part is replaced by a colon. A block IAL (or two or more block
766
+ IALs) has to be put directly after the block level element to which the attributes should be
767
+ attached, otherwise it is ignored. This is, for example, the case when there is a blank line between
768
+ the block level element and the IAL.
769
+
770
+ Key-value pairs of an IAL take precedence over equally named key-value pairs in referenced ALDs.
771
+
772
+ Here are some examples for block IALs:
773
+
774
+ A simple paragraph with an ID attribute.
775
+ {: #para-one}
776
+
777
+ > A blockquote with a title
778
+ {:title="The blockquote title"}
779
+ {: #myid}
780
+
781
+ Some code here
782
+ {:.ruby}
783
+
784
+ TODO: special case for atx style headers.
785
+
786
+
787
+ ## Extension Blocks
788
+
789
+ Extension blocks can be used, for example, to treat whole sections of text specially. For example,
790
+ one could write an extension that highlights a code fragment specified in an extension block.
791
+
792
+ An extension block has two forms, one with a body and one without a body:
793
+
794
+ * Without a body
795
+
796
+ The extension block line has the same structure as an [ALD](#attribute_list_definitions) except
797
+ that the reference name needs to prefixed and postfixed with `:` and identifies the extension to
798
+ be used. Attributes can be defined like it is done for an ALD.
799
+
800
+ * With a body
801
+
802
+ The starting and ending lines of an extension block with a body have the same structure as an
803
+ [ALD](#attribute_list_definitions) except that the reference name needs to prefixed with `:` and
804
+ identifies the extension to be used; attributes can be defined on the starting or ending line.
805
+ The text between the starting and ending line is passed to the extension and not parsed by
806
+ kramdown. If no ending line is found, the starting line is ignored and the body is parsed
807
+ normally by kramdown.
808
+
809
+ If the specified extension is not found, a warning is shown and the whole extension block including
810
+ the body is ignored. The following extensions are builtin:
811
+
812
+ * `comment`
813
+
814
+ Treats the body text as a comment which does not show in the output.
815
+
816
+ * `nokramdown`
817
+
818
+ The body is not processed with kramdown but output as-is.
819
+
820
+ * `kdoptions`
821
+
822
+ Should be used without a body since the body is ignored. Is used for setting options for the
823
+ kramdown processor (for example, to enable automatic header ID generation).
824
+
825
+ Here are some examples for how extension blocks look like:
826
+
827
+ {::toc::}
828
+
829
+ The above extension block could be replaced by a table of contents.
830
+
831
+ {::comment:}
832
+ This text is completely ignored by kramdown - a comment in the text.
833
+ {::comment:}
834
+
835
+
836
+
837
+ # Span Level Elements
838
+
839
+ These elements are used inside block level elements to markup text fragments. For example, one can
840
+ easily create links or apply emphasis to certain text parts.
841
+
842
+ Note that empty span level elements are not converted to empty HTML tags but are copied as-is to the
843
+ output.
844
+
845
+
846
+
847
+ ## Links and Images
848
+
849
+ Two styles of links are supported: inline and reference.
850
+
851
+ As the wording suggests, inline links provide all information inline in the text flow. Reference
852
+ style links only provide the link text in the text flow and everything else is defined
853
+ elsewhere. This also allows you to reuse link definitions.
854
+
855
+ An inline style link can be created by surrounding the link text with square brackets, followed
856
+ immediately by the link URL (and an optional title in single or double quotes preceded by at least
857
+ one space) in normal parentheses. For example:
858
+
859
+ This is [a link](http://rubyforge.org) to a page.
860
+ A [link](../test "local URI") can also have a title.
861
+ And [spaces](<link with spaces.html>)!
862
+
863
+ Notes:
864
+
865
+ * The link text is treated like normal span level text and therefore is parsed and converted.
866
+ However, if you use square brackets within the link text, you have to either properly nest them or
867
+ to escape them. It is not possible to create nested links!
868
+
869
+ * The link URL must not contain any spaces and it has to contain properly nested parentheses if no
870
+ title is specified, or the link URL must be contained in angle brackets (then spaces and
871
+ incorrectly nested parentheses are allowed). There must not be any spaces before the link URL, and
872
+ if no title is specified, no spaces are allowed between the link URL and the closing parenthesis.
873
+
874
+ * The link title may not contain its delimiters and may not be empty.
875
+
876
+ To create a reference style link, you need to surround the link text with square brackets (as with
877
+ inline links), followed by optional spaces/tabs/line breaks and then optionally followed with
878
+ another set of square brackets with the link identifier in them. A link indentifier may only contain
879
+ numbers, letters, spaces (line breaks and tabs are converted to spaces, multiple spaces are
880
+ compressed to one) and punctuation characters (ie. `_.:,;!?-`) and is not case sensitive. For
881
+ example:
882
+
883
+ This is a [reference style link][linkid] to a page. And [this]
884
+ [linkid] is also a link. As is [this][] and [THIS].
885
+
886
+ If you don't specify a link identifier (ie. only use empty square brackets) or completely omit the
887
+ second pair of square brackets, the link text is converted to a valid link identifier by removing
888
+ all invalid characters and inserting spaces for line breaks. If there is a link definition found for
889
+ the link identifier, a link will be created. Otherwise the text is not converted to a link.
890
+
891
+ The link definition can be put anywhere in the document. It does not appear in the output. A link
892
+ definition looks like this:
893
+
894
+ [linkid]: http://www.example.com/ "Optional Title"
895
+
896
+ > Link definitions are, despite being described here, block level elements.
897
+ {: .information}
898
+
899
+ The link definition has the following structure:
900
+
901
+ * The link identifier in square brackets, optionally indented up to three spaces,
902
+ * then a colon and one or more spaces/tabs,
903
+ * then the link URL which must not contain any spaces or a left angle bracket, the link URL which may
904
+ contain spaces and a right angle bracket,
905
+ * then optionally the title in single or double quotes, separated from the link URL by one or more
906
+ spaces or on the next line by itself indented any number of spaces/tabs.
907
+
908
+ > The original Markdown syntax also allowed the title to be specified in parenthesis. This is not
909
+ > allowed for consistency with the inline title.
910
+ {: .markdown-difference}
911
+
912
+ Images can be specified via a syntax that is similar to the one used by links. The difference is
913
+ that you have to use an exclamation mark before the first square bracket and that the link text of a
914
+ normal link becomes the alternative text of the image link. As with normal links, image links can be
915
+ written inline or reference style. For example:
916
+
917
+ Here comes a ![smiley](../images/smiley.png)! And here
918
+ ![too](../images/other.png 'Title text'). Or ![here].
919
+
920
+ The link definition for images is exactly the same as the link definition for normal links.
921
+
922
+
923
+ ## Emphasis
924
+
925
+ kramdown uses the HTML elements `em` and `strong` to style emphasized text parts. Text parts that
926
+ are surrounded with single asterisks `*` or underscores `_` are wrapped in `em` tags, text parts
927
+ surrounded with two asterisks or underscores are wrapped in `strong` tags. Surrounded means that the
928
+ starting delimiter must not be followed by a space and that the stopping delimiter must not be
929
+ preceeded by a space. For example:
930
+
931
+ *some text*
932
+ _some text_
933
+ **some text**
934
+ __some text__
935
+
936
+ will produce the following output:
937
+
938
+ <em>some text</em>
939
+ <em>some text</em>
940
+ <strong>some text</strong>
941
+ <strong>some text</strong>
942
+
943
+ The asterisk form is also allowed within a single word:
944
+
945
+ This is un*believe*able! This d_oe_s not work!
946
+
947
+ Text emphasized with different delimiters can be nested but you can't nest emphasized text with the
948
+ same delimiters:
949
+
950
+ This is a ***strong and emphasized*** text.
951
+ This **is __very__ strong**.
952
+ This **is **very** strong**.
953
+
954
+ will produce the following output:
955
+
956
+ <p>This is a <strong><em>strong and emphasized</em></strong> text.
957
+ This <strong>is <strong>very</strong> strong</strong>.
958
+ This <strong>is </strong>very<strong> strong</strong>.</p>
959
+
960
+ Notice the difference between the second and the third line!
961
+
962
+ If one or two asterisks or underscores are surrounded by spaces, they are treated literally. If you
963
+ want to force the literal meaning of an asterisk or an underscore you can backslash-escape it:
964
+
965
+ This is a * literal asterisk.
966
+ These are ** two literal asterisk.
967
+ As \*are\* these!
968
+
969
+
970
+ ## Code Spans
971
+
972
+ This is the span level equivalent of the code block element. You can markup a text part as code span
973
+ by surrounding it with backticks `` ` ``. For example:
974
+
975
+ Use `<html>` tags for this.
976
+
977
+ The special characters `<`, `>` and `&` are substituted by their respective HTML counterparts (same
978
+ behaviour as seen with the block level code block element).
979
+
980
+ To include a literal backtick in a code span, you need to use two or more backticks as delimiters.
981
+ You can insert one optional space after the starting and before the ending delimiter (these spaces
982
+ are not used in the output). For example:
983
+
984
+ Here is a literal `` ` `` backtick.
985
+ And here is `` `some` `` text (note the two spaces!).
986
+
987
+ will produce:
988
+
989
+ <p>Here is a literal <code>`</code> backtick.</p>
990
+ <p>And here is <code> `some` </code> text (note the two spaces!).</p>
991
+
992
+ A single backtick surrounded by spaces is treated as literal backtick. If you want to force the
993
+ literal meaning of a backtick you can backslash-escape it:
994
+
995
+ This is a ` literal backtick.
996
+ As \`are\` these!
997
+
998
+
999
+ ## HTML Spans
1000
+
1001
+ HTML tags cannot only be used on the block level but also on the span level. Span level HTML tags
1002
+ can only be used inside one block level element, it is not possible to use a start tag in one block
1003
+ level element and the end tag in another. Note that only correct XHTML is supported! This means that
1004
+ you have to use, for example, `<br/>` instead of `<br>`.
1005
+
1006
+ Processing instructions and XML comments can also be used (their content is not parsed).
1007
+
1008
+ Span level HTML tags (opening or closing), span level PIs and span level XML comments have to be
1009
+ preceded by at least one non whitespace character on the same line sothat kramdown correctly
1010
+ recognizes them as span level element and not as block level element.
1011
+
1012
+ Unclosed HTML tags as well as invalidly used end tags are escaped.
1013
+
1014
+
1015
+ ## Footnotes
1016
+
1017
+ > This syntax feature is not part of the original Markdown syntax. The idea and syntax comes from
1018
+ > the [PHP Markdown Extra] package.
1019
+ {: .markdown-difference}
1020
+
1021
+ Footnotes in kramdown are simliar to reference style links and link definitions. You need to place
1022
+ the footnote marker in the correct position in the text and the actual footnote content can be
1023
+ defined anywhere in the document.
1024
+
1025
+ More exactly, a footnote marker can be created by placing the footnote name in square brackets.
1026
+ The footnote name has to start with a caret (`^`), followed by a word character or a digit and then
1027
+ optionally followed by other word characters, digits or dashes. For example:
1028
+
1029
+ This is some text.[^1]. Other text.[^footnote].
1030
+
1031
+ The footnote name has to be unique in the whole kramdown document. Therefore you can't link to the
1032
+ same footnote definition twice. The actual naming of a footnote does not matter since the numbering
1033
+ of footnotes is controlled via the position of the footnote markers in the document (the first found
1034
+ footnote marker will get the number 1, the second footnote marker the number 2 and so on). If there
1035
+ is a footnote definition found for the identifier, a footnote will be created. Otherwise the
1036
+ footnote marker is not converted to a footnote link. Also note that all attributes set via a span
1037
+ IAL are ignored for a footnote marker!
1038
+
1039
+ A footnote definition is used to define the content of a footnote and has the following structure:
1040
+
1041
+ * The footnote name in square brackets, optionally indented up to three spaces,
1042
+ * then a colon and one or more optional spaces,
1043
+ * then the text of the footnote
1044
+ * and optionally more text on the following lines which have have to be indented by four spaces or
1045
+ one tab (like with list items).
1046
+
1047
+ > Footnote definitions are, despite being described here, block level elements.
1048
+ {: .information}
1049
+
1050
+ The whole footnote content is treated like block level text and can therefore contain any valid
1051
+ block level element (also, any block level element can be the first element). If you want to have a
1052
+ code block as first element, note that all leading spaces/tabs on the first line are stripped away.
1053
+ Here are some example footnote definitions:
1054
+
1055
+ [^1]: Some *crazy* footnote definition.
1056
+
1057
+ [^footnote]:
1058
+ > Blockquotes can be in a footnote.
1059
+
1060
+ as well as code blocks
1061
+
1062
+ or, naturally, simple paragraphs.
1063
+
1064
+ [^other-note]: no code block here (spaces are stripped away)
1065
+
1066
+ [^codeblock-note]:
1067
+ this is now a code block (8 spaces indentation)
1068
+
1069
+ It does not matter where you put a footnote definition in a kramdown document; the content of all
1070
+ referenced footnote definitions will be placed at the end of the kramdown document. Not referenced
1071
+ foot note definitions are ignored. If more than one footnote definitions have the same footnote
1072
+ name, all footnote definitions but the last are ignored.
1073
+
1074
+
1075
+ ## Span Inline Attribute Lists
1076
+
1077
+ > This syntax feature is not part of the original Markdown syntax. The idea and syntax comes from
1078
+ > the [Maruku] package.
1079
+ {: .markdown-difference}
1080
+
1081
+ This is a version of the [block inline attribute list](#block_inline_attribute_lists) for span level
1082
+ elements. It has the same structure as the block IAL except that leading and trailing spaces are not
1083
+ allowed. A span IAL (or two or more span IALs) has to be put directly after the span level element,
1084
+ no additional character is allowed between.
1085
+
1086
+ Here are some examples for span IALs:
1087
+
1088
+ This *is*{:.underline} some `code`{:#id}{:.class}.
1089
+ A [link](test.html){:rel='something'} and some **tools**{:.tools}.