diff --git a/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js b/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js index a5d40c9720..b48e71c160 100644 --- a/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js +++ b/modules/ve/dm/nodes/ve.dm.MWTemplateNode.js @@ -30,7 +30,16 @@ ve.dm.MWTemplateNode.static.name = 'MWtemplate'; ve.dm.MWTemplateNode.static.matchTagNames = null; -ve.dm.MWTemplateNode.static.matchRdfaTypes = [ 'mw:Object/Template' ]; +// We're interested in all nodes that have mw:Object/Template, even if they also have other mw: +// types. So we match all mw: types, then use a matchFunction to assert that mw:Object/Template +// is in there. +ve.dm.MWTemplateNode.static.matchRdfaTypes = [ 'mw:Object/Template', /^mw:/ ]; + +ve.dm.MWTemplateNode.static.matchFunction = function ( domElement ) { + return ve.indexOf( 'mw:Object/Template', + ( domElement.getAttribute( 'typeof' ) || '' ).split( ' ' ) + ) !== -1; +}; ve.dm.MWTemplateNode.static.getHashObject = function ( dataElement ) { return { diff --git a/modules/ve/test/dm/ve.dm.example.js b/modules/ve/test/dm/ve.dm.example.js index 6d3a43a091..259dc66f43 100644 --- a/modules/ve/test/dm/ve.dm.example.js +++ b/modules/ve/test/dm/ve.dm.example.js @@ -865,7 +865,33 @@ ve.dm.example.MWTemplate = { 'html/0/data-parsoid': '{\"tsr\":[18,34],\"src\":\"{{Inline|1,234}}\",\"dsr\":[18,34,null,null]}', 'html/0/typeof': 'mw:Object/Template' }, - } + }, + 'mixed': 'Foo', + 'mixedDataOpen': { + 'type': 'MWtemplateInline', + 'attributes': { + 'mw': { + 'id': 'mwt1', + 'target': { 'wt': 'Inline' }, + 'params': { + '1': { 'wt': '5,678' } + } + }, + 'mwOriginal': { + 'id': 'mwt1', + 'target': { 'wt': 'Inline' }, + 'params': { + '1': { 'wt': '5,678' } + } + }, + 'html/0/about': '#mwt1', + 'html/0/rel': 'mw:WikiLink/Category', + 'html/0/typeof': 'mw:Object/Template', + 'html/0/data-mw': '{\"id\":\"mwt1\",\"target\":{\"wt\":\"Inline\"},\"params\":{\"1\":{\"wt\":\"5,678\"}}}', + 'html/1/about': '#mwt1' + } + }, + 'mixedDataClose' : { 'type': '/MWtemplateInline' } }; ve.dm.example.MWTemplate.blockParamsHash = ve.getHash( ve.dm.MWTemplateNode.static.getHashObject( ve.dm.example.MWTemplate.blockData ) ); @@ -880,6 +906,12 @@ ve.dm.example.MWTemplate.inlineStoreItems = { 'value': $( ve.dm.example.MWTemplate.inlineOpen + ve.dm.example.MWTemplate.inlineContent + ve.dm.example.MWTemplate.inlineClose ).get() }; +ve.dm.example.MWTemplate.mixedParamsHash = ve.getHash( ve.dm.MWTemplateNode.static.getHashObject( ve.dm.example.MWTemplate.mixedDataOpen ) ); +ve.dm.example.MWTemplate.mixedStoreItems = { + 'hash': ve.dm.example.MWTemplate.mixedParamsHash, + 'value': $( ve.dm.example.MWTemplate.mixed ).get() +}; + ve.dm.example.domToDataCases = { 'paragraph with plain text': { 'html': '

abc

', @@ -2210,22 +2242,16 @@ ve.dm.example.domToDataCases = { '', 'data': ve.dm.example.withMeta }, - 'RDFa types spread across two attributes': { - 'html': '', + 'RDFa types spread across two attributes, about grouping is forced': { + 'html': '' + ve.dm.example.MWTemplate.mixed + '', 'data': [ - { - 'type': 'alienMeta', - 'attributes': { - 'style': 'link', - 'key': 'mw:WikiLink/Category', - 'value': './Category:Foo', - 'html/0/rel': 'mw:WikiLink/Category', - 'html/0/href': './Category:Foo', - 'html/0/about': '#mwt1', - 'html/0/typeof': 'mw:Object/Template' - } - }, - { 'type': '/alienMeta' }, + { 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } }, + ve.dm.example.MWTemplate.mixedDataOpen, + ve.dm.example.MWTemplate.mixedDataClose, + { 'type': '/paragraph' } + ], + 'storeItems': [ + ve.dm.example.MWTemplate.mixedStoreItems ] }, 'about grouping': { @@ -2295,20 +2321,6 @@ ve.dm.example.domToDataCases = { { 'type': '/alienBlock' } ] }, - 'about grouping is forced': { - 'html': 'Foo', - 'data': [ - { 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } }, - { - 'type': 'alienInline', - 'attributes': { - 'domElements': $( 'Foo' ).get() - } - }, - { 'type': '/alienInline' }, - { 'type': '/paragraph' } - ] - }, 'mw:Entity': { 'html': '

a¢b¥

', 'data': [