diff --git a/gno.land/cmd/gnoweb/main.go b/gno.land/cmd/gnoweb/main.go index 959989ab809..5cec7257ebe 100644 --- a/gno.land/cmd/gnoweb/main.go +++ b/gno.land/cmd/gnoweb/main.go @@ -37,7 +37,7 @@ func runMain(args []string) error { fs.StringVar(&cfg.HelpRemote, "help-remote", cfg.HelpRemote, "help page's remote addr") fs.BoolVar(&cfg.WithAnalytics, "with-analytics", cfg.WithAnalytics, "enable privacy-first analytics") fs.StringVar(&bindAddress, "bind", "127.0.0.1:8888", "server listening address") - fs.BoolVar(&cfg.ExpNoHTML, "exp-no-html", cfg.ExpNoHTML, "Disable HTML parsing in markdown rendering") + fs.BoolVar(&cfg.WithHTML, "with-html", cfg.WithHTML, "Enable HTML parsing in markdown rendering") if err := fs.Parse(args); err != nil { return err diff --git a/gno.land/pkg/gnoweb/gnoweb.go b/gno.land/pkg/gnoweb/gnoweb.go index 357e77c0f0c..0e1a942509b 100644 --- a/gno.land/pkg/gnoweb/gnoweb.go +++ b/gno.land/pkg/gnoweb/gnoweb.go @@ -46,7 +46,7 @@ type Config struct { HelpChainID string HelpRemote string WithAnalytics bool - ExpNoHTML bool + WithHTML bool } func NewDefaultConfig() Config { @@ -58,7 +58,7 @@ func NewDefaultConfig() Config { HelpChainID: "dev", HelpRemote: "127.0.0.1:26657", WithAnalytics: false, - ExpNoHTML: true, + WithHTML: false, } } @@ -117,8 +117,8 @@ var ( htmlTagPattern = regexp.MustCompile(`<\/?\w+[^>]*?>`) ) -func checkHTMLInMarkdown(cfg *Config, content string) string { - if !cfg.ExpNoHTML { +func sanitizeContent(cfg *Config, content string) string { + if cfg.WithHTML { return content } @@ -129,15 +129,15 @@ func checkHTMLInMarkdown(cfg *Config, content string) string { return placeholder }) - contentWithNoHTML := htmlTagPattern.ReplaceAllString(contentWithPlaceholders, "") + sanitazedContent := htmlTagPattern.ReplaceAllString(contentWithPlaceholders, "") if len(placeholders) > 0 { for placeholder, code := range placeholders { - contentWithNoHTML = strings.ReplaceAll(contentWithNoHTML, placeholder, code) + sanitazedContent = strings.ReplaceAll(sanitazedContent, placeholder, code) } } - return contentWithNoHTML + return sanitazedContent } // handlerRealmAlias is used to render official pages from realms. @@ -182,7 +182,7 @@ func handlerRealmAlias(logger *slog.Logger, app gotuna.App, cfg *Config, rlmpath tmpl.Set("RealmPath", rlmpath) tmpl.Set("Query", querystr) tmpl.Set("PathLinks", pathLinks) - tmpl.Set("Contents", checkHTMLInMarkdown(cfg, string(res.Data))) + tmpl.Set("Contents", sanitizeContent(cfg, string(res.Data))) tmpl.Set("Config", cfg) tmpl.Set("IsAlias", true) tmpl.Render(w, r, "realm_render.html", "funcs.html") @@ -370,7 +370,7 @@ func handleRealmRender(logger *slog.Logger, app gotuna.App, cfg *Config, w http. tmpl.Set("RealmPath", rlmpath) tmpl.Set("Query", querystr) tmpl.Set("PathLinks", pathLinks) - tmpl.Set("Contents", checkHTMLInMarkdown(cfg, string(res.Data))) + tmpl.Set("Contents", sanitizeContent(cfg, string(res.Data))) tmpl.Set("Config", cfg) tmpl.Set("HasReadme", hasReadme) tmpl.Render(w, r, "realm_render.html", "funcs.html")