mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
more consistent spacing of block-level elements
This commit is contained in:
parent
d4353d99fa
commit
689f6cb79b
2
block.go
2
block.go
|
@ -942,6 +942,7 @@ func (parser *Parser) blockOliPrefix(data []byte) int {
|
|||
// 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 @@ func (parser *Parser) blockList(out *bytes.Buffer, data []byte, flags int) int {
|
|||
if j == 0 || flags&LIST_ITEM_END_OF_LIST != 0 {
|
||||
break
|
||||
}
|
||||
flags &= ^LIST_ITEM_BEGINNING_OF_LIST
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -86,10 +86,10 @@ func TestPrefixHeaderNoExtensions(t *testing.T) {
|
|||
"<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 @@ func TestPrefixHeaderSpaceExtension(t *testing.T) {
|
|||
"<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 @@ func TestUnorderedList(t *testing.T) {
|
|||
"<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 @@ func TestUnorderedList(t *testing.T) {
|
|||
"<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 @@ func TestUnorderedList(t *testing.T) {
|
|||
"<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 @@ func TestOrderedList(t *testing.T) {
|
|||
"<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",
|
||||
|
|
12
html.go
12
html.go
|
@ -252,9 +252,10 @@ func (options *Html) BlockCodeGithub(out *bytes.Buffer, text []byte, lang string
|
|||
|
||||
|
||||
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 @@ func (options *Html) Table(out *bytes.Buffer, header []byte, body []byte, column
|
|||
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 @@ func (options *Html) List(out *bytes.Buffer, text func() bool, flags int) {
|
|||
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) List(out *bytes.Buffer, text func() bool, flags int) {
|
|||
}
|
||||
|
||||
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 @@ const (
|
|||
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><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 @@
|
|||
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 @@
|
|||
|
||||
<ul>
|
||||
<li><p>asterisk 1</p></li>
|
||||
|
||||
<li><p>asterisk 2</p></li>
|
||||
|
||||
<li><p>asterisk 3</p></li>
|
||||
</ul>
|
||||
|
||||
|
@ -30,7 +32,9 @@
|
|||
|
||||
<ul>
|
||||
<li><p>Plus 1</p></li>
|
||||
|
||||
<li><p>Plus 2</p></li>
|
||||
|
||||
<li><p>Plus 3</p></li>
|
||||
</ul>
|
||||
|
||||
|
@ -48,7 +52,9 @@
|
|||
|
||||
<ul>
|
||||
<li><p>Minus 1</p></li>
|
||||
|
||||
<li><p>Minus 2</p></li>
|
||||
|
||||
<li><p>Minus 3</p></li>
|
||||
</ul>
|
||||
|
||||
|
@ -74,7 +80,9 @@
|
|||
|
||||
<ol>
|
||||
<li><p>First</p></li>
|
||||
|
||||
<li><p>Second</p></li>
|
||||
|
||||
<li><p>Third</p></li>
|
||||
</ol>
|
||||
|
||||
|
@ -82,7 +90,9 @@
|
|||
|
||||
<ol>
|
||||
<li><p>One</p></li>
|
||||
|
||||
<li><p>Two</p></li>
|
||||
|
||||
<li><p>Three</p></li>
|
||||
</ol>
|
||||
|
||||
|
@ -93,7 +103,9 @@
|
|||
|
||||
<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 @@ back.</p></li>
|
|||
|
||||
<ol>
|
||||
<li><p>First</p></li>
|
||||
|
||||
<li><p>Second:</p>
|
||||
|
||||
<ul>
|
||||
|
@ -136,6 +149,7 @@ back.</p></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 2</li>
|
||||
<li>asterisk 3</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
|
Loading…
Reference in New Issue
Block a user