jenkins-bot has submitted this change and it was merged.
Change subject: Associate data-parsoid with duplicated ids
......................................................................
Associate data-parsoid with duplicated ids
* Not sure this is actually a good thing. When we discussed stable-ids,
it was pointed out that clients should take care not to duplicate
ids. Ids are unique to a page so this content isn't well formed.
Change-Id: I0c2f91ac961ac7471c9836c7b543ade894c3147b
---
M lib/mediawiki.DOMUtils.js
M tests/mocha/api.js
2 files changed, 46 insertions(+), 10 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/mediawiki.DOMUtils.js b/lib/mediawiki.DOMUtils.js
index 8ed1efd..e54c58c 100644
--- a/lib/mediawiki.DOMUtils.js
+++ b/lib/mediawiki.DOMUtils.js
@@ -2007,17 +2007,25 @@
},
// Applies a data-parsoid JSON structure to the document.
- // Removes the generated ids from each elements,
- // and adds back the data-parsoid attributes.
- applyDataParsoid: function ( document, dp ) {
- Object.keys( dp.ids ).forEach(function ( key ) {
- var el = document.getElementById( key );
- if ( el ) {
- this.setJSONAttribute( el, 'data-parsoid',
dp.ids[key] );
+ // Leaves id attributes behind -- they are used by citation
+ // code to extract <ref> body from the DOM.
+ applyDataParsoid: function( document, dp ) {
+ function applyToSiblings( node ) {
+ var id;
+ while ( node ) {
+ if ( DU.isElt( node ) ) {
+ id = node.getAttribute("id");
+ if ( dp.ids.hasOwnProperty( id ) ) {
+ DU.setJSONAttribute( node,
'data-parsoid', dp.ids[id] );
+ }
+ if ( node.childNodes.length > 0 ) {
+ applyToSiblings(
node.firstChild );
+ }
+ }
+ node = node.nextSibling;
}
- // Leave id attribute behind -- it is used by citation
- // code to extract <ref> body from the DOM.
- }.bind( this ));
+ }
+ applyToSiblings( document.body );
},
// Removes the data-parsoid attribute from a node,
diff --git a/tests/mocha/api.js b/tests/mocha/api.js
index 6af7585..bc98d98 100644
--- a/tests/mocha/api.js
+++ b/tests/mocha/api.js
@@ -510,6 +510,34 @@
.end(done);
});
+ it('should apply data-parsoid to duplicated ids',
function(done) {
+ request(api)
+ .post('v2/' + mockHost + '/wt/')
+ .send({
+ html: "<html><body id=\"mwAA\"><div
id=\"mwBB\">data-parsoid test</div><div id=\"mwBB\">data-parsoid
test</div></body></html>",
+ original: {
+ title: "Doesnotexist",
+ html: {
+ body: "<html><body
id=\"mwAA\"><div id=\"mwBB\">data-parsoid test</div></body></html>",
+ },
+ "data-parsoid": {
+ body: {
+ "ids": {
+ mwAA:
{},
+ mwBB: {
"autoInsertedEnd": true, "stx": "html" }
+ }
+ }
+ }
+ }
+ })
+ .expect(200)
+ .expect(function(res) {
+
res.body.should.have.property("wikitext");
+
res.body.wikitext.body.should.equal("<div>data-parsoid test<div>data-parsoid
test");
+ })
+ .end(done);
+ });
+
}); // end html2wt
});
--
To view, visit https://gerrit.wikimedia.org/r/198001
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c2f91ac961ac7471c9836c7b543ade894c3147b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits