Marcoil has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184707
Change subject: WIP: T86271: Add newline before category link
......................................................................
WIP: T86271: Add newline before category link
When content between previous node and existing category link has
been removed, a newline should be added in wikitext to improve
legibility.
Change-Id: I1e676203a77d2076247bab8daeba6cf89934dca3
---
M lib/wts.TagHandlers.js
M lib/wts.separators.js
2 files changed, 30 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/07/184707/1
diff --git a/lib/wts.TagHandlers.js b/lib/wts.TagHandlers.js
index 1153980..283f5bd 100644
--- a/lib/wts.TagHandlers.js
+++ b/lib/wts.TagHandlers.js
@@ -1022,10 +1022,16 @@
sepnls: {
before: function (node, otherNode) {
var type = node.getAttribute('rel');
- if
(/(?:^|\s)mw:(PageProp|WikiLink)\/(Category|redirect)(?=$|\s)/.test(type) &&
- DU.isNewElt(node) ) {
- // Fresh category link: Serialize on
its own line
- return {min: 1};
+ if
(/(?:^|\s)mw:(PageProp|WikiLink)\/(Category|redirect)(?=$|\s)/.test(type)) {
+ if (DU.isNewElt(node)) {
+ // Fresh category link:
Serialize on its own line
+ return {min: 1};
+ } else if (node.previousSibling &&
DU.isMarkerMeta(node.previousSibling, "mw:DiffMarker") /*node.previousSibling
!== otherNode*/) {
+ // There's been removed content
in the middle, separate
+ return {min: 2};
+ } else {
+ return {};
+ }
} else {
return {};
}
diff --git a/lib/wts.separators.js b/lib/wts.separators.js
index e015743..b335347 100644
--- a/lib/wts.separators.js
+++ b/lib/wts.separators.js
@@ -72,17 +72,31 @@
* Collects, checks and integrates separator newline requirements to a sinple
* min, max structure.
*/
-function getSepNlConstraints(state, nodeA, sepNlsHandlerA, nodeB,
sepNlsHandlerB) {
+function getSepNlConstraints(state, sepType, nodeA, sepNlsHandlerA, nodeB,
sepNlsHandlerB) {
var nlConstraints = { a:{}, b:{} };
+
+ var diffMarkersInBetween = function (sepType, node, otherNode) {
+ var next = sepType === 'sibling'? node.nextSibling :
+ (sepType === 'parent-child'? node.firstChild :
otherNode.firstChild);
+ while (next) {
+ if (DU.isMarkerMeta(next, "mw:DiffMarker")) {
+ return true;
+ }
+ next = next.nextSibling;
+ }
+ return false;
+ };
// Leave constraints unchanged when:
// * both nodes are element nodes
// * both nodes were present in original wikitext
// * either one of them is sol-transparent
+ // * there's no changed/deleted nodes in between
if (DU.isElt(nodeA) && DU.isElt(nodeB)
&& !DU.isNewElt(nodeA) && !DU.isNewElt(nodeB)
&& (DU.emitsSolTransparentSingleLineWT(nodeA)
- || DU.emitsSolTransparentSingleLineWT(nodeB)))
+ || DU.emitsSolTransparentSingleLineWT(nodeB))
+ && !diffMarkersInBetween(sepType, nodeA, nodeB))
{
return nlConstraints;
}
@@ -343,22 +357,22 @@
if ( nodeA.nextSibling === nodeB ) {
// sibling separator
sepType = "sibling";
- nlConstraints = getSepNlConstraints(state, nodeA,
sepHandlerA.after,
+ nlConstraints = getSepNlConstraints(state, sepType, nodeA,
sepHandlerA.after,
nodeB, sepHandlerB.before);
} else if ( nodeB.parentNode === nodeA ) {
sepType = "parent-child";
// parent-child separator, nodeA parent of nodeB
- nlConstraints = getSepNlConstraints(state, nodeA,
sepHandlerA.firstChild,
+ nlConstraints = getSepNlConstraints(state, sepType, nodeA,
sepHandlerA.firstChild,
nodeB, sepHandlerB.before);
} else if ( nodeA.parentNode === nodeB ) {
sepType = "child-parent";
// parent-child separator, nodeB parent of nodeA
- nlConstraints = getSepNlConstraints(state, nodeA,
sepHandlerA.after,
+ nlConstraints = getSepNlConstraints(state, sepType, nodeA,
sepHandlerA.after,
nodeB, sepHandlerB.lastChild);
} else {
// sibling separator
sepType = "sibling";
- nlConstraints = getSepNlConstraints(state, nodeA,
sepHandlerA.after,
+ nlConstraints = getSepNlConstraints(state, sepType, nodeA,
sepHandlerA.after,
nodeB, sepHandlerB.before);
}
--
To view, visit https://gerrit.wikimedia.org/r/184707
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e676203a77d2076247bab8daeba6cf89934dca3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits