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

hiccup/html behaves differently with literal or let-bound value #158

Open
nha opened this issue Mar 26, 2019 · 3 comments
Open

hiccup/html behaves differently with literal or let-bound value #158

nha opened this issue Mar 26, 2019 · 3 comments

Comments

@nha
Copy link

nha commented Mar 26, 2019

Please consider the following snippet:

(let [c {}]
  (str (hiccup/html c))) ;; "{}"
(str (hiccup/html {})) ;; ""

I am not sure what should be the output here (possibly "", since {} doesn't look like valid html to me), but I would expect both snippets to render the same output.

Adding an explicit {} first parameter makes them render both "{}"

(let [c {}]
  (str (hiccup/html {} c))) ;; "{}"

(str (hiccup/html {} {})) ;; "{}"
@weavejester
Copy link
Owner

It should probably either output "{}" or throw an error in both cases. Hiccup uses precompilation steps, and it looks like this is producing some strange output when it's fed invalid input.

@VictorVSa
Copy link

I think I'm having the same issue while trying to add a class to the html tag:

(defn page [opts & content]
  (-> (p/html5 opts content)
      http-response/ok
      (http-response/content-type "text/html")))

(page {:class "test"} [:div]) ;; ... <html>{ :class "test" } ...

But now if I ignore opts and use the literal inside the p/html5 call, it works correctly

(defn page [opts & content]
  (-> (p/html5 {:class "test"} content)
      http-response/ok
      (http-response/content-type "text/html")))

(page {:class "test"} [:div]) ;; ... <html class="test"> ...

What could be the issue?

@weavejester
Copy link
Owner

html5 is a macro, and some of the options it takes are necessary to be known at compile-time. In this case, I'd suggest not using the macro, and instead write:

(html {:mode :html} (p/doctype :html5) [:html opts content])

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

3 participants