GithubHelp home page GithubHelp logo

Comments (3)

weavejester avatar weavejester commented on June 26, 2024

Thanks for the report. Unfortunately your patch only covers render-html, and not any of the pre-compiled special cases:

(binding [*html-mode* :html4]
  (let [x {:src "foo"}] (html [:img x]))) 
=> "<img src=\"foo\"/>"

I'd also prefer a solution more integrated into the html macro, perhaps something like:

(html {:mode :sgml} [:br])

In that case, I think there might have to be two sets of bindings; one for the macro, and one for the functions executed at runtime. I think that should work.

from hiccup.

sattvik avatar sattvik commented on June 26, 2024

Well, I have implemented a new version of my fix, and its rather substantial. I tried sticking to using a binding and only modifying the html macro. However, this suffers from the problem that functions and HTML executed at run time don't obey the binding. Thus I have modified the various functions in hiccup.core to take an initial output-mode argument. This way, things should work as expected.

Now the way to invoke HTML/SGML mode is pass an option initial keyword argument to html. For example:

=> (html :html4 [:p])
"<p >"
=> (html :xhtml [:p])
"<p />"
=> (html [:p])
"<p />"

I have left :xhtml mode as the default. I call the new mode html4 because that is more self-documenting than :sgml, and also I don't think this is an issue for HTML 5.

Note that render-tag, render-html, and compile-lit-tag are all public, so I added a form of each that doesn't take the output-mode argument. If these functions are intended to be private, the additional form can be removed.

Lastly, I have modified the test suites to test all three different types of invocations of html. Incidentally, the tests for nested-tags on lines 38 and 39 of core_tests.clj are broken. One of the parentheses on each line is misplace, it should come after the closing "]" instead of at the end of the line.

I uploaded my changes to my fork on Github, so you can take a look and let me know what you think.

from hiccup.

weavejester avatar weavejester commented on June 26, 2024

There's a simpler method, I think. Just use two sets of bindings:

(binding [*html-mode* mode]
  `(binding [*html-mode* ~mode]
     ~(make-html content)))

This seems to work with pre-compiled HTML, and dynamically generated HTML.

I'd also prefer the second argument to be an options hash, and I'd prefer the mode to be named after the markup language being used, rather than the doc-type. Although these modes give us compatibility with HTML4 or XHTML, we're actually changing the markup language being used, rather than the supporting specific doc-types. A mode of :xml is a more accurate description of what we're doing.

This means that there will be three modes, one for each markup language used on the web: :xml, :sgml and :html. In practise, SGML (used in HTML4 and below) and html (used in HTML5) are basically the same thing.

I wanted to make sure the changes I was proposing worked, and they're pretty minor, so I went ahead and implemented them. I also fixed the nested-tags bug. Thanks for pointing that out!

from hiccup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.