Skip to content

Fix comment before main document node. #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions cxml/cxml-dom.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
(defmethod transform-html5-dom ((to-type (eql :cxml)) node &key)
(let ((document-type)
(document)
(document-fragment))
(labels ((walk (node &optional parent xlink-defined)
(document-fragment)
(delayed))
(labels ((add-delayed ()
(loop
for value in (nreverse delayed)
do (dom:append-child document (dom:create-comment document value))
finally (setf delayed NIL)))
(walk (node &optional parent xlink-defined)
(ecase (node-type node)
(:document-type
(setf document-type (dom:create-document-type 'rune-dom:implementation
Expand All @@ -37,17 +43,19 @@
(element-map-children #'walk node))
(:document-fragment
(setf document (dom:create-document 'rune-dom:implementation nil nil nil))
(add-delayed)
(setf document-fragment (dom:create-document-fragment document))
(element-map-children (lambda (c) (walk c document-fragment xlink-defined)) node))
(:element
(let ((element
(if document
(dom:create-element-ns document (node-namespace node) (xml-escape-name (node-name node)))
(dom:document-element
(setf document (dom:create-document 'rune-dom:implementation
(node-namespace node)
(xml-escape-name (node-name node))
document-type))))))
(prog1 (dom:document-element
(setf document (dom:create-document 'rune-dom:implementation
(node-namespace node)
(xml-escape-name (node-name node))
document-type)))
(add-delayed)))))
(unless (and parent
(equal (node-namespace node) (dom:namespace-uri parent)))
(dom:set-attribute-ns element (html5-constants:find-namespace "xmlns")
Expand All @@ -67,7 +75,10 @@
(dom:append-child (or parent document)
(dom:create-text-node document (node-value node))))
(:comment
(dom:append-child (or parent document)
(dom:create-comment document (node-value node)))))))
(let ((value (node-value node)))
(if document
(dom:append-child (or parent document)
(dom:create-comment document value))
(push value delayed)))))))
(walk node))
(or document-fragment document)))