Parse multiple types of properties on a single element
2 files changed, 9 insertions(+), 5 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -227,10 +227,10 @@ "Parse children of a microformat, returning a map of properties" [element] (let [cappend (partial merge-with concat)] (merge (parse-implied element) - (apply cappend (map parse-p (html/select element [(html/attr-starts :class "p-")]))) - (apply cappend (map parse-u (html/select element [(html/attr-starts :class "u-")]))) - (apply cappend (map parse-dt (html/select element [(html/attr-starts :class "dt-")]))) - (apply cappend (map parse-e (html/select element [(html/attr-starts :class "e-")])))))) + (apply cappend (map parse-p (html/select element [(html/attr-contains :class "p-")]))) + (apply cappend (map parse-u (html/select element [(html/attr-contains :class "u-")]))) + (apply cappend (map parse-dt (html/select element [(html/attr-contains :class "dt-")]))) + (apply cappend (map parse-e (html/select element [(html/attr-contains :class "e-")])))))) (defn parse-h "Parse h-* classes within a HTML element."@@ -241,7 +241,7 @@ (defn select-h "Select h-* elements within a HTML document." [element] - (html/select element [(html/attr-starts :class "h-")])) + (html/select element [(html/attr-contains :class "h-")])) (defn parse-rel "Parse rel attributes of an HTML link element"
M test/microformats/parser_expectations.clj → test/microformats/parser_expectations.clj
@@ -127,6 +127,10 @@ (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") :url '("http://example.com")} + :type ["h-card"]}] :rels {}} + (parse "<div class=\"h-card\"><a class=\"p-name u-url\" href=\"http://example.com\">Example User</></div>")) + (expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}} (parse "<p class=\"h-card\">Example User</p>"))