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

How to flexibly specify (no) closing tag? #103

Open
limist opened this issue Jul 3, 2014 · 2 comments
Open

How to flexibly specify (no) closing tag? #103

limist opened this issue Jul 3, 2014 · 2 comments

Comments

@limist
Copy link

limist commented Jul 3, 2014

There are some (edge) cases where tags need to be self-closing, but are not known as such to hiccup's void-tags list. Modifying the void-tags would be inelegant. Is there a way to specify a tag as self-closing in a hiccup tag vector - especially as a local override of that tag's rendering to HTML/XML?

In particular, with sitemaps using the hreflang specification, per https://support.google.com/webmasters/answer/2620865?hl=en one can see that <xhtml:link ... /> tags are self-closing. If dealing with an isolated tag vector, it's possible to specify :mode xml to produce the desired outcome:

(require '[hiccup.core :as hic])

(hic/html [:xhtml:link (merge {:rel "alternate"} {:hreflang "en" :href http://www.foo.com/en"})])
;;=> "<xhtml:link href=\"http://www.foo.com/en\" hreflang=\"en\" rel=\"alternate\"></xhtml:link>"  INCORRECT, empty body and closing tag

(hic/html {:mode :xhtml} [:xhtml:link (merge {:rel "alternate"} {:hreflang "en" :href "http://www.foo.com/en"})])
;;=> "<xhtml:link href=\"http://www.foo.com/en\" hreflang=\"en\" rel=\"alternate\"></xhtml:link>"  INCORRECT, empty body and closing tag

(hic/html {:mode :xml} [:xhtml:link (merge {:rel "alternate"} {:hreflang "en" :href "http://www.foo.com/en"})])
;;=> "<xhtml:link href=\"http://www.foo.com/en\" hreflang=\"en\" rel=\"alternate\" />"  CORRECT

A problem arises when hic/html is being called on a larger collection of tag vectors, most of which render as desired, but we want some local overrides for the links of [:xhtml:link ...] See https://github.com/hashobject/sitemap and in particular https://github.com/hashobject/sitemap/blob/master/src/sitemap/core.clj

Any solutions/suggestions? Thanks!

@drakezhard
Copy link

drakezhard commented Nov 7, 2016

I have the same problem but for the tag.

@Em-AK
Copy link

Em-AK commented Jun 25, 2020

I don't understand when the problem arise here. But this Issue benefited me by documenting the :mode option 🙏

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