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

Inconsistent *html-mode* and lazyness #4

Closed
geoffsalmon opened this issue Jun 11, 2010 · 2 comments
Closed

Inconsistent *html-mode* and lazyness #4

geoffsalmon opened this issue Jun 11, 2010 · 2 comments

Comments

@geoffsalmon
Copy link
Contributor

I'm using hiccup 0.2.5 and am trying to set the mode to be :sgml, but for some tags it is still the default :xml. Here's an example,

user> (html {:mode :sgml} [:html [:title] [:link] (list [:link])])
"<html><title><link /><link></html>"

Notice that the first link tag is closed <link />. The behaviour is very sensitive to the input, and adding or removing other tags will make the output a correct link tag. The (list [:link]) at the end is meant to be the return of a helper function like include-css.

It looks like a lazy sequence is being evaluated outside the *html-mode* binding. Adding a doall to collapse-strs fixed it, but there might be a more appropriate spot.

(defn- collapse-strs
  "Collapse nested str expressions into one, where possible."
  [expr]
  (if (seq? expr)
    (do
      (doall expr)
      (cons
        (first expr)
        (mapcat
         #(if (and (seq? %) (symbol? (first %)) (= (first %) (first expr) `str))
            (rest (collapse-strs %))
            (list (collapse-strs %)))
          (rest expr))))
    expr))
@geoffsalmon
Copy link
Contributor Author

Turns out the doall in collapse-strs wasn't sufficient, but adding doall to compile-html did the trick. Does this handle everything? Here's a commit adding tests and a commit adding the doall
geoffsalmon/hiccup@708cf4e
geoffsalmon/hiccup@3b0ae78

@weavejester
Copy link
Owner

I've grabbed your changes and committed them. Thanks for the fix! :)

This issue was closed.
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

2 participants