fix(preview): static-notice, simplify transform, HTML-safe rendering
- Add static-notice banner: 'Gmail/Outlook simulation is approximate. Use dev mode for accurate rendering.' Hidden in dev mode via WebSocket try/catch, auto-shown in file:// mode on WS failure. - Simplify transform(): Gmail/Outlook modes now return same HTML as Modern — the dev server with Juice provides actual client sim. - Add markSafeHTML(): converts RenderedNote/Body/RenderedContent from plain string to template.HTML so markdown-rendered HTML content is not escaped by Go's html/template engine. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0cd5e32f4
commit
13c49d2087
2 files changed
+78
-15
No files matched your search
@@ -165,6 +165,11 @@ func renderTheme(themeDir, themeName string, cfg *config.TemplatesConfig) ThemeS
|
||||
}
|
||||
data["locale"] = Locale{}
|
||||
|
||||
// Convert HTML-safe fields from string to template.HTML so Go's
|
||||
// html/template renders them raw instead of escaping. Matches Gitea's
|
||||
// behavior where RenderedNote / Body / RenderedContent are template.HTML.
|
||||
markSafeHTML(data)
|
||||
|
||||
// Parse and execute
|
||||
tmpl, err := template.New(tplID).Funcs(TemplateFuncs).Parse(string(tmplContent))
|
||||
if err != nil {
|
||||
@@ -276,6 +281,31 @@ func PrintDetailedSummary(result *PreviewResult, themesDir string, cfg *config.T
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// markSafeHTML recursively converts known HTML-containing string fields to
|
||||
// template.HTML so Go's html/template renders them raw instead of escaping.
|
||||
// These fields mirror Gitea's data model where rendered markdown is typed as
|
||||
// template.HTML: Release.RenderedNote, Body (comment content), and
|
||||
// ReviewComments[].RenderedContent.
|
||||
func markSafeHTML(data map[string]any) {
|
||||
for k, v := range data {
|
||||
switch val := v.(type) {
|
||||
case string:
|
||||
if k == "RenderedNote" || k == "Body" || k == "RenderedContent" {
|
||||
data[k] = template.HTML(val)
|
||||
}
|
||||
case map[string]any:
|
||||
markSafeHTML(val)
|
||||
case []any:
|
||||
for i, item := range val {
|
||||
if m, ok := item.(map[string]any); ok {
|
||||
markSafeHTML(m)
|
||||
val[i] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func formatSize(bytes int64) string {
|
||||
const unit = 1024
|
||||
if bytes < unit {
|
||||
|
||||
Reference in new issue
Block a user