Giter VIP home page Giter VIP logo

Comments (3)

Raynes avatar Raynes commented on June 14, 2024

I was able to fix it like so:

diff --git a/src/hickory/core.clj b/src/hickory/core.clj
index 22fcdd2..5c75426 100644
--- a/src/hickory/core.clj
+++ b/src/hickory/core.clj
@@ -57,7 +57,7 @@
                                       (as-hiccup (.attributes this))]
                                      (map as-hiccup (.childNodes this)))))
   TextNode
-  (as-hiccup [this] (.text this))
+  (as-hiccup [this] (.outerHtml this))
   XmlDeclaration
   (as-hiccup [this] (str this)))

@@ -86,7 +86,7 @@
                       :content (not-empty (into [] (map as-hickory
                                                         (.childNodes this))))})
   TextNode
-  (as-hickory [this] (.text this)))
+  (as-hickory [this] (.outerHtml this)))

 (defn parse
   "Parse an entire HTML document into a DOM structure that can be

The .outerHtml function of nodes seems to return the text untouched. I noticed that .text also seems to be doing other weird formatting things like stripping line breaks and stuff. I'm not sure if outerHtml is what we want here, but I didn't see anything else in the API docs that wouldn't unescape stuff. http://jsoup.org/apidocs/org/jsoup/nodes/TextNode.html

Furthermore, I'm not entirely certain if you consider this a bug or not. I suppose unescaping makes sense for certain uses of the library, but if you're redistributing the HTML when you're finished mucking with it you definitely want what was escaped to stay that way.

from hickory.

davidsantiago avatar davidsantiago commented on June 14, 2024

You are absolutely correct to flag the issue of whether it should be parsing escaped or unescaped text. There are use cases in which you'd want either, and currently it is only supporting one of those. However, simply switching the code to the version that addresses your use case is not the best way to handle this.

I think the way to handle this is to change the parsing functions so they can take keyword arguments, of which we'd add one (for now): :unescaped-html, which defaults to false. This should leave user source code unchanged. It will also match the behavior of clojure.xml, which unescapes the XML it parses. Of course, passing the options map around will require a change to the function signatures in the protocol, but that should be fairly mechanical.

David

from hickory.

davidsantiago avatar davidsantiago commented on June 14, 2024

(After much discussion with you on IRC), I believe version 0.2.1 will address your problems.

from hickory.

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.