Trim extra spaces from HTML content
2 files changed, 17 insertions(+), 0 deletions(-)
M src/microformats/parser.clj → src/microformats/parser.clj
@@ -101,6 +101,15 @@ (map #(if (string? %) % (apply str (persistent! (html/emit-tag % (transient []))))) el)) +(defn- node-to-text + "Turn a node into a text string" + [content] + (->> content + html/texts + (map #(str/replace % #"\s+" " ")) + (apply str) + str/trim)) + (defn get-e-value "Get the e-x propery value of an element" [el]
M test/microformats/parser_expectations.clj → test/microformats/parser_expectations.clj
@@ -16,6 +16,14 @@ (expect "Foo <strong>bar</strong>" (apply str (#'microformats.parser/node-to-html '("Foo " {:tag :strong, :attrs nil, :content ("bar")})))) +(expect "665 3rd St. Suite 207" + (->> "<p class=\"h-adr\"> +<span class=\"p-street-address\">665 3rd St.</span> +<span class=\"p-extended-address\">Suite 207</span> +</p>" + snippet :content + (#'microformats.parser/node-to-text))) + (expect {:name '("Name")} (parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span></p>")))