weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.67k stars 174 forks source link

Unminified output #65

Open ghost opened 11 years ago

ghost commented 11 years ago

Is there a way making hiccup generate unminified output so it would be easier to debug in the browser?

weavejester commented 11 years ago

Not with the current version (because it outputs directly to a string). However, most (all?) modern browsers allow you to look at the DOM of the page. Viewing the raw source usually isn't necessary.

ghost commented 11 years ago

Can't newline characters with correct indentation be added for making the initial HTML document readable?

When using a framework it adds a lot of custom elements/attributes making debugging harder if we are depending on the web inspector.

weavejester commented 11 years ago

Can't newline characters with correct indentation be added for making the initial HTML document readable?

No, because it outputs directly to strings. In order to produce correct indentation you need the whole DOM, which is planned for version 2.0.

drusellers commented 9 years ago

:+1:

dwhite44 commented 8 years ago

It would definitely be nice to have some minify options with hiccup. I don't necessarily need unminified but I would like an option to have a space between each element to help with spacing problems that can result from having no whitespace between elements such as this bootstrap issue: https://github.com/twbs/bootstrap/issues/14401

mgerlach-klick commented 5 years ago

I wrote this library to deal with this: https://github.com/px0/clj-beautify-web I usually put something like this in the render chain after the html macro:

(fn [html]
    (if (= "production" (:environment render-params))
    html
    (beautify-web.core/beautify-html html)))
didibus commented 5 years ago

Is this planned for 2.0 ?

weavejester commented 5 years ago

No, plans for 2.0 were scaled back. Adding it in for 2.1 is a possibility, but I haven't had much time to work on Hiccup recently.

didibus commented 5 years ago

Ah I see. Okay, thank you, I'll look into beautify-html for my debugging purpose.

metametadata commented 1 year ago

I'm also interested in such a built-in feature as I find readable formatting more convenient for unit tests and sometimes look at the source code instead of a browser inspector. The current workaround is to use Jericho to postformat the generated HTML:

[net.htmlparser.jericho/jericho-html "3.4"]
...
(:import [net.htmlparser.jericho Source])
...
(defn formatted-html
  [s]
  (str (-> (.getSourceFormatter (Source. s))
           (.setIndentString "  "))))