Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373420 )
Change subject: T172896: Add mw-empty-elt class to empty li items that can't be
deleted
......................................................................
T172896: Add mw-empty-elt class to empty li items that can't be deleted
* This piece of wikitext "* {{DCdatabase|Batman}}" generates an empty
<li> item that cannot be removed because it has template encapsulation
information.
* In keeping with how empty list items are treated in core, this
patch adds the mw-empty-elt class to it.
Change-Id: I906ee8347726e1fb2cc0b1304ba8e0714afe5f12
---
M lib/utils/DOMUtils.js
M lib/wt2html/pp/handlers/cleanup.js
2 files changed, 19 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/20/373420/1
diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js
index 8fd5b5e..e073bde 100644
--- a/lib/utils/DOMUtils.js
+++ b/lib/utils/DOMUtils.js
@@ -1335,24 +1335,19 @@
* `strict` adds the condition that all whitespace is forbidden.
*/
nodeEssentiallyEmpty: function(node, strict) {
- var childNodes = node.childNodes;
- if (childNodes.length === 0) {
- return true;
- } else {
- var n = node.firstChild;
- while (n) {
- if (DU.isElt(n) && !this.isDiffMarker(n)) {
- return false;
- } else if (DU.isText(n) &&
- (strict || !/^[
\t]*$/.test(n.nodeValue))) {
- return false;
- } else if (DU.isComment(n)) {
- return false;
- }
- n = n.nextSibling;
+ var n = node.firstChild;
+ while (n) {
+ if (DU.isElt(n) && !this.isDiffMarker(n)) {
+ return false;
+ } else if (DU.isText(n) &&
+ (strict || !/^[
\t]*$/.test(n.nodeValue))) {
+ return false;
+ } else if (DU.isComment(n)) {
+ return false;
}
- return true;
+ n = n.nextSibling;
}
+ return true;
},
/**
diff --git a/lib/wt2html/pp/handlers/cleanup.js
b/lib/wt2html/pp/handlers/cleanup.js
index d588ec8..f335105 100644
--- a/lib/wt2html/pp/handlers/cleanup.js
+++ b/lib/wt2html/pp/handlers/cleanup.js
@@ -38,7 +38,7 @@
}
function stripEmptyElements(node, env, atTopLevel, tplInfo) {
- if (!atTopLevel || !tplInfo || !DU.isElt(node)) {
+ if (!atTopLevel || !DU.isElt(node) || (!tplInfo && node.nodeName !==
'LI')) {
return true;
}
@@ -48,13 +48,19 @@
// the info over, but more pain than worth it. We can reconsider if
// this ever becomes an issue.
// * it has any attributes.
- if (!node.firstChild && node !== tplInfo.first &&
+ if (!node.firstChild && tplInfo && node !== tplInfo.first &&
node.nodeName in { 'TR': 1, 'LI': 1 } && node.attributes.length
=== 0
) {
var nextNode = node.nextSibling;
DU.deleteNode(node);
return nextNode;
} else {
+ // Non-deleted empty <li> nodes should get the mw-empty-elt
class
+ if (node.nodeName === 'LI' && DU.nodeEssentiallyEmpty(node)) {
+ var classNames = node.getAttribute('class');
+ classNames = classNames ? classNames + ' mw-empty-elt':
'mw-empty-elt';
+ node.setAttribute('class', classNames);
+ }
return true;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/373420
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I906ee8347726e1fb2cc0b1304ba8e0714afe5f12
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits