about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2014-09-23 19:05:47 +0100
committerAlan Pearce2014-09-23 19:05:47 +0100
commit46d8526af589558b7ed1a2537e96953245c08720 (patch)
treea7515742e9685cee5e4d33b7f64dd90e25004729
parent4f80b088207c13f787a2b2bfbb5a716fe9a5dbb5 (diff)
downloadmicroformats-46d8526af589558b7ed1a2537e96953245c08720.tar.lz
microformats-46d8526af589558b7ed1a2537e96953245c08720.tar.zst
microformats-46d8526af589558b7ed1a2537e96953245c08720.zip
Add basic implied URL parsing
-rw-r--r--src/microformats/parser.clj12
-rw-r--r--test/microformats/parser_expectations.clj3
2 files changed, 13 insertions, 2 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index 934a0a3..4f9f9e9 100644
--- a/src/microformats/parser.clj
+++ b/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"
diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj
index 2fc8a19..bf39778 100644
--- a/test/microformats/parser_expectations.clj
+++ b/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."),