about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2014-09-28 19:21:55 +0100
committerAlan Pearce2014-09-28 19:21:55 +0100
commit2beb34d0d9481faa111567b6faf019c0c179c591 (patch)
treeff3282f6615fad6aff575006cdd5b28d64d130c1 /src
parentb1e28b8b122a46951ab8e17f010ab58fd06f9524 (diff)
downloadmicroformats-2beb34d0d9481faa111567b6faf019c0c179c591.tar.lz
microformats-2beb34d0d9481faa111567b6faf019c0c179c591.tar.zst
microformats-2beb34d0d9481faa111567b6faf019c0c179c591.zip
Parse properties for child microformats
Diffstat (limited to 'src')
-rw-r--r--src/microformats/parser.clj39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index 32d0331..27c1388 100644
--- a/src/microformats/parser.clj
+++ b/src/microformats/parser.clj
@@ -79,19 +79,38 @@
   (when-let [values (seq (html/select el [html/root :> :.value]))]
     (get-value-class values)))
 
+(declare parse-h)
+
+(defn get-child-mf-properties
+  [element]
+  (assoc (parse-h element) :value (-> element :content node-to-text)))
+
+(defn remove-property-classes
+  [element]
+  (into {} (html/transform (list element) [html/root]
+                           (apply html/remove-class (filter (prefixed-by? "p-")
+                                                            (element-to-classes element))))))
+
+(defn- find-child-mf
+  "Find child property microformats of an element."
+  [element]
+  (when (-> element :attrs :class (.indexOf "h-") (>= 0))
+    (-> element remove-property-classes get-child-mf-properties)))
+
 (defn get-p-value
   "Get the p-x property value of an element"
   [el]
-  (str/trim (or (find-value-class el)
-                (case (:tag el)
-                  :img (-> el :attrs :alt)
-                  :area (-> el :attrs :alt)
-                  :abbr (-> el :attrs :title)
-                  :data (-> el :attrs :value)
-                  :input (-> el :attrs :value)
-                  nil)
-                (node-to-text (:content el))
-                "")))
+  (or (find-child-mf el)
+      (str/trim (or (find-value-class el)
+                    (case (:tag el)
+                      :img (-> el :attrs :alt)
+                      :area (-> el :attrs :alt)
+                      :abbr (-> el :attrs :title)
+                      :data (-> el :attrs :value)
+                      :input (-> el :attrs :value)
+                      nil)
+                    (node-to-text (:content el))
+                    ""))))
 
 (defn get-u-value
   "Get the u-x property value of an element"