Legal documents, maintenance and status page descriptions get an editor with a toolbar of the formatting their field supports, keyboard shortcuts, list continuation, a character count and a preview rendered by the server. Images are no longer rendered: an external image on a status page would hand every visitor's address to its host, so the editor offers none. Editor behavior is tested in a headless browser when Chromium is available. Closes #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
28 lines
805 B
Go
28 lines
805 B
Go
package web
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderMarkdown(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
in, want, notWant string
|
|
}{
|
|
{"**bold** _it_ ~~gone~~", "<strong>bold</strong> <em>it</em> <del>gone</del>", ""},
|
|
{"", "tracker", "<img"},
|
|
{"<script>alert(1)</script>", "", "<script"},
|
|
{"[x](javascript:alert(1))", "", "javascript:"},
|
|
{"| a | b |\n|---|---|\n| 1 | 2 |", "<table>", ""},
|
|
{"see https://example.com", `<a href="https://example.com">`, ""},
|
|
} {
|
|
got, err := RenderMarkdown(tc.in)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(got, tc.want) || (tc.notWant != "" && strings.Contains(got, tc.notWant)) {
|
|
t.Errorf("RenderMarkdown(%q) = %q, want %q without %q", tc.in, got, tc.want, tc.notWant)
|
|
}
|
|
}
|
|
}
|