Test + implement multi-child property parsing
2 files changed, 24 insertions(+), 5 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -174,13 +174,13 @@ (defn parse-h "Parse h-* classes within a HTML element." [element] - (let [el (first (html/select element [(html/union [(html/attr-starts :class "p-") - (html/attr-starts :class "u-") - (html/attr-starts :class "dt-") - (html/attr-starts :class "e-")])]))] + (let [el (html/select element [(html/union [(html/attr-starts :class "p-") + (html/attr-starts :class "u-") + (html/attr-starts :class "dt-") + (html/attr-starts :class "e-")])])] (hash-map :type (get-mf-names element) :properties (merge (parse-implied element) - (apply merge ((juxt parse-p parse-u parse-dt parse-e) el)))))) + (apply merge (map #(apply merge %) (map (juxt parse-p parse-u parse-dt parse-e) el))))))) (defn select-h "Select h-* elements within a HTML document."
M test/microformats/parser_expectations.clj → test/microformats/parser_expectations.clj
@@ -129,3 +129,22 @@ (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>")) + +(expect + {:items [{:type ["h-adr"], + :properties {:street-address '("665 3rd St."), + :extended-address '("Suite 207"), + :locality '("San Francisco"), + :region '("CA"), + :postal-code '("94107"), + :country-name '("U.S.A."), + :name '("665 3rd St. Suite 207 San Francisco, CA 94107 U.S.A.")}}] + :rels {}} + (parse "<p class=\"h-adr\"> +<span class=\"p-street-address\">665 3rd St.</span> +<span class=\"p-extended-address\">Suite 207</span> +<span class=\"p-locality\">San Francisco</span>, +<span class=\"p-region\">CA</span> +<span class=\"p-postal-code\">94107</span> +<span class=\"p-country-name\">U.S.A.</span> +</p>"))