Parse mf names into type array
2 files changed, 11 insertions(+), 2 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -144,6 +144,14 @@ ((classes-to-props "e-")) (r/map #(hash-map % (get-e-value element))) (into {}))) +(defn- get-mf-names + "Get the microformat names from an element" + [element] + (->> element + element-to-classes + (r/filter (mf-names-from-class "h-")) + (into []))) + (defn parse-h "Parse h-* classes within a HTML element." [element]@@ -151,7 +159,8 @@ (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-")])]))] - (hash-map :properties (apply merge ((juxt parse-p parse-u parse-dt parse-e) el))))) + (hash-map :type (get-mf-names element) + :properties (apply merge ((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
@@ -113,5 +113,5 @@ (expect {:items [] :rels {}} (parse "")) -(expect {:items [{:properties {:name "Example User"}}] :rels {}} +(expect {:items [{:properties {:name "Example User"} :type ["h-card"]}] :rels {}} (parse "<div class=\"h-card\"><p class=\"p-name\">Example User</p></div>"))