about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2014-09-21 20:53:25 +0100
committerAlan Pearce2014-09-21 20:53:25 +0100
commit6d5093970156cc85794c9a5f503f93c9989d461b (patch)
treea8d292f17c195eadf6fe0b6721e176cedc3cde88
parent8a6e342bee04cf1443cf71bcef3973b132375816 (diff)
downloadmicroformats-6d5093970156cc85794c9a5f503f93c9989d461b.tar.lz
microformats-6d5093970156cc85794c9a5f503f93c9989d461b.tar.zst
microformats-6d5093970156cc85794c9a5f503f93c9989d461b.zip
Parse mf names into type array
-rw-r--r--src/microformats/parser.clj11
-rw-r--r--test/microformats/parser_expectations.clj2
2 files changed, 11 insertions, 2 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index b993a76..38bca21 100644
--- a/src/microformats/parser.clj
+++ b/src/microformats/parser.clj
@@ -144,6 +144,14 @@
        (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 @@
                                                      (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."
diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj
index 8f84cfc..8948840 100644
--- a/test/microformats/parser_expectations.clj
+++ b/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>"))