fixed minor bugs uncovered by more testing

This commit is contained in:
Russ Ross 2011-06-27 14:35:11 -06:00
parent 47c4852520
commit 9a0217f7aa
4 changed files with 13 additions and 23 deletions

View File

@ -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) {

View File

@ -198,6 +198,9 @@ func TestUnderlineHeaders(t *testing.T) {
"Trailing spaces\n==== \n\n",
"<h1>Trailing spaces</h1>\n",
"Double underline\n=====\n=====\n",
"<h1>Double underline</h1>\n\n<p>=====</p>\n",
}
doTestsBlock(t, tests, 0)
}

View File

@ -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,23 +135,17 @@ 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
}
}
return end

View File

@ -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)