diff --git a/README.md b/README.md index 5d653b8..556e92a 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ coverage: 100.0% of statements ## Benchmarks ``` -BenchmarkSmall-12 8899971 131.5 ns/op 32 B/op 1 allocs/op -BenchmarkMedium-12 980007 1217 ns/op 512 B/op 1 allocs/op -BenchmarkLarge-12 315229 3554 ns/op 2560 B/op 2 allocs/op +BenchmarkSmall-12 8495775 140.9 ns/op 32 B/op 1 allocs/op +BenchmarkMedium-12 729133 1457 ns/op 512 B/op 1 allocs/op +BenchmarkLarge-12 293284 3831 ns/op 2560 B/op 2 allocs/op ``` ## License diff --git a/Render.go b/Render.go index 862b53c..07c6de3 100644 --- a/Render.go +++ b/Render.go @@ -253,6 +253,7 @@ func (r *renderer) writeText(markdown string) { textEnd = -1 urlStart = -1 parentheses = 0 + codeStart = -1 ) for { @@ -268,14 +269,17 @@ func (r *renderer) writeText(markdown string) { r.WriteString(html.EscapeString(markdown[tokenStart:i])) tokenStart = i textStart = i + case ']': textEnd = i + case '(': if parentheses == 0 { urlStart = i } parentheses++ + case ')': parentheses-- @@ -295,6 +299,19 @@ func (r *renderer) writeText(markdown string) { tokenStart = i + 1 } + + 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 + } } i++ diff --git a/Render_test.go b/Render_test.go index 30a2cac..212a077 100644 --- a/Render_test.go +++ b/Render_test.go @@ -52,6 +52,8 @@ func TestTables(t *testing.T) { 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("Inline `monospace` text."), "

Inline monospace text.

") } func TestQuote(t *testing.T) {