about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2014-10-19 17:32:42 +0100
committerAlan Pearce2014-10-19 17:32:42 +0100
commitcfc7b8399308136d62f172a4d522652d0097bb96 (patch)
treec815fbd25bce28751b7b8e6fe3a37c8436c633f8 /src
parente741d80aac6cc88ba7101585924d070a35583e5b (diff)
downloadmicroformats-master.tar.lz
microformats-master.tar.zst
microformats-master.zip
Join multiple u/dt value elements without spaces HEAD master main
Diffstat (limited to 'src')
-rw-r--r--src/microformats/parser.clj21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index e0e2310..f5d18d9 100644
--- a/src/microformats/parser.clj
+++ b/src/microformats/parser.clj
@@ -114,20 +114,21 @@
 
 (defn get-value-class
   "Get the value class of elements"
-  [elements]
-  (str/join " " (into [] ((comp (r/map (partial apply str))
-                                (r/map node-to-text)
-                                (r/map :content))
-                          elements))))
+  [elements ws?]
+  (str/join (if ws? " " "")
+            (into [] ((comp (r/map (partial apply str))
+                            (r/map node-to-text)
+                            (r/map :content))
+                      elements))))
 
 (defn find-value-class
   "Find and get the value class of elements"
-  [el]
+  [el ws?]
   (anacond
    (not-empty (html/select el [html/root :> :.value-title]))
    (get-value-title-class %)
    (not-empty (html/select el [html/root :> :.value ]))
-   (get-value-class %)))
+   (get-value-class % ws?)))
 
 (declare parse-h)
 
@@ -152,7 +153,7 @@
   [loc]
   (let [el (z/node loc)]
     (or (find-child-mf loc)
-        (str/trim (or (find-value-class el)
+        (str/trim (or (find-value-class el true)
                       (case (:tag el)
                         :img (-> el :attrs :alt)
                         :area (-> el :attrs :alt)
@@ -167,7 +168,7 @@
   "Get the u-x property value of an element"
   [loc]
   (let [el (z/node loc)]
-    (str/trim (or (find-value-class el)
+    (str/trim (or (find-value-class el nil)
                   (case (:tag el)
                     :a (normalise-url (z/root loc) (-> el :attrs :href))
                     :area (normalise-url (z/root loc) (-> el :attrs :href))
@@ -181,7 +182,7 @@
   "Get the dt-x property value of an element"
   [loc]
   (let [el (z/node loc)]
-    (str/trim (or (find-value-class el)
+    (str/trim (or (find-value-class el nil)
                   (case (:tag el)
                     :time (-> el :attrs :datetime)
                     :ins  (-> el :attrs :datetime)