hiccup
hiccup copied to clipboard
Unminified output
Is there a way making hiccup generate unminified output so it would be easier to debug in the browser?
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.
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.
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.
:+1:
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
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)))
Is this planned for 2.0 ?
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.
Ah I see. Okay, thank you, I'll look into beautify-html for my debugging purpose.
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 " "))))