Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370697 )

Change subject: Empty tags are omitted from summary output
......................................................................

Empty tags are omitted from summary output

Change-Id: I28e6c6518036daa331dd181f437e4997903a3f21
---
M lib/transformations/summarize.js
M test/lib/transformations/summarize.js
2 files changed, 7 insertions(+), 1 deletion(-)


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

diff --git a/lib/transformations/summarize.js b/lib/transformations/summarize.js
index 7668c07..8c78d2e 100644
--- a/lib/transformations/summarize.js
+++ b/lib/transformations/summarize.js
@@ -15,5 +15,6 @@
     rmElementsWithSelector(doc, '.mw-ref');
     rmElementsWithSelector(doc, '.noexcerpts');
     rmElementsWithSelector(doc, 'math');
+    rmElementsWithSelector(doc, 'span:empty,b:empty,i:empty,p:empty');
     return doc.body.innerHTML;
 };
diff --git a/test/lib/transformations/summarize.js 
b/test/lib/transformations/summarize.js
index 43a2914..47f0745 100644
--- a/test/lib/transformations/summarize.js
+++ b/test/lib/transformations/summarize.js
@@ -8,6 +8,11 @@
 describe('summarize', () => {
     it('matches the spec', () => {
         const testCases = [
+            // Should flatten empty nodes
+            [
+                '<span></span><b></b><i></i><p><span>f</span></p>',
+                '<p><span>f</span></p>'
+            ],
             // Should flatten links
             [
                 'This is some content with <a href="#"">a link</a>.',
@@ -31,7 +36,7 @@
             // math tags are stripped but any math images are shown
             [
                 '<p>The Planck–Einstein relation connects the particulate 
photon energy <span class=\"texhtml \"><i>E</i></span> with its associated wave 
frequency <span class=\"texhtml \"><i>f</i></span>:</p>\n\n<dl id=\"mwmQ\"><dd 
id=\"mwmg\"><span class=\"mwe-math-element\"><span 
class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\" style=\"display: 
none;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\";>\n  <semantics>\n    
<mrow class=\"MJX-TeXAtom-ORD\">\n      <mstyle displaystyle=\"true\" 
scriptlevel=\"0\">\n        <mi>E</mi>\n        <mo>=</mo>\n        
<mi>h</mi>\n        <mi>f</mi>\n      </mstyle>\n    </mrow>\n    <annotation 
encoding=\"application/x-tex\">{\\displaystyle E=hf}</annotation>\n  
</semantics>\n</math></span><img 
src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/f39fac3593bb1e2dec0282c112c4dff7a99007f6\";
 class=\"mwe-math-fallback-image-inline\" aria-hidden=\"true\" 
style=\"vertical-align: -0.671ex; width:7.533ex; 
height:2.509ex;\"></span></dd></dl>',
-                '<p>The Planck–Einstein relation connects the particulate 
photon energy <span class=\"texhtml \"><i>E</i></span> with its associated wave 
frequency <span class=\"texhtml \"><i>f</i></span>:</p>\n\n<dl id=\"mwmQ\"><dd 
id=\"mwmg\"><span class=\"mwe-math-element\"><span 
class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\" style=\"display: 
none;\"></span><img 
src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/f39fac3593bb1e2dec0282c112c4dff7a99007f6\";
 class=\"mwe-math-fallback-image-inline\" aria-hidden=\"true\" 
style=\"vertical-align: -0.671ex; width:7.533ex; 
height:2.509ex;\"></span></dd></dl>'
+                '<p>The Planck–Einstein relation connects the particulate 
photon energy <span class=\"texhtml \"><i>E</i></span> with its associated wave 
frequency <span class=\"texhtml \"><i>f</i></span>:</p>\n\n<dl id=\"mwmQ\"><dd 
id=\"mwmg\"><span class=\"mwe-math-element\"><img 
src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/f39fac3593bb1e2dec0282c112c4dff7a99007f6\";
 class=\"mwe-math-fallback-image-inline\" aria-hidden=\"true\" 
style=\"vertical-align: -0.671ex; width:7.533ex; 
height:2.509ex;\"></span></dd></dl>'
             ]
         ];
         testCases.forEach((test) => {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28e6c6518036daa331dd181f437e4997903a3f21
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to