-
Notifications
You must be signed in to change notification settings - Fork 51
/
utils.cljc
49 lines (41 loc) · 1.22 KB
/
utils.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns hickory.utils
"Miscellaneous utilities used internally."
(:require [clojure.string :as string]
#?(:clj
[quoin.text :as qt]
:cljs [goog.string :as gstring])))
;;
;; Data
;;
(def void-element
"Elements that don't have a meaningful <tag></tag> form."
#{:area :base :br :col :command :embed :hr :img :input :keygen :link :meta
:param :source :track :wbr})
(def unescapable-content
"Elements whose content should never have html-escape codes."
#{:script :style})
;;
;; String utils
;;
(defn html-escape
[s]
#?(:clj (qt/html-escape s)
:cljs (gstring/htmlEscape s)))
(defn starts-with
[^String s ^String prefix]
#?(:clj (.startsWith s prefix)
:cljs (goog.string.startsWith s prefix)))
(defn lower-case-keyword
"Converts its string argument into a lowercase keyword."
[s]
(-> s string/lower-case keyword))
(defn render-doctype
"Returns a string containing the HTML source for the doctype with given args.
The second and third arguments can be nil or empty strings."
[name publicid systemid]
(str "<!DOCTYPE " name
(when (not-empty publicid)
(str " PUBLIC \"" publicid "\""))
(when (not-empty systemid)
(str " \"" systemid "\""))
">"))