more consistent spacing of block-level elements
@@ -942,6 +942,7 @@
// parse ordered or unordered list block func (parser *Parser) blockList(out *bytes.Buffer, data []byte, flags int) int { i := 0 + flags |= LIST_ITEM_BEGINNING_OF_LIST work := func() bool { j := 0 for i < len(data) {@@ -951,6 +952,7 @@
if j == 0 || flags&LIST_ITEM_END_OF_LIST != 0 { break } + flags &= ^LIST_ITEM_BEGINNING_OF_LIST } return true }
@@ -86,10 +86,10 @@ "Hello\n# Header 1\nGoodbye\n",
"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n", "* List\n# Header\n* List\n", - "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n", + "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n", "* List\n#Header\n* List\n", - "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n", + "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n", "* List\n * Nested list\n # Nested header\n", "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +@@ -146,7 +146,7 @@ "Hello\n# Header 1\nGoodbye\n",
"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n", "* List\n# Header\n* List\n", - "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n", + "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n", "* List\n#Header\n* List\n", "<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",@@ -285,10 +285,10 @@ "* Ting\n* Bong\n* Goo\n",
"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n", "* Yin\n\n* Yang\n", - "<ul>\n<li><p>Yin</p></li>\n<li><p>Yang</p></li>\n</ul>\n", + "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n", "* Ting\n\n* Bong\n* Goo\n", - "<ul>\n<li><p>Ting</p></li>\n<li><p>Bong</p></li>\n<li><p>Goo</p></li>\n</ul>\n", + "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n", "+ Hello\n", "<ul>\n<li>Hello</li>\n</ul>\n",@@ -300,10 +300,10 @@ "+ Ting\n+ Bong\n+ Goo\n",
"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n", "+ Yin\n\n+ Yang\n", - "<ul>\n<li><p>Yin</p></li>\n<li><p>Yang</p></li>\n</ul>\n", + "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n", "+ Ting\n\n+ Bong\n+ Goo\n", - "<ul>\n<li><p>Ting</p></li>\n<li><p>Bong</p></li>\n<li><p>Goo</p></li>\n</ul>\n", + "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n", "- Hello\n", "<ul>\n<li>Hello</li>\n</ul>\n",@@ -315,10 +315,10 @@ "- Ting\n- Bong\n- Goo\n",
"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n", "- Yin\n\n- Yang\n", - "<ul>\n<li><p>Yin</p></li>\n<li><p>Yang</p></li>\n</ul>\n", + "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n", "- Ting\n\n- Bong\n- Goo\n", - "<ul>\n<li><p>Ting</p></li>\n<li><p>Bong</p></li>\n<li><p>Goo</p></li>\n</ul>\n", + "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n", "*Hello\n", "<p>*Hello</p>\n",@@ -393,10 +393,10 @@ "1. Ting\n2. Bong\n3. Goo\n",
"<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n", "1. Yin\n\n2. Yang\n", - "<ol>\n<li><p>Yin</p></li>\n<li><p>Yang</p></li>\n</ol>\n", + "<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n", "1. Ting\n\n2. Bong\n3. Goo\n", - "<ol>\n<li><p>Ting</p></li>\n<li><p>Bong</p></li>\n<li><p>Goo</p></li>\n</ol>\n", + "<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n", "1 Hello\n", "<p>1 Hello</p>\n",
@@ -252,9 +252,10 @@ }
func (options *Html) BlockQuote(out *bytes.Buffer, text []byte) { + doubleSpace(out) out.WriteString("<blockquote>\n") out.Write(text) - out.WriteString("</blockquote>") + out.WriteString("</blockquote>\n") } func (options *Html) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {@@ -263,7 +264,7 @@ out.WriteString("<table>\n<thead>\n")
out.Write(header) out.WriteString("\n</thead>\n<tbody>\n") out.Write(body) - out.WriteString("\n</tbody>\n</table>") + out.WriteString("\n</tbody>\n</table>\n") } func (options *Html) TableRow(out *bytes.Buffer, text []byte) {@@ -295,9 +296,9 @@ marker := out.Len()
doubleSpace(out) if flags&LIST_TYPE_ORDERED != 0 { - out.WriteString("<ol>\n") + out.WriteString("<ol>") } else { - out.WriteString("<ul>\n") + out.WriteString("<ul>") } if !text() { out.Truncate(marker)@@ -311,6 +312,9 @@ }
} func (options *Html) ListItem(out *bytes.Buffer, text []byte, flags int) { + if flags&LIST_ITEM_CONTAINS_BLOCK != 0 || flags&LIST_ITEM_BEGINNING_OF_LIST != 0 { + doubleSpace(out) + } out.WriteString("<li>") out.Write(text) out.WriteString("</li>\n")
@@ -51,6 +51,7 @@ // These are mostly of interest if you are writing a new output format.
const ( LIST_TYPE_ORDERED = 1 << iota LIST_ITEM_CONTAINS_BLOCK + LIST_ITEM_BEGINNING_OF_LIST LIST_ITEM_END_OF_LIST )
@@ -7,9 +7,11 @@ <li>In a list?</li>
<li><a href="http://example.com/">http://example.com/</a></li> <li>It should.</li> </ul> + <blockquote> <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p> </blockquote> + <p>Auto-links should not occur here: <code><http://example.com/></code></p> <pre><code>or here: <http://example.com/>
@@ -12,4 +12,4 @@ <pre><code>sub status {
return "working"; } </code></pre> -</blockquote>+</blockquote>
@@ -1,7 +1,9 @@
<blockquote> <p>foo</p> + <blockquote> <p>bar</p> </blockquote> + <p>foo</p> -</blockquote>+</blockquote>
@@ -12,7 +12,9 @@ <p>Asterisks loose:</p>
<ul> <li><p>asterisk 1</p></li> + <li><p>asterisk 2</p></li> + <li><p>asterisk 3</p></li> </ul>@@ -30,7 +32,9 @@ <p>Pluses loose:</p>
<ul> <li><p>Plus 1</p></li> + <li><p>Plus 2</p></li> + <li><p>Plus 3</p></li> </ul>@@ -48,7 +52,9 @@ <p>Minuses loose:</p>
<ul> <li><p>Minus 1</p></li> + <li><p>Minus 2</p></li> + <li><p>Minus 3</p></li> </ul>@@ -74,7 +80,9 @@ <p>Loose using tabs:</p>
<ol> <li><p>First</p></li> + <li><p>Second</p></li> + <li><p>Third</p></li> </ol>@@ -82,7 +90,9 @@ <p>and using spaces:</p>
<ol> <li><p>One</p></li> + <li><p>Two</p></li> + <li><p>Three</p></li> </ol>@@ -93,7 +103,9 @@ <li><p>Item 1, graf one.</p>
<p>Item 2. graf two. The quick brown fox jumped over the lazy dog's back.</p></li> + <li><p>Item 2.</p></li> + <li><p>Item 3.</p></li> </ol>@@ -129,6 +141,7 @@ <p>Same thing but with paragraphs:</p>
<ol> <li><p>First</p></li> + <li><p>Second:</p> <ul>@@ -136,6 +149,7 @@ <li>Fee</li>
<li>Fie</li> <li>Foe</li> </ul></li> + <li><p>Third</p></li> </ol>
@@ -1,6 +1,7 @@
<ul> <li><p>this is a list item indented with tabs</p></li> + <li><p>this is a list item indented with spaces</p></li> </ul>
@@ -6,4 +6,4 @@ <li>asterisk 1</li>
<li>asterisk 2</li> <li>asterisk 3</li> </ul> -</blockquote>+</blockquote>