all repos — archive/microformats @ d5b6c2d56e84a93232c2d3c87d93b70102006bee

Incomplete Clojure microformats library

Add initial implied property parsing

Alan Pearce
commit

d5b6c2d56e84a93232c2d3c87d93b70102006bee

parent

6d5093970156cc85794c9a5f503f93c9989d461b

2 files changed, 15 insertions(+), 1 deletion(-)

jump to
M src/microformats/parser.cljsrc/microformats/parser.clj
@@ -152,6 +152,16 @@ element-to-classes
(r/filter (mf-names-from-class "h-")) (into []))) +(defn- imply-name + "Imply the name of an entity from the element" + [element] + (or (first (:content element)))) + +(defn parse-implied + "Parse implied properties of a HTML element" + [element] + {:name (imply-name element)}) + (defn parse-h "Parse h-* classes within a HTML element." [element]
@@ -160,7 +170,8 @@ (html/attr-starts :class "u-")
(html/attr-starts :class "dt-") (html/attr-starts :class "e-")])]))] (hash-map :type (get-mf-names element) - :properties (apply merge ((juxt parse-p parse-u parse-dt parse-e) el))))) + :properties (merge (parse-implied element) + (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.cljtest/microformats/parser_expectations.clj
@@ -115,3 +115,6 @@ (parse ""))
(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 [{:type ["h-card"] :properties {:name "Example User"}}] :rels {}} + (parse "<p class=\"h-card\">Example User</p>"))