Skip to content

Commit

Permalink
joker.html/escape, joker.html/unescape
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Mar 25, 2018
1 parent cae8927 commit d91cead
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions main.go
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion 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)

Expand Down
16 changes: 16 additions & 0 deletions 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 &lt;. It escapes only five such characters: <, >, &, ' and \"."
{:added "1.0"
:go "html.EscapeString(s)"}
[^String s])

(defn ^String unescape
"Unescapes entities like &lt; to become <."
{:added "1.0"
:go "html.UnescapeString(s)"}
[^String s])
57 changes: 57 additions & 0 deletions 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 &lt;. It escapes only five such characters: <, >, &, ' and ".`, "1.0"))

htmlNamespace.InternVar("unescape", unescape_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Unescapes entities like &lt; to become <.`, "1.0"))

}

0 comments on commit d91cead

Please sign in to comment.