diff options
author | Alan Pearce | 2014-09-22 20:16:22 +0100 |
---|---|---|
committer | Alan Pearce | 2014-09-22 20:16:22 +0100 |
commit | 0fe95fe03334c62c2c36f0e3a1d2be167fc4a506 (patch) | |
tree | 6b064bca252bd34bd1d56dfad1d462ca19e1a11c | |
parent | 21830ef89ee29c4dfbaa4340601ef837ffb53159 (diff) | |
download | microformats-0fe95fe03334c62c2c36f0e3a1d2be167fc4a506.tar.lz microformats-0fe95fe03334c62c2c36f0e3a1d2be167fc4a506.tar.zst microformats-0fe95fe03334c62c2c36f0e3a1d2be167fc4a506.zip |
Trim strings when retrieving property values
-rw-r--r-- | src/microformats/parser.clj | 58 | ||||
-rw-r--r-- | test/microformats/parser_expectations.clj | 3 |
2 files changed, 32 insertions, 29 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index de53855..eade3dc 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -56,43 +56,43 @@ (defn get-p-value "Get the p-x property value of an element" [el] - (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) - (first (:content 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) + (first (:content el)) + ""))) (defn get-u-value "Get the u-x property value of an element" [el] - (or (find-value-class el) - (case (:tag el) - :a (-> el :attrs :href) - :area (-> el :attrs :href) - :img (-> el :attrs :src) - :object (-> el :attrs :data) - (get-p-value el)) - (first :content el) - "")) + (str/trim (or (find-value-class el) + (case (:tag el) + :a (-> el :attrs :href) + :area (-> el :attrs :href) + :img (-> el :attrs :src) + :object (-> el :attrs :data) + (get-p-value el)) + (first :content el) + ""))) (defn get-dt-value "Get the dt-x property value of an element" [el] - (or (find-value-class el) - (case (:tag el) - :time (-> el :attrs :datetime) - :ins (-> el :attrs :datetime) - :del (-> el :attrs :datetime) - :abbr (-> el :attrs :title) - :data (-> el :attrs :value) - :input (-> el :attrs :value)) - (first (:content el)) - "")) + (str/trim (or (find-value-class el) + (case (:tag el) + :time (-> el :attrs :datetime) + :ins (-> el :attrs :datetime) + :del (-> el :attrs :datetime) + :abbr (-> el :attrs :title) + :data (-> el :attrs :value) + :input (-> el :attrs :value)) + (first (:content el)) + ""))) (defn- node-to-html "Turn a node into a list of HTML strings" diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj index 498d8e1..05cc052 100644 --- a/test/microformats/parser_expectations.clj +++ b/test/microformats/parser_expectations.clj @@ -116,5 +116,8 @@ (expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}} (parse "<div class=\"h-card\"><p class=\"p-name\">Example User</p></div>")) +(expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}} + (parse "<div class=\"h-card\"><p class=\"p-name\"> Example User </p></div>")) + (expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}} (parse "<p class=\"h-card\">Example User</p>")) |