Implemented inline code
This commit is contained in:
parent
68111da0a2
commit
a06defdc3d
@ -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
|
||||
|
17
Render.go
17
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("<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++
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user