Permalink
Browse files

nodeToCode() now works on void elements.

  • Loading branch information...
toolness committed May 27, 2012
1 parent bd7866d commit 562994ad02868d507b4d9398e1f9732685573cb0
@@ -39,12 +39,15 @@ define([
var path = "html " + pathTo(root, node);
var parallelNode = docFrag.querySelector(path);
var result = null;
- if (parallelNode)
+ if (parallelNode) {
+ var pi = parallelNode.parseInfo;
+ var isVoidElement = !pi.closeTag;
result = {
- start: parallelNode.parseInfo.openTag.start,
- end: parallelNode.parseInfo.closeTag.end,
- contentStart: parallelNode.parseInfo.openTag.end
+ start: pi.openTag.start,
+ end: isVoidElement ? pi.openTag.end : pi.closeTag.end,
+ contentStart: isVoidElement ? pi.openTag.start : pi.openTag.end
};
+ }
if (origDocFrag != docFrag) {
for (i = 0; i < htmlNode.childNodes.length; i++)
origDocFrag.appendChild(htmlNode.childNodes[i]);
@@ -48,6 +48,13 @@ require([
expect: "<p>u</p>"
});
+ n2cTest({
+ name: "nodeToCode() works on void element",
+ html: '<html><img id="foo"></html>',
+ selector: "img",
+ expect: '<img id="foo">'
+ });
+
n2cTest({
name: "nodeToCode() can't map to anything from implied <html>",
html: "<p>hi</p>",

0 comments on commit 562994a

Please sign in to comment.