jenkins-bot has submitted this change and it was merged.

Change subject: T88017: Remove data-parsoid.src for elts with valid data-mw and 
DSR info
......................................................................


T88017: Remove data-parsoid.src for elts with valid data-mw and DSR info

We don't need data-parsoid.src in these scenarios since the serializer 
can emit wikitext using data-mw and/or DSR just fine.

Change-Id: Ife17d1d4f3300b84ec769363f15a141ae2bcfc6b
---
M lib/dom.cleanup.js
M tests/parserTests.txt
2 files changed, 23 insertions(+), 20 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/dom.cleanup.js b/lib/dom.cleanup.js
index dc170ca..29f91fd 100644
--- a/lib/dom.cleanup.js
+++ b/lib/dom.cleanup.js
@@ -1,6 +1,7 @@
 "use strict";
 
-var DU = require('./mediawiki.DOMUtils.js').DOMUtils;
+var DU = require('./mediawiki.DOMUtils.js').DOMUtils,
+       WTSUtils = require('./wts.utils.js').WTSUtils;
 
 // Extension/ref/Marker nodes are now processed on the final top-level dom only
 // and have to be preserved all the way till that time.
@@ -57,18 +58,20 @@
 
                        dp.tagId = undefined;
 
-                       var validDM = !!Object.keys(DU.getDataMw(node)).length;
-                       if ( !validDM ) {
+                       var validDataMW = 
!!Object.keys(DU.getDataMw(node)).length;
+                       if ( !validDataMW ) {
                                // strip it
                                DU.setDataMw(node, undefined);
                        }
 
-                       // Remove data-parsoid.src from templates and 
extensions that have
-                       // valid data-mw and dsr.  This should reduce 
data-parsoid bloat.
-                       //
+                       // Remove dp.src from elements that have valid data-mw 
and dsr. This
+                       // should reduce data-parsoid bloat.
+                       if (validDataMW && WTSUtils.isValidDSR(dp.dsr)) {
+                               dp.src = undefined;
+                       }
                        // Transcluded nodes will not have dp.tsr set and dont 
need dp.src either
                        if 
(/(?:^|\s)mw:(Transclusion|Extension)(?=$|\s)/.test(node.getAttribute("typeof"))
 &&
-                               (!dp.tsr || validDM && dp.dsr && dp.dsr[0] && 
dp.dsr[1]))
+                               !dp.tsr)
                        {
                                dp.src = undefined;
                        }
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 18aeabb..cc0f27f 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -3838,12 +3838,12 @@
 <dl>
 <dt>
 <dl>
-<dt>foo<span typeof="mw:Placeholder" data-parsoid='{"src":" 
"}'>&nbsp;</span></dt>
+<dt>foo<span typeof="mw:Placeholder">&nbsp;</span></dt>
 <dd data-parsoid='{"stx":"row"}'>bar</dd>
 </dl></dt>
 </dl></li>
 </ul></dt>
-<dt>boo<span typeof="mw:Placeholder" data-parsoid='{"src":" 
"}'>&nbsp;</span></dt>
+<dt>boo<span typeof="mw:Placeholder">&nbsp;</span></dt>
 <dd data-parsoid='{"stx":"row"}'>baz</dd>
 </dl></li>
 </ol></li>
@@ -3911,7 +3911,7 @@
 <dl>
 <dt>
 <dl>
-<dt> foo<span typeof="mw:Placeholder" data-parsoid='{"src":" 
"}'>&nbsp;</span></dt>
+<dt> foo<span typeof="mw:Placeholder">&nbsp;</span></dt>
 <dd data-parsoid='{"stx":"row"}'> bar (who uses this?)</dd>
 </dl></dt>
 </dl></dd>
@@ -8918,7 +8918,7 @@
 !! options
 parsoid=html2wt
 !! html
-<meta property="mw:PageProp/forcetoc" 
data-parsoid='{"src":"__NOTOC__","magicSrc":"__NOTOC__"}'/>
+<meta property="mw:PageProp/forcetoc" data-parsoid='{"magicSrc":"__NOTOC__"}'/>
 !! wikitext
 __FORCETOC__
 !! end
@@ -8943,7 +8943,7 @@
 !! wikitext
 __NOEDITSECTION__
 !! html
-<meta property="mw:PageProp/noeditsection" 
data-parsoid='{"src":"__NOEDITSECTION__","magicSrc":"__NOEDITSECTION__"}'/>
+<meta property="mw:PageProp/noeditsection" 
data-parsoid='{"magicSrc":"__NOEDITSECTION__"}'/>
 !! end
 
 ###
@@ -9898,7 +9898,7 @@
 |c
 |}
 !!html/parsoid
-<meta typeof="mw:Includes/IncludeOnly" 
data-parsoid='{"src":"&lt;includeonly>a&lt;/includeonly>"'/><meta 
typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><table 
about="#mwt2" typeof="mw:ExpandedAttrs" 
data-mw='{"attribs":[[{"txt":"{{{b}}}","html":"&lt;span about=\"#mwt1\" 
typeof=\"mw:Param\" 
data-parsoid=\"{&amp;quot;dsr&amp;quot;:[31,38,null,null],&amp;quot;src&amp;quot;:&amp;quot;{{{b}}}&amp;quot;}\">{{{b}}}&lt;/span>"},{"html":""}]]}'
 data-parsoid='{"a":{"{{{b}}}":null},"sa":{"{{{b}}}":""}}'>
