-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
joker.html/escape, joker.html/unescape
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
|
||
} |