Skip to content

Utility function to remove whitespace from hiccup forms #28

Open
@lvh

Description

Hi!

This seems like a fairly reasonable utility feature that I've needed in more than one place now.

(def ^:private whitespace?
  "Is this a string, and does it consist of only whitespace?"
  (every-pred string? (partial re-matches #"\s*")))

(defn ^:private remove-whitespace
  "Walk a given Hiccup form and remove all pure whitespace."
  [row]
  (walk/prewalk
   (fn [form]
     (if (vector? form)
       (into [] (remove whitespace? form))
       form))
   row))

(walk is [clojure.walk :as walk].)

If you'd like it in Hiccup, I'm more than happy to add it (with unit tests, of course.)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions