togo-framework/richtext
GitHub: togo-framework/richtext
为 togo 框架提供富文本与 Markdown 的净化、渲染和安全存储能力,确保用户输入的 HTML 始终是 XSS 安全的。
Stars: 0 | Forks: 0
## 安装
```
togo install togo-framework/richtext
```
togo 针对 Rails **Action Text** / Trix 的解决方案。接受用户的富文本,对其进行**净化**并生成安全的白名单(剔除 `")
rt.HTML // "", "text": "..."}`。
## 安全性
HTML 会使用 [bluemonday](https://github.com/microcosm-cc/bluemonday) 的 UGC 策略进行净化;Markdown 会先使用 [goldmark](https://github.com/yuin/goldmark) 进行渲染,然后再进行净化。请始终存储并重新渲染**已净化的** HTML;切勿直接渲染用户的原始输入。
Hi
\nbold
" (script removed) rt.PlainText() // "Hi bold" — tags stripped, entities decoded rt.Excerpt(120)// preview text, ellipsised on a word boundary richtext.Sanitize(htmlStr) // one-off clean richtext.RenderMarkdown(md) // md → sanitized html ``` `RichText` 序列化为 `{"raw": "...", "html": "..."}`,并且**在反序列化时会重新进行净化** —— 永远不会信任已存储的 `html` 字段。 ## REST `POST /api/richtext/render`,传入 `{"markdown":"..."}` 或 `{"html":"..."}` → `{"html": "标签:EVTX分析, Go, HTML过滤, Markdown, Ruby工具, Syscall, Web开发, XSS防御, 富文本处理, 日志审计