Add basic implied URL parsing
2 files changed, 13 insertions(+), 2 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -164,12 +164,20 @@ (defn- imply-name "Imply the name of an entity from the element" [element] - (list (node-to-text (:content element)))) + (node-to-text (:content element))) + +(defn- imply-url + [element] + (case (:tag element) + :a (-> element :attrs :href) + nil)) (defn parse-implied "Parse implied properties of a HTML element" [element] - {:name (imply-name element)}) + (into {} (filter #(first (second %)) + {:name (list (imply-name element)) + :url (list (imply-url element))}))) (defn get-mf-properties "Parse children of a microformat, returning a map of properties"
M test/microformats/parser_expectations.clj → test/microformats/parser_expectations.clj
@@ -130,6 +130,9 @@ (expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}} (parse "<p class=\"h-card\">Example User</p>")) +(expect {:items [{:type ["h-card"] :properties {:name '("Example User") :url '("http://example.com")}}] :rels {}} + (parse "<a class=\"h-card\" href=\"http://example.com\">Example User</a>")) + (expect {:items [{:type ["h-adr"], :properties {:street-address '("665 3rd St."),