From bd5a901a5081d01df16ab3a750fdfa403391b3d2 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 10 Oct 2014 09:14:30 +0100 Subject: Add helper function to get base URL --- src/microformats/parser.clj | 9 +++++++++ test/microformats/parser_expectations.clj | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index ba07fcf..e3a244e 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -65,6 +65,15 @@ (apply str) str/trim)) +(defn get-base-url + "Find the base-url of a document." + [document] + (-> document + (html/select [:head :> [:base (html/attr? :href)]]) + first + :attrs + :href)) + (defn get-value-class "Get the value class of elements" [elements] diff --git a/test/microformats/parser_expectations.clj b/test/microformats/parser_expectations.clj index 1c6d4f1..7344fde 100644 --- a/test/microformats/parser_expectations.clj +++ b/test/microformats/parser_expectations.clj @@ -51,6 +51,9 @@

")))) +(expect "http://example.com" + (get-base-url (snippet ""))) + (expect {:name '("Name")} (parse-p (snippet "

Name

"))) -- cgit 1.4.1