diff --git a/block.go b/block.go index 17bf17c..ba84c67 100644 --- a/block.go +++ b/block.go @@ -1093,14 +1093,23 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int { // 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 diff --git a/block_test.go b/block_test.go index 57e865d..834a7e6 100644 --- a/block_test.go +++ b/block_test.go @@ -91,9 +91,6 @@ func TestPrefixHeaderNoExtensions(t *testing.T) { "* List\n * Nested list\n # Nested header\n", "
List
\n\nNested list
\n\n" + "List
\n\nNested list
\n\n" + "Paragraph
\n\nParagraph
\n", + + "Header\n===\nAnother header\n---\n", + "Code\n
\n\n========
\n", + + "Header with *inline*\n=====\n", + "Paragraph
\n\n