Implemented inline code

This commit is contained in:
Eduard Urbach 2024-04-02 19:13:28 +02:00
parent 68111da0a2
commit a06defdc3d
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 22 additions and 3 deletions

View File

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

View File

@ -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("<code>")
r.WriteString(html.EscapeString(markdown[codeStart:i]))
r.WriteString("</code>")
codeStart = -1
tokenStart = i + 1
} else {
r.WriteString(html.EscapeString(markdown[tokenStart:i]))
tokenStart = i
codeStart = i + 1
}
}
i++

View File

@ -52,6 +52,8 @@ func TestTables(t *testing.T) {
func TestCode(t *testing.T) {
assert.Equal(t, markdown.Render("```\nText\n```"), "<pre><code>Text</code></pre>")
assert.Equal(t, markdown.Render("```go\ntype A struct {\n\t\n}\n```"), "<pre><code class=\"language-go\">type A struct {\n\t\n}</code></pre>")
assert.Equal(t, markdown.Render("`monospace`"), "<p><code>monospace</code></p>")
assert.Equal(t, markdown.Render("Inline `monospace` text."), "<p>Inline <code>monospace</code> text.</p>")
}
func TestQuote(t *testing.T) {