From 42c1aa10cd0ab93300fe56c8022082cf4b1edea1 Mon Sep 17 00:00:00 2001 From: Catrope Date: Wed, 17 Apr 2013 18:26:54 -0700 Subject: [PATCH] Serialize alienated context-sensitive nodes correctly Context-sensitive nodes are HTML elements like that can only appear in certain contexts ( in this case). This means that serializing them by throwing them in a
and calling .innerHTML fails, because the browser knows a
' } }, + { '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': '
can't be in a
and unwraps it. jQuery's .html() function is clever though and knows to wrap
in a (and has similar rules for other elements). So use jQuery's .html() rather than manual .innerHTML stuff. Change-Id: Id7d3eff968b3a2ba345680772f7cc32e3dcdb529 --- modules/ve/dm/nodes/ve.dm.AlienNode.js | 2 +- modules/ve/test/dm/ve.dm.example.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/ve/dm/nodes/ve.dm.AlienNode.js b/modules/ve/dm/nodes/ve.dm.AlienNode.js index 03b7261993..cdf397f50b 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.toDataElement = function ( domElements, converter ) { 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 2a04071d42..277644565b 100644 --- a/modules/ve/test/dm/ve.dm.example.js +++ b/modules/ve/test/dm/ve.dm.example.js @@ -2072,6 +2072,26 @@ ve.dm.example.domToDataCases = { { 'type': '/paragraph' } ] }, + 'context-sensitive nodes are alienated correctly': { + 'html': '
Foo
Bar
', + 'data': [ + { 'type': 'table' }, + { 'type': 'alienBlock', 'attributes': { 'html': '
Foo
Foo\n
', 'data': [