Comments (3)
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.
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.
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)
- Shouldn't this line call the html function in hiccup2.core? HOT 1
- Hi How to write hiccup code for observable embed code in Roam ? HOT 3
- Null pointer exception with `:class` attribute containing vector nil HOT 3
- Replace license.html with license.txt (for artifact scanners) HOT 9
- Passing nil query param values to to url-encode throws exception
- New version? HOT 15
- :script async HOT 1
- Clojerl support HOT 2
- Historical question: Why is hiccup called hiccup? HOT 2
- link to api docs in project description is broken HOT 3
- Please remove.
- Fragment equivalent for the back end. HOT 2
- *escape-strings?* HOT 1
- hiccup.core/h not backward-compatible HOT 1
- Getting RuntimeException: no such var util/raw-string HOT 2
- Parameters for iframe src attribute HOT 8
- clj-kondo exported config HOT 4
- void-tags might not be complete HOT 3
- "Method code too large!" when compiling the hiccup2.core/html macro HOT 1
- Exponential increase in generated code when there are multiple nested hiccup2.core/html calls HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hiccup.