diff --git a/Render.go b/Render.go index a2d353d..148bf9a 100644 --- a/Render.go +++ b/Render.go @@ -253,7 +253,6 @@ func (r *renderer) writeText(markdown string) { searchStart = 0 linkTextStart = -1 linkTextEnd = -1 - codeStart = -1 emStart = -1 strongStart = -1 strikeStart = -1 @@ -324,18 +323,20 @@ begin: } case '`': - if codeStart != -1 { - r.WriteString("") - r.WriteString(html.EscapeString(markdown[codeStart:i])) - r.WriteString("") - codeStart = -1 - tokenStart = i + 1 - } else { - r.WriteString(html.EscapeString(markdown[tokenStart:i])) - tokenStart = i - codeStart = i + 1 + end := strings.IndexByte(markdown[searchStart:], '`') + + if end == -1 { + continue } + r.WriteString(html.EscapeString(markdown[tokenStart:i])) + r.WriteString("") + r.WriteString(html.EscapeString(markdown[searchStart : searchStart+end])) + r.WriteString("") + + searchStart += end + 1 + tokenStart = searchStart + case '*', '_': if i == emStart { strongStart = i + 1 diff --git a/Render_test.go b/Render_test.go index 144cc60..9e96cc0 100644 --- a/Render_test.go +++ b/Render_test.go @@ -70,6 +70,7 @@ func TestCode(t *testing.T) { assert.Equal(t, markdown.Render("```\nText\n```"), "
Text
") assert.Equal(t, markdown.Render("```go\ntype A struct {\n\t\n}\n```"), "
type A struct {\n\t\n}
") assert.Equal(t, markdown.Render("`monospace`"), "

monospace

") + assert.Equal(t, markdown.Render("`unfinished"), "

`unfinished

") assert.Equal(t, markdown.Render("Inline `monospace` text."), "

Inline monospace text.

") }