Skip to content

Commit

Permalink
Dont entity escape script content in html-compatibility-mode re ADWol…
Browse files Browse the repository at this point in the history
…f:#1197 (2)
  • Loading branch information
bobbysmith007 committed Nov 22, 2013
1 parent 4a5b769 commit 4147abd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
34 changes: 20 additions & 14 deletions src/buildnode.lisp
Expand Up @@ -198,15 +198,13 @@
(rune-dom::document db))

(defmethod sax:unescaped ((builder scoped-dom-builder) data)
;; TODO: Is this the correct answer?
;; I have no idea how to handle
;; unescaped content in a dom (which is probably why this was not
;; implemented on dom-builder)
(let ((content (dom:child-nodes
(inner-html data "div" "http://www.w3.org/1999/xhtml" nil nil))))
(buildnode:add-children
(first (rune-dom::element-stack builder))
content))
;; I have no idea how to handle unescaped content in a dom (which is
;; probably why this was not implemented on dom-builder)
;; we will just make a text node of it for now :/
;; other thoughts would be a processing instruction or something
(buildnode:add-children
(first (rune-dom::element-stack builder))
(dom:create-text-node *document* data))
(values))

;;;; I think we might be able to use this as a dom-builder for a more efficient
Expand All @@ -228,11 +226,11 @@
(defmethod sax:characters ((handler html-whitespace-remover) data)
(unless (every #'cxml::white-space-rune-p (cxml::rod data)) (call-next-method)))

(defun inner-html (string &optional
(tag "div")
(namespace-uri "http://www.w3.org/1999/xhtml")
(dtd nil)
(remove-whitespace? t))
(defun insert-text-content (string &key
(tag "div")
(namespace-uri "http://www.w3.org/1999/xhtml")
(dtd nil)
(remove-whitespace? t))
"Parses a string containing a well formed html snippet
into dom nodes inside of a newly created node.
Expand All @@ -254,6 +252,14 @@
:dtd dtd)
(dom:first-child node))))

(defun inner-html (string &optional (tag "div")
(namespace-uri "http://www.w3.org/1999/xhtml")
(dtd nil)
(remove-whitespace? t))
(insert-text-content
string :tag tag :namespace-uri namespace-uri :dtd dtd
:remove-whitespace? remove-whitespace?))

(defun document-of (el)
"Returns the document of a given node (or the document if passed in)"
(if (typep el 'rune-dom::document)
Expand Down
8 changes: 6 additions & 2 deletions src/dom-walker.lisp
Expand Up @@ -96,8 +96,12 @@
(sax:characters handler (dom:data n))
(sax:end-cdata handler))

(defmethod dom-walk (handler (n dom:text) &key &allow-other-keys)
(sax:characters handler (dom:data n)))
(defmethod dom-walk (handler (n dom:text) &key &allow-other-keys
&aux (parent (dom:tag-name (dom:parent-node n))) )
(if (and *html-compatibility-mode*
(member parent '("script") :test #'string-equal))
(sax:unescaped handler (dom:data n))
(sax:characters handler (dom:data n))))

(defmethod dom-walk (handler (n dom:comment) &key &allow-other-keys)
(sax:comment handler (dom:data n)))
Expand Down

0 comments on commit 4147abd

Please sign in to comment.