Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unminified output #65

Open
ghost opened this issue Oct 2, 2012 · 10 comments
Open

Unminified output #65

ghost opened this issue Oct 2, 2012 · 10 comments

Comments

@ghost
Copy link

ghost commented Oct 2, 2012

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

@weavejester
Copy link
Owner

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
Copy link
Author

ghost commented Oct 2, 2012

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
Copy link
Owner

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
Copy link

👍

@dwhite44
Copy link

dwhite44 commented Oct 1, 2015

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: twbs/bootstrap#14401

@mgerlach-klick
Copy link

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
Copy link

didibus commented Mar 25, 2019

Is this planned for 2.0 ?

@weavejester
Copy link
Owner

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
Copy link

didibus commented Mar 25, 2019

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

@metametadata
Copy link

metametadata commented Jul 30, 2023

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 "  "))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants