all repos — grayfriday @ 47c48525200b30e3ac433fae66d6f0bad7911953

blackfriday fork with a few changes

unit tests for underlined headers, improved whitespace handling for the same
Russ Ross russ@dixie.edu
Mon, 27 Jun 2011 11:42:38 -0600
commit

47c48525200b30e3ac433fae66d6f0bad7911953

parent

3af64a90ad74a0c4bd13fc63b41b298b8a09ac21

2 files changed, 56 insertions(+), 6 deletions(-)

jump to
M block.goblock.go

@@ -1093,14 +1093,23 @@ if level := isUnderlinedHeader(current); level > 0 {

// render the paragraph 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 - // 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 { return func() bool { parseInline(o, r, d) return true } - }(out, rndr, data[prev:i-1]) + }(out, rndr, data[prev:eol]) rndr.mk.Header(out, work, level, rndr.mk.Opaque) // find the end of the underline
M block_test.goblock_test.go

@@ -91,9 +91,6 @@

"* 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" + "<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) }

@@ -154,9 +151,53 @@

"* 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" + "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n", + } + 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, EXTENSION_SPACE_HEADERS) + doTestsBlock(t, tests, 0) }