Skip to content

Commit

Permalink
fix: flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiscolin committed Oct 17, 2024
1 parent 244575d commit 48ddbec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gno.land/cmd/gnoweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions gno.land/pkg/gnoweb/gnoweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Config struct {
HelpChainID string
HelpRemote string
WithAnalytics bool
ExpNoHTML bool
WithHTML bool
}

func NewDefaultConfig() Config {
Expand All @@ -58,7 +58,7 @@ func NewDefaultConfig() Config {
HelpChainID: "dev",
HelpRemote: "127.0.0.1:26657",
WithAnalytics: false,
ExpNoHTML: true,
WithHTML: false,
}
}

Expand Down Expand Up @@ -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

Check warning on line 122 in gno.land/pkg/gnoweb/gnoweb.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoweb/gnoweb.go#L122

Added line #L122 was not covered by tests
}

Expand All @@ -129,15 +129,15 @@ func checkHTMLInMarkdown(cfg *Config, content string) string {
return placeholder
})

Check warning on line 130 in gno.land/pkg/gnoweb/gnoweb.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoweb/gnoweb.go#L127-L130

Added lines #L127 - L130 were not covered by tests

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)

Check warning on line 136 in gno.land/pkg/gnoweb/gnoweb.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoweb/gnoweb.go#L135-L136

Added lines #L135 - L136 were not covered by tests
}
}

return contentWithNoHTML
return sanitazedContent
}

// handlerRealmAlias is used to render official pages from realms.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 48ddbec

Please sign in to comment.