Skip to content

Instantly share code, notes, and snippets.

@isaksky
Created July 2, 2013 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaksky/5906464 to your computer and use it in GitHub Desktop.
Save isaksky/5906464 to your computer and use it in GitHub Desktop.
core.match example
(defn interactive-content?
"Check if an html element (in hiccup form) is interactive content. See http://www.w3.org/html/wg/drafts/html/master/dom.html#interactive-content-0"
[node]
(match node
[(:or :a :button :details :embed :iframe :keygen :label :select :textarea :video) & _] true
[(:or :audio :video) {:controls _} & _] true
[ (:or :img :object) {:usemap _} & _] true
[:input attrs & _ ] (not (= "hidden"(:type attrs)))
:else false))
(def ex1
[:a
{:shape "rect", :href "http://www.github.com/isaksky"}
[:img
{:class "gh-icon",
:src "img/blacktocat-16-d97e09c0.png",
:width "16",
:height "16"}]
"Github"])
(interactive-content? ex1) => true
(def ex2 [:input {:type "hidden", :name "utf8", :value "1"}])
(interactive-content? ex2) => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment