Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/59780


Change subject: Serialize alienated context-sensitive nodes correctly
......................................................................

Serialize alienated context-sensitive nodes correctly

Context-sensitive nodes are HTML elements like <caption> that can only
appear in certain contexts (<table> in this case). This means that
serializing them by throwing them in a <div> and calling .innerHTML
fails, because the browser knows a <caption> can't be in a <div> and
unwraps it. jQuery's .html() function is clever though and knows to wrap
<caption> in a <table> (and has similar rules for other elements).
So use jQuery's .html() rather than manual .innerHTML stuff.

Change-Id: Id7d3eff968b3a2ba345680772f7cc32e3dcdb529
---
M modules/ve/dm/nodes/ve.dm.AlienNode.js
M modules/ve/test/dm/ve.dm.example.js
2 files changed, 21 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/80/59780/1

diff --git a/modules/ve/dm/nodes/ve.dm.AlienNode.js 
b/modules/ve/dm/nodes/ve.dm.AlienNode.js
index 03b7261..cdf397f 100644
--- a/modules/ve/dm/nodes/ve.dm.AlienNode.js
+++ b/modules/ve/dm/nodes/ve.dm.AlienNode.js
@@ -45,7 +45,7 @@
 
 ve.dm.AlienNode.static.toDomElements = function ( dataElement, doc ) {
        var wrapper = doc.createElement( 'div' );
-       wrapper.innerHTML = dataElement.attributes.html;
+       $( wrapper ).html( dataElement.attributes.html );
        // Convert wrapper.children to an array
        return Array.prototype.slice.call( wrapper.childNodes, 0 );
 };
diff --git a/modules/ve/test/dm/ve.dm.example.js 
b/modules/ve/test/dm/ve.dm.example.js
index 2a04071..2776445 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -2072,6 +2072,26 @@
                        { 'type': '/paragraph' }
                ]
        },
+       'context-sensitive nodes are alienated correctly': {
+               'html': 
'<table><caption>Foo</caption><tbody><tr><td>Bar</td></tr></tbody></table>',
+               'data': [
+                       { 'type': 'table' },
+                       { 'type': 'alienBlock', 'attributes': { 'html': 
'<caption>Foo</caption>' } },
+                       { 'type': '/alienBlock' },
+                       { 'type': 'tableSection', 'attributes': { 'style': 
'body' } },
+                       { 'type': 'tableRow' },
+                       { 'type': 'tableCell', 'attributes': { 'style': 'data' 
} },
+                       { 'type': 'paragraph', 'internal': { 'generated': 
'wrapper' } },
+                       'B',
+                       'a',
+                       'r',
+                       { 'type': '/paragraph' },
+                       { 'type': '/tableCell' },
+                       { 'type': '/tableRow' },
+                       { 'type': '/tableSection' },
+                       { 'type': '/table' }
+               ]
+       },
        'whitespace before meta node in wrapping mode': {
                'html': '<body><table><tbody><tr><td>Foo\n<meta 
property="mw:foo" content="bar" /></td></tr></tbody></table></body>',
                'data': [

-- 
To view, visit https://gerrit.wikimedia.org/r/59780
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7d3eff968b3a2ba345680772f7cc32e3dcdb529
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to