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
34 lines
713 B
Go
34 lines
713 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
|
)
|
|
|
|
type previewRequest struct {
|
|
Markdown string `json:"markdown" binding:"max=100000"`
|
|
}
|
|
|
|
// previewMarkdown renders Markdown exactly as pages will, for the editor's
|
|
// preview tab.
|
|
func (s *Server) previewMarkdown(c *gin.Context) {
|
|
var req previewRequest
|
|
if !bind(c, &req) {
|
|
return
|
|
}
|
|
if !s.limit(c, "md-preview:"+auth.Current(c).UserID.String(), 120, time.Minute) {
|
|
return
|
|
}
|
|
html, err := web.RenderMarkdown(req.Markdown)
|
|
if err != nil {
|
|
internalError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"html": html})
|
|
}
|