[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Do not completely flatten links with child nodes

2018-01-17 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/404609 )

Change subject: Do not completely flatten links with child nodes
..


Do not completely flatten links with child nodes

Only flatten an anchor link to text content.

Bug: T185050
Change-Id: I05edcf02163289e2e735aff54743cd51cb7da42b
---
M lib/transformations/flattenElements.js
M test/lib/transformations/flattenElements.test.js
2 files changed, 14 insertions(+), 2 deletions(-)

Approvals:
  BearND: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Mholloway: Looks good to me, approved



diff --git a/lib/transformations/flattenElements.js 
b/lib/transformations/flattenElements.js
index 0ee39fc..8153bad 100644
--- a/lib/transformations/flattenElements.js
+++ b/lib/transformations/flattenElements.js
@@ -32,13 +32,13 @@
 }
 
 function createReplacementNode(oldElement, document) {
-if (hasAttribute(oldElement, KEEP_ATTRIBUTES)) {
+if (hasAttribute(oldElement, KEEP_ATTRIBUTES) || 
oldElement.querySelectorAll('*').length) {
 const spanElement = document.createElement('span');
 spanElement.innerHTML = oldElement.innerHTML;
 copyAttributes(oldElement, spanElement, KEEP_ATTRIBUTES);
 return spanElement;
 } else {
-return document.createTextNode(oldElement.innerHTML);
+return document.createTextNode(oldElement.textContent);
 }
 }
 
diff --git a/test/lib/transformations/flattenElements.test.js 
b/test/lib/transformations/flattenElements.test.js
index 3bc1c6c..afbd6ab 100644
--- a/test/lib/transformations/flattenElements.test.js
+++ b/test/lib/transformations/flattenElements.test.js
@@ -22,4 +22,16 @@
 flattenElements(document, 'a');
 assert.deepEqual(document.body.innerHTML, 'foo');
 });
+
+it('retains HTML inside elements', () => {
+const document = domino.createDocument('The Mummy 
franchise');
+flattenElements(document, 'a');
+assert.deepEqual(document.body.innerHTML, 'The Mummy 
franchise');
+});
+
+it('does not change the text content of the node', () => {
+const document = domino.createDocument('');
+flattenElements(document, 'a');
+assert.deepEqual(document.body.innerHTML, '');
+});
 });

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I05edcf02163289e2e735aff54743cd51cb7da42b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson 
Gerrit-Reviewer: BearND 
Gerrit-Reviewer: Fjalapeno 
Gerrit-Reviewer: Mholloway 
Gerrit-Reviewer: Mhurd 
Gerrit-Reviewer: Ppchelko 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Do not completely flatten links with child nodes

2018-01-16 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404609 )

Change subject: Do not completely flatten links with child nodes
..

Do not completely flatten links with child nodes

Only flatten an anchor link to text content.

Bug: T185050
Change-Id: I05edcf02163289e2e735aff54743cd51cb7da42b
---
M lib/transformations/flattenElements.js
M test/lib/transformations/flattenElements.test.js
2 files changed, 14 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/09/404609/1

diff --git a/lib/transformations/flattenElements.js 
b/lib/transformations/flattenElements.js
index 0ee39fc..8153bad 100644
--- a/lib/transformations/flattenElements.js
+++ b/lib/transformations/flattenElements.js
@@ -32,13 +32,13 @@
 }
 
 function createReplacementNode(oldElement, document) {
-if (hasAttribute(oldElement, KEEP_ATTRIBUTES)) {
+if (hasAttribute(oldElement, KEEP_ATTRIBUTES) || 
oldElement.querySelectorAll('*').length) {
 const spanElement = document.createElement('span');
 spanElement.innerHTML = oldElement.innerHTML;
 copyAttributes(oldElement, spanElement, KEEP_ATTRIBUTES);
 return spanElement;
 } else {
-return document.createTextNode(oldElement.innerHTML);
+return document.createTextNode(oldElement.textContent);
 }
 }
 
diff --git a/test/lib/transformations/flattenElements.test.js 
b/test/lib/transformations/flattenElements.test.js
index 3bc1c6c..afbd6ab 100644
--- a/test/lib/transformations/flattenElements.test.js
+++ b/test/lib/transformations/flattenElements.test.js
@@ -22,4 +22,16 @@
 flattenElements(document, 'a');
 assert.deepEqual(document.body.innerHTML, 'foo');
 });
+
+it('retains HTML inside elements', () => {
+const document = domino.createDocument('The Mummy 
franchise');
+flattenElements(document, 'a');
+assert.deepEqual(document.body.innerHTML, 'The Mummy 
franchise');
+});
+
+it('does not change the text content of the node', () => {
+const document = domino.createDocument('');
+flattenElements(document, 'a');
+assert.deepEqual(document.body.innerHTML, '');
+});
 });

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I05edcf02163289e2e735aff54743cd51cb7da42b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson 

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