+<meta typeof="mw:Includes/IncludeOnly"/><meta 
typeof="mw:Includes/IncludeOnly/End"/><table about="#mwt2" 
typeof="mw:ExpandedAttrs" 
data-mw='{"attribs":[[{"txt":"{{{b}}}","html":"&lt;span about=\"#mwt1\" 
typeof=\"mw:Param\" 
data-parsoid=\"{&amp;quot;dsr&amp;quot;:[31,38,null,null],&amp;quot;src&amp;quot;:&amp;quot;{{{b}}}&amp;quot;}\">{{{b}}}&lt;/span>"},{"html":""}]]}'
 data-parsoid='{"a":{"{{{b}}}":null},"sa":{"{{{b}}}":""}}'>
 <tbody><tr><td>c</td></tr>
 </tbody></table>
 
@@ -18797,10 +18797,10 @@
 <div style="border&#160;: solid;">&#160;</div>
 
 !! html/parsoid
-<div style="width:50% !important" data-parsoid='{"stx":"html"}'><span 
typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> 
</span></div>
-<div style="width:50% !important" 
data-parsoid='{"stx":"html","a":{"style":"width:50% 
!important"},"sa":{"style":"width:50%&amp;nbsp;!important"}}'><span 
typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> 
</span></div>
-<div style="width:50% !important" 
data-parsoid='{"stx":"html","a":{"style":"width:50% 
!important"},"sa":{"style":"width:50%&amp;#160;!important"}}'><span 
typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> 
</span></div>
-<div style="border : solid;" data-parsoid='{"stx":"html"}'><span 
typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> 
</span></div>
+<div style="width:50% !important" data-parsoid='{"stx":"html"}'><span 
typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
+<div style="width:50% !important" 
data-parsoid='{"stx":"html","a":{"style":"width:50% 
!important"},"sa":{"style":"width:50%&amp;nbsp;!important"}}'><span 
typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
+<div style="width:50% !important" 
data-parsoid='{"stx":"html","a":{"style":"width:50% 
!important"},"sa":{"style":"width:50%&amp;#160;!important"}}'><span 
typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
+<div style="border : solid;" data-parsoid='{"stx":"html"}'><span 
typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
 
 !! end
 
@@ -20031,7 +20031,7 @@
 !! wikitext
 <ref name="test &amp; me">hi</ref>
 !! html
-<p><span about="#mwt2" class="reference" id="cite_ref-test_.26_me_1-0" 
rel="dc:references" typeof="mw:Extension/ref" data-parsoid='{"src":"&lt;ref 
name=\"test &amp;amp; me\">hi&lt;/ref>"}' 
data-mw='{"name":"ref","body":{"html":"hi"},"attrs":{"name":"test &amp;amp; 
me"}}'><a href="#cite_note-test_.26_me-1">[1]</a></span></p>
+<p><span about="#mwt2" class="reference" id="cite_ref-test_.26_me_1-0" 
rel="dc:references" typeof="mw:Extension/ref" 
data-mw='{"name":"ref","body":{"html":"hi"},"attrs":{"name":"test &amp;amp; 
me"}}'><a href="#cite_note-test_.26_me-1">[1]</a></span></p>
 !! end
 
 # This test is wt2html only because we're permitting the serializer to produce
@@ -22275,7 +22275,7 @@
 }}
 </table>
 !! html/parsoid
-<table about="#mwt1" typeof="mw:Transclusion" 
data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"#if:","function":"#if"},"params":{"1":{"wt":"\n&lt;td>foo&lt;/td>\n"}},"i":0}},"\n&lt;/table>"]}'
 
data-parsoid='{"stx":"html","pi":[[{"k":"1","spc":["","","",""]}]],"src":"&lt;table>\n{{#if:|\n&lt;td>foo&lt;/td>\n}}\n&lt;/table>"}'>
+<table about="#mwt1" typeof="mw:Transclusion" 
data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"#if:","function":"#if"},"params":{"1":{"wt":"\n&lt;td>foo&lt;/td>\n"}},"i":0}},"\n&lt;/table>"]}'
 data-parsoid='{"stx":"html","pi":[[{"k":"1","spc":["","","",""]}]]}'>
 
 </table>
 !! end
@@ -23085,7 +23085,7 @@
 !! options
 parsoid=html2wt
 !! html
-<link rel="mw:PageProp/redirect" href="Bar" data-parsoid='{"src":"#REDIRECT 
","a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>
+<link rel="mw:PageProp/redirect" href="Bar" 
data-parsoid='{"a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>
 !! wikitext
 #REDIRECT [[Bar]]
 !! end

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ife17d1d4f3300b84ec769363f15a141ae2bcfc6b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Marcoil <[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

Reply via email to