aboutsummaryrefslogtreecommitdiff
path: root/alternative-html-blocks.txt
blob: 3ba0d1561429c3dc8b58bc3d05f6ddc5ea746200 (plain)
  1. # Appendix B: An alternate spec for HTML blocks {-}
  2. (The following spec departs less from original markdown than the
  3. one described above, but is also less flexible.)
  4. An [HTML block](#html-block) <a id="html-block-tag"/> begins
  5. with an [open tag](#open-tag), [HTML comment](#html-comment),
  6. [processing instruction](#processing-instruction),
  7. [declaration](#declaration), or [CDATA section](#cdata-section).
  8. This opening element may optionally be preceded by 1-3 spaces,
  9. and must not be followed on a line by anything other than white space.
  10. If the opening tag is self-closing, or if it is an [HTML
  11. comment](#html-comment), [processing
  12. instruction](#processing-instruction), [declaration](#declaration), or
  13. [CDATA section](#cdata-section), then the [HTML block](#html-block)
  14. contains just that tag.
  15. If it is an [open tag](#open-tag), then the [HTML block](#html-block)
  16. continues until a matching closing tag is found, or until the end
  17. of the document. Note that the matching closing tag is not necessarily
  18. the first closing tag of the same type that is encountered, since
  19. that tag may close a later open tag of the same type. Open and closing
  20. tags must be balanced.
  21. The contents of the HTML block are interpreted as raw HTML, and will not
  22. be escaped in HTML output.
  23. Some simple examples:
  24. .
  25. <table>
  26. <tr>
  27. <td>
  28. hi
  29. </td>
  30. </tr>
  31. </table>
  32. okay.
  33. .
  34. <table>
  35. <tr>
  36. <td>
  37. hi
  38. </td>
  39. </tr>
  40. </table>
  41. <p>okay.</p>
  42. .
  43. .
  44. <div class="outer">
  45. <div class="inner">
  46. <p>foo&ouml;</p>
  47. </div>
  48. </div>
  49. .
  50. <div class="outer">
  51. <div class="inner">
  52. <p>foo&ouml;</p>
  53. </div>
  54. </div>
  55. .
  56. A self-closing tag:
  57. .
  58. <div />
  59. .
  60. <div />
  61. .
  62. Here we have an unclosed tag, and the block continues to the end of
  63. the document:
  64. .
  65. <div>
  66. <div>
  67. foo
  68. </div>
  69. *bar*
  70. .
  71. <div>
  72. <div>
  73. foo
  74. </div>
  75. *bar*
  76. .
  77. A comment:
  78. .
  79. <!-- Foo
  80. bar
  81. baz -->
  82. .
  83. <!-- Foo
  84. bar
  85. baz -->
  86. .
  87. A processing instruction:
  88. .
  89. <?php
  90. echo 'foo'
  91. ?>
  92. .
  93. <?php
  94. echo 'foo'
  95. ?>
  96. .
  97. CDATA:
  98. .
  99. <![CDATA[
  100. function matchwo(a,b)
  101. {
  102. if (a < b && a < 0) then
  103. {
  104. return 1;
  105. }
  106. else
  107. {
  108. return 0;
  109. }
  110. }
  111. ]]>
  112. .
  113. <![CDATA[
  114. function matchwo(a,b)
  115. {
  116. if (a < b && a < 0) then
  117. {
  118. return 1;
  119. }
  120. else
  121. {
  122. return 0;
  123. }
  124. }
  125. ]]>
  126. .
  127. The opening tag can be indented 1-3 spaces, but not 4:
  128. .
  129. <!-- foo -->
  130. <!-- foo -->
  131. .
  132. <!-- foo -->
  133. <pre><code>&lt;!-- foo --&gt;
  134. </code></pre>
  135. .
  136. The opening tag must be on a line (or lines) by itself:
  137. .
  138. <table><tr><td>
  139. foo
  140. </td></tr></table>
  141. .
  142. <p><table><tr<td> foo </td></tr></table></p>
  143. .
  144. .
  145. <!-- foo -->bar
  146. .
  147. <p><!-- foo -->bar</p>
  148. .
  149. The opening tag need not be an HTML block tag or even an HTML tag:
  150. .
  151. <a>
  152. foo
  153. </a>
  154. .
  155. <a>
  156. foo
  157. </a>
  158. .
  159. .
  160. <foo>
  161. bar
  162. </foo>
  163. .
  164. <foo>
  165. bar
  166. </foo>
  167. .
  168. So, note the difference:
  169. .
  170. <del>
  171. bar
  172. </del>
  173. <del>bar</del>
  174. .
  175. <del>
  176. bar
  177. </del>
  178. <p><del>bar</del></p>
  179. .
  180. This rule differs from John Gruber's original markdown syntax
  181. specification, which says:
  182. > The only restrictions are that block-level HTML elements —
  183. > e.g. `<div>`, `<table>`, `<pre>`, `<p>`, etc. — must be separated from
  184. > surrounding content by blank lines, and the start and end tags of the
  185. > block should not be indented with tabs or spaces.
  186. In some ways Gruber's rule is more restrictive than the one given
  187. here:
  188. - It requires that an HTML block be preceded and followed by a blank line.
  189. - It does not allow the start tag to be indented.
  190. - It does not allow the end tag to be indented.
  191. - It does not require that the open tag be an HTML block-level tag.
  192. Indeed, most markdown implementations, including some of Gruber's
  193. own perl implementations, do not impose these restrictions.
  194. However, unlike Gruber's rule, this one requires that the open
  195. tag be on a line by itself. It also differs from most markdown
  196. implementations in how it handles the case where there is no matching
  197. closing tag (a case not mentioned in Gruber's rule). In such a case,
  198. the rule stated above includes the whole rest of the document in the
  199. HTML block.