diff --git a/main.go b/main.go index 856bdc26f..44b3f51a3 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( . "github.com/candid82/joker/core" _ "github.com/candid82/joker/std/base64" + _ "github.com/candid82/joker/std/html" _ "github.com/candid82/joker/std/http" _ "github.com/candid82/joker/std/json" _ "github.com/candid82/joker/std/math" diff --git a/std/generate-std.joke b/std/generate-std.joke index ca3d49012..177bf6b64 100644 --- a/std/generate-std.joke +++ b/std/generate-std.joke @@ -1,4 +1,4 @@ -(def namespaces ['string 'json 'base64 'os 'time 'yaml 'http 'math]) +(def namespaces ['string 'json 'base64 'os 'time 'yaml 'http 'math 'html]) (apply require namespaces) diff --git a/std/html.joke b/std/html.joke new file mode 100644 index 000000000..a646a723e --- /dev/null +++ b/std/html.joke @@ -0,0 +1,16 @@ +(ns + ^{:go-imports ["html"] + :doc "Provides functions for escaping and unescaping HTML text."} + html) + +(defn ^String escape + "Escapes special characters like < to become <. It escapes only five such characters: <, >, &, ' and \"." + {:added "1.0" + :go "html.EscapeString(s)"} + [^String s]) + +(defn ^String unescape + "Unescapes entities like < to become <." + {:added "1.0" + :go "html.UnescapeString(s)"} + [^String s]) diff --git a/std/html/a_html.go b/std/html/a_html.go new file mode 100644 index 000000000..683ed5338 --- /dev/null +++ b/std/html/a_html.go @@ -0,0 +1,57 @@ +// This file is generated by generate-std.joke script. Do not edit manually! + +package html + +import ( + "html" + . "github.com/candid82/joker/core" +) + +var htmlNamespace = GLOBAL_ENV.EnsureNamespace(MakeSymbol("joker.html")) + +var escape_ Proc = func(args []Object) Object { + c := len(args) + switch { + case c == 1: + + s := ExtractString(args, 0) + res := html.EscapeString(s) + return MakeString(res) + + default: + PanicArity(c) + } + return NIL +} + +var unescape_ Proc = func(args []Object) Object { + c := len(args) + switch { + case c == 1: + + s := ExtractString(args, 0) + res := html.UnescapeString(s) + return MakeString(res) + + default: + PanicArity(c) + } + return NIL +} + + +func init() { + +htmlNamespace.ResetMeta(MakeMeta(nil, "Provides functions for escaping and unescaping HTML text.", "1.0")) + +htmlNamespace.InternVar("escape", escape_, + MakeMeta( + NewListFrom(NewVectorFrom(MakeSymbol("s"))), + `Escapes special characters like < to become <. It escapes only five such characters: <, >, &, ' and ".`, "1.0")) + +htmlNamespace.InternVar("unescape", unescape_, + MakeMeta( + NewListFrom(NewVectorFrom(MakeSymbol("s"))), + `Unescapes entities like < to become <.`, "1.0")) + +}