diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index fbe1327..d31d938 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -1,6 +1,7 @@ package stdlib import ( + "html" "strings" "text/template" @@ -25,10 +26,6 @@ func New(api *confluence.API) (*Lib, error) { return nil, err } - if err != nil { - return nil, err - } - return &lib, nil } @@ -67,6 +64,9 @@ func templates(api *confluence.API) (*template.Template, error) { "_", ) }, + "xmlesc": func(s string) string { + return html.EscapeString(s) + }, }, ) @@ -90,20 +90,20 @@ func templates(api *confluence.API) (*template.Template, error) { // This template is used for rendering code in ``` `ac:code`: text( ``, - /**/ `{{ .Language }}`, + /**/ `{{ .Language | xmlesc }}`, /**/ `{{ .Collapse }}`, - /**/ `{{ if .Theme }}{{ .Theme }}{{ end }}`, + /**/ `{{ if .Theme }}{{ .Theme | xmlesc }}{{ end }}`, /**/ `{{ if .Linenumbers }}{{ .Linenumbers }}{{ end }}`, /**/ `{{ if .Firstline }}{{ .Firstline }}{{ end }}`, - /**/ `{{ if .Title }}{{ .Title }}{{ end }}`, + /**/ `{{ if .Title }}{{ .Title | xmlesc }}{{ end }}`, /**/ ``, ``, ), `ac:status`: text( ``, - `{{ or .Color "Grey" }}`, - `{{ or .Title .Color }}`, + `{{ or .Color "Grey" | xmlesc }}`, + `{{ or .Title .Color | xmlesc }}`, `{{ or .Subtle false }}`, ``, ), @@ -161,7 +161,7 @@ func templates(api *confluence.API) (*template.Template, error) { `ac:box`: text( ``, `{{ or .Icon "false" }}`, - `{{ if .Title }}{{ .Title }}{{ end }}`, + `{{ if .Title }}{{ .Title | xmlesc }}{{ end }}`, `{{ .Body }}`, ``, ),