From 9a0217f7aa435282b4ba9139d9141bccca28ab05 Mon Sep 17 00:00:00 2001 From: Russ Ross Date: Mon, 27 Jun 2011 14:35:11 -0600 Subject: [PATCH] fixed minor bugs uncovered by more testing --- block.go | 7 ++++--- block_test.go | 3 +++ inline.go | 18 ++++++------------ inline_test.go | 8 -------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/block.go b/block.go index ba84c67..8b2bfa0 100644 --- a/block.go +++ b/block.go @@ -335,7 +335,7 @@ func blockHtml(out *bytes.Buffer, rndr *render, data []byte, do_render bool) int func blockHtmlFindTag(data []byte) (string, bool) { i := 0 - for i < len(data) && ((data[i] >= '0' && data[i] <= '9') || (data[i] >= 'A' && data[i] <= 'Z') || (data[i] >= 'a' && data[i] <= 'z')) { + for i < len(data) && isalnum(data[i]) { i++ } if i >= len(data) { @@ -352,11 +352,12 @@ func blockHtmlFindEnd(tag string, rndr *render, data []byte) int { // assume data[0] == '<' && data[1] == '/' already tested // check if tag is a match - if len(tag)+3 >= len(data) || bytes.Compare(data[2:2+len(tag)], []byte(tag)) != 0 || data[len(tag)+2] != '>' { + if len(data) < len(tag)+3 || data[len(tag)+2] != '>' || + bytes.Compare(data[2:2+len(tag)], []byte(tag)) != 0 { return 0 } - // check white lines + // check for blank line/eof after the closing tag i := len(tag) + 3 w := 0 if i < len(data) { diff --git a/block_test.go b/block_test.go index 834a7e6..602879b 100644 --- a/block_test.go +++ b/block_test.go @@ -198,6 +198,9 @@ func TestUnderlineHeaders(t *testing.T) { "Trailing spaces\n==== \n\n", "

Trailing spaces

\n", + + "Double underline\n=====\n=====\n", + "

Double underline

\n\n

=====

\n", } doTestsBlock(t, tests, 0) } diff --git a/inline.go b/inline.go index ae3fed1..1556022 100644 --- a/inline.go +++ b/inline.go @@ -123,9 +123,9 @@ func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) in } } + // no matching delimiter? if i < nb && end >= len(data) { - out.WriteByte('`') - return 0 // no matching delimiter + return 0 } // trim outside whitespace @@ -135,22 +135,16 @@ func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) in } f_end := end - nb - for f_end > nb && (data[f_end-1] == ' ' || data[f_end-1] == '\t') { + for f_end > f_begin && (data[f_end-1] == ' ' || data[f_end-1] == '\t') { f_end-- } - // real code span + // render the code span if rndr.mk.CodeSpan == nil { return 0 } - if f_begin < f_end { - if rndr.mk.CodeSpan(out, data[f_begin:f_end], rndr.mk.Opaque) == 0 { - end = 0 - } - } else { - if rndr.mk.CodeSpan(out, nil, rndr.mk.Opaque) == 0 { - end = 0 - } + if rndr.mk.CodeSpan(out, data[f_begin:f_end], rndr.mk.Opaque) == 0 { + end = 0 } return end diff --git a/inline_test.go b/inline_test.go index 4f4f21e..81d21b9 100644 --- a/inline_test.go +++ b/inline_test.go @@ -16,19 +16,11 @@ import ( func runMarkdownInline(input string) string { var extensions uint32 - extensions |= EXTENSION_NO_INTRA_EMPHASIS - extensions |= EXTENSION_TABLES - extensions |= EXTENSION_FENCED_CODE extensions |= EXTENSION_AUTOLINK extensions |= EXTENSION_STRIKETHROUGH - extensions |= EXTENSION_SPACE_HEADERS - extensions |= EXTENSION_LAX_HTML_BLOCKS html_flags := 0 html_flags |= HTML_USE_XHTML - html_flags |= HTML_USE_SMARTYPANTS - html_flags |= HTML_SMARTYPANTS_FRACTIONS - html_flags |= HTML_SMARTYPANTS_LATEX_DASHES renderer := HtmlRenderer(html_flags)