Comments (7)
This behavior is triggered by the metadata of the internal node structures: When the metadata of a node has the :net.cgrand.xml/dtd key, the html emitter prepends a doctype.
This metadata key shouldn't be there in the first place.
Dirty workaround: Manually edit the nodes of your snippet before emission and strip away all but the first :net.cgrand.xml/dtd keys in the metadata.
The code I use looks somehow like this:
(defn- adjust-dtd
[nodes]
(cons (with-meta (first nodes) {:net.cgrand.xml/dtd ["html" nil nil]}) (map #(vary-meta % dissoc :net.cgrand.xml/dtd) (rest nodes))))
This does mean though that you can't use the deftemplate since it already emits the node structure. Instead, you will have to use defsnippet, snippet*, html-resource etc.
from enlive.
I have a couple of ideas, it seems that emit-root may require a couple of tweaks/improvements. Basic idea is as follows:
(defn- emit-root [node etc]
(if (and (not (nil? (-> node meta ::xml/dtd)))
(not (= :comment (-> node meta ::xml/type))))
(let [[name public-id system-id] (-> node meta ::xml/dtd)
preamble (cond
public-id
(str "<!DOCTYPE " name " PUBLIC \"" public-id "\"\n \"" system-id "\">\n")
system-id
(str "<!DOCTYPE " name " SYSTEM \"" system-id "\">\n")
:else
(str "<!DOCTYPE " name ">\n"))]
(cons preamble (emit node etc)))
(emit node etc)))
And within xml.clj, handler proxy, comment implementation would be like:
(comment [ch start length]
(swap! metadata assoc ::type :comment)
(swap! loc z/append-child {:type :comment :data (String. ^chars ch (int start) (int length))}))
That does solve issue with duplicates, but now first comment doesn't render doctype as well, so it's still not correct.
I'll try to investigate in that direciton, if you have any thoughts let me know
from enlive.
Actually, any node that is either a tag or a comment and was encountered first, qualifies for the one that's going to be prepended with Doctype, maybe we should try that out?...
from enlive.
The way doctypes are handled is too much of a hack. DTD should be nodes.
On Fri, Jan 11, 2013 at 12:20 AM, Alex P [email protected] wrote:
Actually, any node that is either a tag or a comment and was encountered
first, qualifies for the one that's going to be prepended with Doctype,
maybe we should try that out?...—
Reply to this email directly or view it on GitHubhttps://github.com//issues/43#issuecomment-12124181.
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/
from enlive.
Hm, didn't think of it. Thanks for the fix!
from enlive.
If I remember correctly,I introduced DTD before comments, at a time where I
tried to stay very close to clojure.xml. That's why I made this odd choice.
Or I was in a bad day.
On Fri, Jan 11, 2013 at 12:16 PM, Alex P [email protected] wrote:
Hm, didn't think of it. Thanks for the fix!
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/43#issuecomment-12140241.
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/
from enlive.
Yeah, project has quite a history, and sometimes it's quite hard to guess for a newcomer what's the best way of handling certain things in given context. In any case, always good to learn.
from enlive.
Related Issues (20)
- Automated CSS selector translation to vector form HOT 5
- [org.jsoup/jsoup "1.8.3"] exists HOT 1
- Make JSoup the default for enlive 1.2 HOT 1
- StackOverflowError when parsing certain html HOT 4
- Composable selector/transform in snippet HOT 1
- Simple variable substitution (with example) in meta tag throwing NullPointerException HOT 2
- Less obscure error messages
- first-child
- End tag for <col> violates the specs
- javax.net.ssl.SSLHandshakeException while trying to reach some resources HOT 1
- attribute matching inside at-form HOT 1
- "safe write" "feature" in IntelliJ prevents auto-reloading of namespace depending on changed HTML
- Removing element cleanly HOT 2
- Is this project dead? HOT 1
- Update jsoup dependency to v1.11.3+
- Setting HTTP headers HOT 1
- Broken wiki link in project description
- HTML resource not found
- Any interest in CSS-style selector syntax option? HOT 1
- [BUG] Some tags are loosing part of their content when selected.
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 enlive.