Merge "Avoid splitting about-groups starting with an empty <span>"

This commit is contained in:
jenkins-bot 2021-11-15 21:38:56 +00:00 committed by Gerrit Code Review
commit 9fbf2b3177
3 changed files with 20 additions and 5 deletions

View file

@ -47,6 +47,7 @@ class CommentUtils {
* @return bool Node is considered a rendering-transparent node in Parsoid
*/
public static function isRenderingTransparentNode( Node $node ): bool {
$nextSibling = $node->nextSibling;
return (
$node instanceof Comment ||
$node instanceof Element && (
@ -55,11 +56,18 @@ class CommentUtils {
strtolower( $node->tagName ) === 'link' &&
preg_match( self::SOL_TRANSPARENT_LINK_REGEX, $node->getAttribute( 'rel' ) ?? '' )
) ||
// Empty inline templates, e.g. tracking templates
// Empty inline templates, e.g. tracking templates. (T269036)
// But not empty nodes that are just the start of a non-empty template about-group. (T290940)
(
strtolower( $node->tagName ) === 'span' &&
in_array( 'mw:Transclusion', explode( ' ', $node->getAttribute( 'typeof' ) ?? '' ) ) &&
!self::htmlTrim( DOMCompat::getInnerHTML( $node ) )
!self::htmlTrim( DOMCompat::getInnerHTML( $node ) ) &&
(
!$nextSibling || !( $nextSibling instanceof Element ) ||
// Maybe we should be checking all of the about-grouped nodes to see if they're empty,
// but that's prooobably not needed in practice, and it leads to a quadratic worst case.
$nextSibling->getAttribute( 'about' ) !== $node->getAttribute( 'about' )
)
)
)
);

View file

@ -21,6 +21,7 @@ var solTransparentLinkRegexp = /(?:^|\s)mw:PageProp\/(?:Category|redirect|Langua
* @return {boolean} Node is considered a rendering-transparent node in Parsoid
*/
function isRenderingTransparentNode( node ) {
var nextSibling = node.nextSibling;
return (
node.nodeType === Node.COMMENT_NODE ||
node.nodeType === Node.ELEMENT_NODE && (
@ -34,7 +35,13 @@ function isRenderingTransparentNode( node ) {
node.tagName.toLowerCase() === 'span' &&
( node.getAttribute( 'typeof' ) || '' ).split( ' ' ).indexOf( 'mw:Transclusion' ) !== -1 &&
// eslint-disable-next-line no-use-before-define
!htmlTrim( node.innerHTML )
!htmlTrim( node.innerHTML ) &&
(
!nextSibling || nextSibling.nodeType !== Node.ELEMENT_NODE ||
// Maybe we should be checking all of the about-grouped nodes to see if they're empty,
// but that's prooobably not needed in practice, and it leads to a quadratic worst case.
nextSibling.getAttribute( 'about' ) !== node.getAttribute( 'about' )
)
)
)
);

View file

@ -1,6 +1,6 @@
<!DOCTYPE html>
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="https://en.wikipedia.beta.wmflabs.org/wiki/Special:Redirect/revision/513949"><head prefix="mwr: https://en.wikipedia.beta.wmflabs.org/wiki/Special:Redirect/"><meta property="mw:TimeUuid" content="a4ac8490-43f9-11ec-8c00-619144b79799"/><meta charset="utf-8"/><meta property="mw:pageId" content="266763"/><meta property="mw:pageNamespace" content="1"/><link rel="dc:replaces" resource="mwr:revision/513948"/><meta property="mw:revisionSHA1" content="2ac6b8686bf322ce9276fcbc0135e84a1d4861fb"/><meta property="dc:modified" content="2021-11-12T14:23:08.000Z"/><meta property="mw:htmlVersion" content="2.3.0"/><meta property="mw:html:version" content="2.3.0"/><link rel="dc:isVersionOf" href="https://en.wikipedia.beta.wmflabs.org/wiki/Talk%3AT290940"/><title>Talk:T290940</title><base href="https://en.wikipedia.beta.wmflabs.org/wiki/"/><link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=mediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles&amp;only=styles&amp;skin=vector"/><meta http-equiv="content-language" content="en"/><meta http-equiv="vary" content="Accept"/></head><body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><section data-mw-section-id="0" id="mwAQ"><p id="mwAg">1 <a rel="mw:WikiLink" href="./User:Yatu" title="User:Yatu" id="mwAw">Yatu</a> (<a rel="mw:WikiLink" href="./User_talk:Yatu" title="User talk:Yatu" id="mwBA">talk</a>) 14:21, 12 November 2021 (UTC)</p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n\n2 [[User:Yatu|Yatu]] ([[User talk:Yatu|talk]]) 14:22, 12 November 2021 (UTC)"}},"i":0}}]}' id="mwBQ">
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="https://en.wikipedia.beta.wmflabs.org/wiki/Special:Redirect/revision/513949"><head prefix="mwr: https://en.wikipedia.beta.wmflabs.org/wiki/Special:Redirect/"><meta property="mw:TimeUuid" content="a4ac8490-43f9-11ec-8c00-619144b79799"/><meta charset="utf-8"/><meta property="mw:pageId" content="266763"/><meta property="mw:pageNamespace" content="1"/><link rel="dc:replaces" resource="mwr:revision/513948"/><meta property="mw:revisionSHA1" content="2ac6b8686bf322ce9276fcbc0135e84a1d4861fb"/><meta property="dc:modified" content="2021-11-12T14:23:08.000Z"/><meta property="mw:htmlVersion" content="2.3.0"/><meta property="mw:html:version" content="2.3.0"/><link rel="dc:isVersionOf" href="https://en.wikipedia.beta.wmflabs.org/wiki/Talk%3AT290940"/><title>Talk:T290940</title><base href="https://en.wikipedia.beta.wmflabs.org/wiki/"/><link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=mediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles&amp;only=styles&amp;skin=vector"/><meta http-equiv="content-language" content="en"/><meta http-equiv="vary" content="Accept"/></head><body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><section data-mw-section-id="0" id="mwAQ"><p id="mwAg">1 <a rel="mw:WikiLink" href="./User:Yatu" title="User:Yatu" id="mwAw">Yatu</a> (<a rel="mw:WikiLink" href="./User_talk:Yatu" title="User talk:Yatu" id="mwBA">talk</a>) 14:21, 12 November 2021 (UTC)</p><dl><dd data-parsoid="{}">Reply to c-Yatu-2021-11-12T14:21:00.000Z</dd></dl><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n\n2 [[User:Yatu|Yatu]] ([[User talk:Yatu|talk]]) 14:22, 12 November 2021 (UTC)"}},"i":0}}]}' id="mwBQ">
</span><dl><dd data-parsoid="{}">Reply to c-Yatu-2021-11-12T14:21:00.000Z</dd></dl><p about="#mwt1">2 <a rel="mw:WikiLink" href="./User:Yatu" title="User:Yatu">Yatu</a> (<a rel="mw:WikiLink" href="./User_talk:Yatu" title="User talk:Yatu">talk</a>) 14:22, 12 November 2021 (UTC)</p><dl><dd data-parsoid="{}">Reply to c-Yatu-2021-11-12T14:22:00.000Z</dd></dl>
</span><p about="#mwt1">2 <a rel="mw:WikiLink" href="./User:Yatu" title="User:Yatu">Yatu</a> (<a rel="mw:WikiLink" href="./User_talk:Yatu" title="User talk:Yatu">talk</a>) 14:22, 12 November 2021 (UTC)</p><dl><dd data-parsoid="{}">Reply to c-Yatu-2021-11-12T14:22:00.000Z</dd></dl>
<p id="mwBg">3 <a rel="mw:WikiLink" href="./User:Yatu" title="User:Yatu" id="mwBw">Yatu</a> (<a rel="mw:WikiLink" href="./User_talk:Yatu" title="User talk:Yatu" id="mwCA">talk</a>) 14:23, 12 November 2021 (UTC)</p><dl><dd data-parsoid="{}">Reply to c-Yatu-2021-11-12T14:23:00.000Z</dd></dl></section></body></html>