Giter Club home page Giter Club logo

Comments (7)

toofuu avatar toofuu commented on August 21, 2024

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.

ifesdjeen avatar ifesdjeen commented on August 21, 2024

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.

ifesdjeen avatar ifesdjeen commented on August 21, 2024

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.

cgrand avatar cgrand commented on August 21, 2024

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.

ifesdjeen avatar ifesdjeen commented on August 21, 2024

Hm, didn't think of it. Thanks for the fix!

from enlive.

cgrand avatar cgrand commented on August 21, 2024

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.

ifesdjeen avatar ifesdjeen commented on August 21, 2024

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)

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.