From 4debb2f471188fdd17a03f7250050b8e83ae9b32 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 10 Oct 2014 19:57:56 +0100 Subject: Parse values from value-title class elements --- src/microformats/parser.clj | 14 ++++++++++++-- test/microformats/parser_expectations.clj | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index 0b26372..4f63d55 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -92,6 +92,13 @@ [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) diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj index 92e4448..5486898 100644 --- a/test/microformats/parser_expectations.clj +++ b/test/microformats/parser_expectations.clj @@ -67,6 +67,9 @@ (expect {:name '("Name")} (parse-p (snippet "

Name

"))) +(expect {:name '("Name")} + (parse-p (snippet "

Not this name

"))) + (expect {:name '("Name Endname")} (parse-p (snippet "

Name (this should not be included) Endname

"))) -- cgit 1.4.1