mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
unit tests for underlined headers, improved whitespace handling for the same
This commit is contained in:
parent
3af64a90ad
commit
47c4852520
13
block.go
13
block.go
|
@ -1093,14 +1093,23 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int {
|
||||||
// render the paragraph
|
// render the paragraph
|
||||||
renderParagraph(out, rndr, data[:prev])
|
renderParagraph(out, rndr, data[:prev])
|
||||||
|
|
||||||
|
// ignore leading and trailing whitespace
|
||||||
|
eol := i - 1
|
||||||
|
for prev < eol && (data[prev] == ' ' || data[prev] == '\t') {
|
||||||
|
prev++
|
||||||
|
}
|
||||||
|
for eol > prev && (data[eol-1] == ' ' || data[eol-1] == '\t') {
|
||||||
|
eol--
|
||||||
|
}
|
||||||
|
|
||||||
// render the header
|
// render the header
|
||||||
// this ugly, convoluted closure avoids forcing variables onto the heap
|
// this ugly double closure avoids forcing variables onto the heap
|
||||||
work := func(o *bytes.Buffer, r *render, d []byte) func() bool {
|
work := func(o *bytes.Buffer, r *render, d []byte) func() bool {
|
||||||
return func() bool {
|
return func() bool {
|
||||||
parseInline(o, r, d)
|
parseInline(o, r, d)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}(out, rndr, data[prev:i-1])
|
}(out, rndr, data[prev:eol])
|
||||||
rndr.mk.Header(out, work, level, rndr.mk.Opaque)
|
rndr.mk.Header(out, work, level, rndr.mk.Opaque)
|
||||||
|
|
||||||
// find the end of the underline
|
// find the end of the underline
|
||||||
|
|
|
@ -91,9 +91,6 @@ func TestPrefixHeaderNoExtensions(t *testing.T) {
|
||||||
"* List\n * Nested list\n # Nested header\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" +
|
"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
|
||||||
"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
|
"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
|
||||||
|
|
||||||
"* List\n * Sublist\n Not a header\n ------\n",
|
|
||||||
"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
|
|
||||||
}
|
}
|
||||||
doTestsBlock(t, tests, 0)
|
doTestsBlock(t, tests, 0)
|
||||||
}
|
}
|
||||||
|
@ -154,9 +151,53 @@ func TestPrefixHeaderSpaceExtension(t *testing.T) {
|
||||||
"* List\n * Nested list\n # Nested header\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" +
|
"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
|
||||||
"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
|
"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
|
||||||
|
|
||||||
"* List\n * Sublist\n Not a header\n ------\n",
|
|
||||||
"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
|
|
||||||
}
|
}
|
||||||
doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)
|
doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnderlineHeaders(t *testing.T) {
|
||||||
|
var tests = []string{
|
||||||
|
"Header 1\n========\n",
|
||||||
|
"<h1>Header 1</h1>\n",
|
||||||
|
|
||||||
|
"Header 2\n--------\n",
|
||||||
|
"<h2>Header 2</h2>\n",
|
||||||
|
|
||||||
|
"A\n=\n",
|
||||||
|
"<h1>A</h1>\n",
|
||||||
|
|
||||||
|
"B\n-\n",
|
||||||
|
"<h2>B</h2>\n",
|
||||||
|
|
||||||
|
"Paragraph\nHeader\n=\n",
|
||||||
|
"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
|
||||||
|
|
||||||
|
"Header\n===\nParagraph\n",
|
||||||
|
"<h1>Header</h1>\n\n<p>Paragraph</p>\n",
|
||||||
|
|
||||||
|
"Header\n===\nAnother header\n---\n",
|
||||||
|
"<h1>Header</h1>\n\n<h2>Another header</h2>\n",
|
||||||
|
|
||||||
|
" Header\n======\n",
|
||||||
|
"<h1>Header</h1>\n",
|
||||||
|
|
||||||
|
" Code\n========\n",
|
||||||
|
"<pre><code>Code\n</code></pre>\n\n<p>========</p>\n",
|
||||||
|
|
||||||
|
"Header with *inline*\n=====\n",
|
||||||
|
"<h1>Header with <em>inline</em></h1>\n",
|
||||||
|
|
||||||
|
"* List\n * Sublist\n Not a header\n ------\n",
|
||||||
|
"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
|
||||||
|
|
||||||
|
"Paragraph\n\n\n\n\nHeader\n===\n",
|
||||||
|
"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
|
||||||
|
|
||||||
|
"Trailing space \n==== \n\n",
|
||||||
|
"<h1>Trailing space</h1>\n",
|
||||||
|
|
||||||
|
"Trailing spaces\n==== \n\n",
|
||||||
|
"<h1>Trailing spaces</h1>\n",
|
||||||
|
}
|
||||||
|
doTestsBlock(t, tests, 0)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user