feat(web): Markdown editor with toolbar limited to what is rendered
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
This commit is contained in:
1 parent
532bb0d1b0
commit
d7126b1e2c
20 files changed
+1206
-602
No files matched your search
+20
-2
@@ -4,7 +4,10 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/ast"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/renderer"
|
||||
"github.com/yuin/goldmark/util"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
)
|
||||
@@ -23,8 +26,23 @@ type LegalLink struct {
|
||||
}
|
||||
|
||||
// markdown renders untrusted input: goldmark drops raw HTML and links with
|
||||
// dangerous schemes such as javascript: unless told otherwise.
|
||||
var markdown = goldmark.New(goldmark.WithExtensions(extension.Table, extension.Linkify, extension.Strikethrough))
|
||||
// dangerous schemes such as javascript: unless told otherwise. Images are
|
||||
// shown as their alt text: on a status page an external image would hand
|
||||
// every visitor's address to its host.
|
||||
var markdown = goldmark.New(
|
||||
goldmark.WithExtensions(extension.Table, extension.Linkify, extension.Strikethrough),
|
||||
goldmark.WithRendererOptions(renderer.WithNodeRenderers(util.Prioritized(altTextImages{}, 100))),
|
||||
)
|
||||
|
||||
type altTextImages struct{}
|
||||
|
||||
// RegisterFuncs implements renderer.NodeRenderer.
|
||||
func (altTextImages) RegisterFuncs(r renderer.NodeRendererFuncRegisterer) {
|
||||
r.Register(ast.KindImage, func(w util.BufWriter, src []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||
// The children are the alt text and render as usual.
|
||||
return ast.WalkContinue, nil
|
||||
})
|
||||
}
|
||||
|
||||
// RenderMarkdown converts src to HTML that is safe to embed.
|
||||
func RenderMarkdown(src string) (string, error) {
|
||||
|
||||
Reference in new issue
Block a user