all repos — archive/microformats @ 4debb2f471188fdd17a03f7250050b8e83ae9b32

Incomplete Clojure microformats library

Parse values from value-title class elements

Alan Pearce
commit

4debb2f471188fdd17a03f7250050b8e83ae9b32

parent

3213c0c46a152e709772f0818a9281f5ce0e1988

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

jump to
M src/microformats/parser.cljsrc/microformats/parser.clj
@@ -92,6 +92,13 @@ "Normalise a URL"
[root url] (url/resolve (get-base-url root) url)) +(defn get-value-title-class + "Get the value-title class of elements" + [elements] + (str/join " " (into [] ((comp (r/map :title) + (r/map :attrs)) + elements)))) + (defn get-value-class "Get the value class of elements" [elements]
@@ -103,8 +110,11 @@
(defn find-value-class "Find and get the value class of elements" [el] - (when-let [values (seq (html/select el [html/root :> :.value]))] - (get-value-class values))) + (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 %))) (declare parse-h)
M test/microformats/parser_expectations.cljtest/microformats/parser_expectations.clj
@@ -67,6 +67,9 @@
(expect {:name '("Name")} (parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span></p>"))) +(expect {:name '("Name")} + (parse-p (snippet "<p class=\"p-name\"><span class=\"value-title\" title=\"Name\">Not this name</span></p>"))) + (expect {:name '("Name Endname")} (parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span> (this should not be included) <span class=\"value\">Endname</span></p>")))