diff options
author | Alan Pearce | 2014-09-23 21:38:11 +0100 |
---|---|---|
committer | Alan Pearce | 2014-09-23 21:38:11 +0100 |
commit | 648699e0c15773bc332b2876ad0aa21c897e3654 (patch) | |
tree | e362e91b4f88215297bcacdbc15071f8f39cd138 /src | |
parent | 2bf7f18a47beb329f6dcd3776a819d6541cff166 (diff) | |
download | microformats-648699e0c15773bc332b2876ad0aa21c897e3654.tar.lz microformats-648699e0c15773bc332b2876ad0aa21c897e3654.tar.zst microformats-648699e0c15773bc332b2876ad0aa21c897e3654.zip |
Add full support for implied names
Diffstat (limited to 'src')
-rw-r--r-- | src/microformats/parser.clj | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index b28fce7..875caec 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -3,6 +3,16 @@ [clojure.core.reducers :as r] [clojure.string :as str])) +(defmacro cond-let + [& clauses] + (when clauses + (list 'if-let ['x (first clauses)] + (if (next clauses) + (second clauses) + (throw (IllegalArgumentException. + "cond-let requires an even number of forms"))) + (cons 'cond-let (next (next clauses)))))) + (defn mf-names-from-class "Get microformat classnames from a class attribute" [prefix] @@ -165,8 +175,18 @@ "Imply the name of an entity from the element" [element] (case (:tag element) + :abbr (-> element :attrs :title) :img (-> element :attrs :alt) - (node-to-text (:content element)))) + (cond-let + (first (html/select element [html/root :> [:img html/only-child]])) + (-> x :attrs :alt) + (first (html/select element [html/root :> [:abbr html/only-child (html/attr? :title)]])) + (-> x :attrs :title) + (first (html/select element [html/root :> html/only-child :> [:img html/only-child]])) + (-> x :attrs :alt) + (first (html/select element [html/root :> html/only-child :> [:abbr html/only-child (html/attr? :title)]])) + (-> x :attrs :title) + true (node-to-text (:content element))))) (defn- imply-url [element] |