Subramanya Sastry has uploaded a new change for review. https://gerrit.wikimedia.org/r/254906
Change subject: Followup on stripping trailing <nowiki/>s to retain valid uses ...................................................................... Followup on stripping trailing <nowiki/>s to retain valid uses * Transclusions can have trailing <nowiki/> when it is a valid template argument being passed in. * Eliminates selser diffs seen during roundtrip testing. Change-Id: I08c7b8b204d4a80c27efbefe8ef08efd7034c4c9 --- M lib/html2wt/WikitextSerializer.js M tests/parserTests.txt 2 files changed, 17 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/06/254906/1 diff --git a/lib/html2wt/WikitextSerializer.js b/lib/html2wt/WikitextSerializer.js index 003bfff..73bbab5 100644 --- a/lib/html2wt/WikitextSerializer.js +++ b/lib/html2wt/WikitextSerializer.js @@ -1194,7 +1194,13 @@ if (state.hasSelfClosingNowikis || state.selserMode) { // Strip (useless) trailing <nowiki/>s // Interim fix till we stop introducing them in the first place. - state.out = state.out.replace(/(?:<nowiki\s*\/>)+($|\n)/g, '$1'); + // + // Don't strip |param = <nowiki/> since that pattern is used + // in transclusions and where the trailing <nowiki /> is a valid + // template arg. So, use a conservative regexp to detect that usage. + state.out = state.out.split('\n').map(function(piece) { + return piece.replace(/^([^=]*?(?![^=]*=\s*))(?:<nowiki\s*\/>)+(\s*$)/g, '$1'); + }).join('\n'); } return state.out; diff --git a/tests/parserTests.txt b/tests/parserTests.txt index 3bdcb11..c28c008 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -26274,15 +26274,24 @@ # This is meant to be an interim fix while we go about figuring out # how to not introduce these trailing <nowiki/>s in the first place. !! test -T115717: Strip trailing <nowiki/>s +T115717: Strip trailing <nowiki/>s (without affecting valid uses) !! options parsoid=html2wt !! html/parsoid <p>x<meta typeof="mw:Placeholder" data-parsoid='{"src":"<nowiki/>"}'/><meta typeof="mw:Placeholder" data-parsoid='{"src":"<nowiki/>"}'/> y</p> +<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,23,null,null],"pi":[[{"k":"1","named":true,"spc":["\n"," "," ",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki/>"}},"i":0}}]}'></span></p> +<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,24,null,null],"pi":[[{"k":"1","named":true,"spc":["\n"," "," ","\n"]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki/>"}},"i":0}}]}'></span></p> !! wikitext x y + +{{echo| +1 = <nowiki/>}} + +{{echo| +1 = <nowiki/> +}} !! end # --------------------------------------------------- -- To view, visit https://gerrit.wikimedia.org/r/254906 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I08c7b8b204d4a80c27efbefe8ef08efd7034c4c9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits