jenkins-bot has submitted this change and it was merged.
Change subject: Make reference editing work
......................................................................
Make reference editing work
The only reason it doesn't save correctly right now is because Parsoid
doesn't serialize reference edits correctly.
Change-Id: Ia0f272c07cc28ee829372eb848f23aec99eb92f0
---
M modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
M modules/ve/dm/ve.dm.InternalList.js
M modules/ve/test/dm/ve.dm.example.js
3 files changed, 38 insertions(+), 27 deletions(-)
Approvals:
Trevor Parscal: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
index 9855603..c363521 100644
--- a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
@@ -36,12 +36,11 @@
ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter
) {
var dataElement, listIndex,
about = domElements[0].getAttribute( 'about' ),
- // TODO: this is always-present in the new spec, so "|| '{}'"
can be removed later
mw = JSON.parse( domElements[0].getAttribute( 'data-mw' ) ||
'{}' ),
- // TODO: this will be stored in mw.body.html in the new spec
- body = JSON.parse( domElements[0].getAttribute( 'data-parsoid'
) ).src,
- // TODO: this will be stored in mw.name in the new spec
- name = $( body ).attr( 'name' ),
+ body = mw.body.html,
+ // TODO: this should use mw.attrs.name once available from
Parsoid
+ name = $( domElements[0] ).children( 'a' ).attr( 'href' ),
+ // TODO: should also store and use mw.attrs.group once
available from Parsoid
key = name !== null ? name : ve.getHash( body );
listIndex = converter.internalList.addItem( key, body );
@@ -58,7 +57,7 @@
};
ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc,
converter ) {
- var itemNodeHtml,
+ var itemNodeHtml, mw,
span = doc.createElement( 'span' ),
itemNodeWrapper = doc.createElement( 'div' ),
itemNode = converter.internalList.getItemNode(
dataElement.attributes.listIndex ),
@@ -73,9 +72,9 @@
),
itemNodeHtml = $( itemNodeWrapper ).html();
- // TODO: store internalNodeHtml in data.mw:
- // dataElement.attributes.mw.body.html = itemNodeHtml;
- // span.setAttribute( 'data-mw', JSON.stringify(
dataElement.attributes.mw ) );
+ mw = ( dataElement.attributes && ve.copyObject(
dataElement.attributes.mw ) ) || {};
+ ve.setProp( mw, 'body', 'html', itemNodeHtml );
+ span.setAttribute( 'data-mw', JSON.stringify( mw ) );
return [ span ];
};
diff --git a/modules/ve/dm/ve.dm.InternalList.js
b/modules/ve/dm/ve.dm.InternalList.js
index db5cb82..db39eaa 100644
--- a/modules/ve/dm/ve.dm.InternalList.js
+++ b/modules/ve/dm/ve.dm.InternalList.js
@@ -118,7 +118,7 @@
if ( itemsHtml.length ) {
list.push( { 'type': 'internalList' } );
for ( i = 0, length = itemsHtml.length; i < length; i++ ) {
- itemData = converter.getDataFromDomRecursion( $(
itemsHtml[i] )[0] );
+ itemData = converter.getDataFromDomRecursion( $(
'<div>' ).html( itemsHtml[i] )[0] );
list = list.concat(
[{ 'type': 'internalItem' }],
itemData,
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index b2ce994..9eecf66 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -1180,22 +1180,26 @@
'<body>' +
'<p>Foo' +
'<span id="cite_ref-bar-1-0"
class="reference" about="#mwt5" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref
name=\\"bar\\">Bar</ref>"}">'+
+
'data-parsoid="{"src":"<ref
name=\\"bar\\">Bar</ref>"}"'+
+
'data-mw="{"body":{"html":"Bar"}}">' +
'<a href="#cite_note-bar-1"
data-parsoid="{}">[1]</a>' +
'</span>' +
' Baz' +
'<span id="cite_ref-quux-2-0"
class="reference" about="#mwt6" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref
name=\\"quux\\">Quux</ref>"}">' +
+
'data-parsoid="{"src":"<ref
name=\\"quux\\">Quux</ref>"}"' +
+
'data-mw="{"body":{"html":"Quux"}}">' +
'<a href="#cite_note-quux-2"
data-parsoid="{}">[2]</a>' +
'</span>' +
' Whee' +
'<span id="cite_ref-bar-1-1"
class="reference" about="#mwt7" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref name=\\"bar\\"
/>"}">' +
+
'data-parsoid="{"src":"<ref name=\\"bar\\" />"}"'
+
+
'data-mw="{"body":{"html":""}}">' +
'<a href="#cite_note-bar-1"
data-parsoid="{}">[1]</a>' +
'</span>' +
' Yay' +
'<span id="cite_ref-3-0"
class="reference" about="#mwt8" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref>No name</ref>"}">' +
+
'data-parsoid="{"src":"<ref>No name</ref>"}"' +
+
'data-mw="{"body":{"html":"No name"}}">' +
'<a href="#cite_note-3"
data-parsoid="{}">[3]</a>' +
'</span>' +
'</p>' +
@@ -1211,17 +1215,18 @@
'attributes': {
'about': '#mwt5',
'listIndex': 0,
- 'mw': {}
+ 'mw': { 'body': { 'html': 'Bar' } }
},
'htmlAttributes': [
{
- 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid' ],
+ 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid', 'data-mw' ],
'values': {
'about': '#mwt5',
'class': 'reference',
+ 'data-mw':
'{"body":{"html":"Bar"}}',
'data-parsoid':
'{"src":"<ref name=\\"bar\\">Bar</ref>"}',
'id':
'cite_ref-bar-1-0',
- 'typeof':
'mw:Object/Ext/Ref'
+ 'typeof':
'mw:Object/Ext/Ref',
},
'children': [
{
@@ -1242,14 +1247,15 @@
'attributes': {
'about': '#mwt6',
'listIndex': 1,
- 'mw': {}
+ 'mw': { 'body': { 'html': 'Quux' } }
},
'htmlAttributes': [
{
- 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid' ],
+ 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid', 'data-mw' ],
'values': {
'about': '#mwt6',
'class': 'reference',
+ 'data-mw':
'{"body":{"html":"Quux"}}',
'data-parsoid':
'{"src":"<ref name=\\"quux\\">Quux</ref>"}',
'id':
'cite_ref-quux-2-0',
'typeof':
'mw:Object/Ext/Ref'
@@ -1273,14 +1279,15 @@
'attributes': {
'about': '#mwt7',
'listIndex': 0,
- 'mw': {}
+ 'mw': { 'body': { 'html': '' } }
},
'htmlAttributes': [
{
- 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid' ],
+ 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid', 'data-mw' ],
'values': {
'about': '#mwt7',
'class': 'reference',
+ 'data-mw':
'{"body":{"html":""}}',
'data-parsoid':
'{"src":"<ref name=\\"bar\\" />"}',
'id':
'cite_ref-bar-1-1',
'typeof':
'mw:Object/Ext/Ref'
@@ -1304,14 +1311,15 @@
'attributes': {
'about': '#mwt8',
'listIndex': 2,
- 'mw': {}
+ 'mw': { 'body': { 'html': 'No name' } }
},
'htmlAttributes': [
{
- 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid' ],
+ 'keys': [ 'id', 'class',
'about', 'typeof', 'data-parsoid', 'data-mw' ],
'values': {
'about': '#mwt8',
'class': 'reference',
+ 'data-mw':
'{"body":{"html":"No name"}}',
'data-parsoid':
'{"src":"<ref>No name</ref>"}',
'id': 'cite_ref-3-0',
'typeof':
'mw:Object/Ext/Ref'
@@ -1358,19 +1366,23 @@
'normalizedHtml':
'<p>Foo' +
'<span id="cite_ref-bar-1-0" class="reference"
about="#mwt5" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref
name=\\"bar\\">Bar</ref>"}">'+
+
'data-parsoid="{"src":"<ref
name=\\"bar\\">Bar</ref>"}"' +
+
'data-mw="{"body":{"html":"Bar"}}">' +
'</span>' +
' Baz' +
'<span id="cite_ref-quux-2-0" class="reference"
about="#mwt6" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref
name=\\"quux\\">Quux</ref>"}">' +
+
'data-parsoid="{"src":"<ref
name=\\"quux\\">Quux</ref>"}"' +
+
'data-mw="{"body":{"html":"Quux"}}">' +
'</span>' +
' Whee' +
'<span id="cite_ref-bar-1-1" class="reference"
about="#mwt7" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref name=\\"bar\\"
/>"}">' +
+
'data-parsoid="{"src":"<ref name=\\"bar\\" />"}"'
+
+
'data-mw="{"body":{"html":"Bar"}}">' +
'</span>' +
' Yay' +
'<span id="cite_ref-3-0" class="reference"
about="#mwt8" typeof="mw:Object/Ext/Ref" ' +
-
'data-parsoid="{"src":"<ref>No name</ref>"}">' +
+
'data-parsoid="{"src":"<ref>No name</ref>"}"' +
+
'data-mw="{"body":{"html":"No name"}}">' +
'</span>' +
'</p>' +
'<ol class="references"
typeof="mw:Object/References"><li id="cite_note-quux-2"><a
href="#cite_ref-quux-2-0">u2191</a>Quux</li></ol>'
--
To view, visit https://gerrit.wikimedia.org/r/65441
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia0f272c07cc28ee829372eb848f23aec99eb92f0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits