all repos — archive/microformats @ 1ebede4bbab4fc1315cc0bf5fdc402a29eab34e1

Incomplete Clojure microformats library

Fallback to text content if attributes are not found

Alan Pearce
commit

1ebede4bbab4fc1315cc0bf5fdc402a29eab34e1

parent

5955c420a37fdb57eeeeb04c0f649b9d922f7fde

2 files changed, 31 insertions(+), 15 deletions(-)

changed files
M src/microformats/parser.cljsrc/microformats/parser.clj
@@ -35,23 +35,27 @@
(defn get-p-property "Get the p-x property value of an element" [el] - (case (:tag el) - :img (-> el :attrs :alt) - :area (-> el :attrs :alt) - :abbr (-> el :attrs :title) - :data (-> el :attrs :value) - :input (-> el :attrs :value) - (or (first (:content el)) ""))) + (or (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-property "Get the u-x property value of an element" [el] - (case (:tag el) - :a (-> el :attrs :href) - :area (-> el :attrs :href) - :img (-> el :attrs :src) - :object (-> el :attrs :data) - (get-p-property el))) + (or (case (:tag el) + :a (-> el :attrs :href) + :area (-> el :attrs :href) + :img (-> el :attrs :src) + :object (-> el :attrs :data) + (get-p-property el)) + (first :content el) + "")) (defn parse-p "Parse p-* classes within HTML element."
M test/microformats/parser_test.cljtest/microformats/parser_test.clj
@@ -26,8 +26,14 @@
{:name "Example User"} "<abbr class=\"p-name\" title=\"Example User\">@example</abbr>" + {:name "@example"} + "<abbr class=\"p-name\">@example</abbr>" + {:name "Example User"} - "<data class=\"p-name\" value=\"Example User\"></data>"))) + "<data class=\"p-name\" value=\"Example User\"></data>" + + {:name "Example User"} + "<data class=\"p-name\">Example User</data>"))) (deftest parse-p-empty-br-hr (testing "br and hr tags should return empty strings"
@@ -57,4 +63,10 @@ {:photo "http://example.com/someimage.png"}
"<abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr>" {:photo "http://example.com/someimage.png"} - "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>"))) + "<abbr class=\"u-photo\">http://example.com/someimage.png</abbr>" + + {:photo "http://example.com/someimage.png"} + "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>" + + {:photo "http://example.com/someimage.png"} + "<data class=\"u-photo\">http://example.com/someimage.png</data>")))