Add helper function to get base URL
2 files changed, 12 insertions(+), 0 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -65,6 +65,15 @@ (map #(str/replace % #"\s+" " ")) (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]
M test/microformats/parser_expectations.clj → test/microformats/parser_expectations.clj
@@ -51,6 +51,9 @@ (map-h identity (z/xml-zip (snippet "<div class=\"h-card\"> <p><a class=\"h-org\"></a></p> </div>")))) +(expect "http://example.com" + (get-base-url (snippet "<head><base href=\"http://example.com\"></head>"))) + (expect {:name '("Name")} (parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span></p>")))