diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/microformats/parser.clj | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index f348f3b..ab14cd6 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -171,8 +171,8 @@ (r/filter (mf-names-from-class "h-")) (into []))) -(defn- imply-name - "Imply the name of an entity from the element" +(defn- parse-implied-name + "Get the implied name of an entity" [element] (case (:tag element) :abbr (-> element :attrs :title) @@ -188,25 +188,38 @@ (-> % :attrs :title) true (node-to-text (:content element))))) -(defn- imply-url +(defn- parse-implied-url [element] (case (:tag element) :a (-> element :attrs :href) nil)) -(defn- imply-photo +(defn- parse-implied-photo [element] (case (:tag element) :img (-> element :attrs :src) - nil)) + :object (-> element :attrs :data) + (cond-let + (first (html/select element [html/root :> [:img (html/but-node (html/attr-contains :class "h-")) html/only-of-type]])) + (-> % :attrs :src) + (first (html/select element [html/root :> [:object (html/but-node (html/attr-contains :class "h-")) html/only-of-type]])) + (-> % :attrs :data) + (first (html/select element [html/root :> html/only-child :> [:img (html/but-node (html/attr-contains :class "h-")) html/only-of-type]])) + (-> % :attrs :src) + (first (html/select element [html/root :> html/only-child :> [:object (html/but-node (html/attr-contains :class "h-")) html/only-of-type]])) + (-> % :attrs :data) + ))) + +(def empty-ish + #(not (str/blank? (first (second %))))) (defn parse-implied "Parse implied properties of a HTML element" [element] - (into {} (filter #(first (second %)) - {:name (list (imply-name element)) - :url (list (imply-url element)) - :photo (list (imply-photo element))}))) + (into {} (filter empty-ish + {:name (list (parse-implied-name element)) + :url (list (parse-implied-url element)) + :photo (list (parse-implied-photo element))}))) (defn get-mf-properties "Parse children of a microformat, returning a map of properties" |