jenkins-bot has submitted this change and it was merged. Change subject: Bug 53287: More robust in-table state tracking in the paragraph wrapper ......................................................................
Bug 53287: More robust in-table state tracking in the paragraph wrapper From the bug report: Unbalanced table tokens in pages like http://fi.wikipedia.org/wiki/Kypros throw off the in-table tracking in the paragraph wrapper. This causes newlines in fosterable position to be paragraph-wrapped, which is then fostered out. Broken behavior: echo -ne '{|\n<td><td>fo</td>\n\n\n\n|}' | node parse WARNING: DSR inconsistency: cs/s mismatch for node: BODY s: 0; cs: -1 <body><p data-parsoid='{"autoInsertedEnd":true,"dsr":[-1,-1,0,0]}'><br data-parsoid='{"dsr":[-1,-1,0,0]}'></p> <table data-parsoid='{"dsr":[0,24,2,2]}'> <tbody data-parsoid='{"dsr":[3,22,0,0]}'><tr data-parsoid='{"dsr":[3,19,0,0]}'><td data-parsoid='{"stx":"html","autoInsertedEnd":true,"dsr":[3,7,4,0]}'></td><td data-parsoid='{"stx":"html","dsr":[7,18,4,5]}'>fo</td></tr> </tbody></table></body> Correct behavior: echo -ne '{|\n<td><td>fo</td>\n\n\n\n|}' | node parse <body data-parsoid='{"dsr":[0,24,0,0]}'><table data-parsoid='{"dsr":[0,24,2,2]}'> <tbody data-parsoid='{"dsr":[3,22,0,0]}'><tr data-parsoid='{"autoInsertedEnd":true,"dsr":[3,18,0,0]}'><td data-parsoid='{"stx":"html","autoInsertedEnd":true,"dsr":[3,7,4,0]}'></td><td data-parsoid='{"stx":"html","dsr":[7,18,4,5]}'>fo</td></tr> </tbody></table></body> Change-Id: I4c607885ad52be3f39a1f72eb5ead9239e014820 --- M js/lib/ext.core.ParagraphWrapper.js M js/tests/parserTests.txt 2 files changed, 78 insertions(+), 16 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/js/lib/ext.core.ParagraphWrapper.js b/js/lib/ext.core.ParagraphWrapper.js index 2bd9440..67452fb 100644 --- a/js/lib/ext.core.ParagraphWrapper.js +++ b/js/lib/ext.core.ParagraphWrapper.js @@ -227,12 +227,17 @@ ParagraphWrapper.prototype.onAny = function ( token, frame ) { function updateTableContext(tblTags, token) { - function popTags(tblTags, tokenName, altTag1, altTag2) { - while (tblTags.length > 0) { - var topTag = tblTags.pop(); - if (topTag === tokenName || topTag === altTag1 || topTag === altTag2) { - break; - } + // popUntil: pop anything until one of the tag in this array is found. + // Pass null to disable. + // popThen: after a stop is reached (or popUntil was null), continue + // popping as long as the elements in this array match. Pass + // null to disable. + function popTags(tblTags, popUntil, popThen) { + while (popUntil && tblTags.length > 0 && popUntil.indexOf(tblTags.last()) === -1) { + tblTags.pop(); + } + while (popThen && tblTags.length > 0 && popThen.indexOf(tblTags.last()) !== -1) { + tblTags.pop(); } } @@ -243,23 +248,24 @@ } else { switch (tokenName) { case "table": - // Pop till we match - popTags(tblTags, tokenName); + // Pop a table scope + popTags(tblTags, ["table"], ["table"]); break; case "tbody": - // Pop till we match - popTags(tblTags, tokenName, "table"); + // Pop to the nearest table + popTags(tblTags, ["table"], null); break; case "tr": - // Pop till we match - popTags(tblTags, tokenName, "table", "tbody"); + case "thead": + case "tfoot": + case "caption": + // Pop to tbody or table, whichever is nearer + popTags(tblTags, ["tbody", "table"], null); break; case "td": case "th": - // Pop just the topmost tag if it matches the token - if (tblTags.last() === token.name) { - tblTags.pop(); - } + // Pop to tr or (if that fails) to tbody or table. + popTags(tblTags, ["tr", "tbody", "table"], null); break; } } diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt index 77523bf..2d1cd49 100644 --- a/js/tests/parserTests.txt +++ b/js/tests/parserTests.txt @@ -1600,6 +1600,62 @@ </pre> !!end +# TODO / maybe: fix wt2wt for this +!! test +Parsoid: Don't paragraph-wrap fosterable content +!! options +parsoid=wt2html +!! input +{| +<td></td> +<td></td> + + + +|} +!! result +<table> + +<tbody> +<tr> +<td></td> + +<td></td></tr> + + + +</tbody></table> +!! end + +!! test +Parsoid: Don't paragraph-wrap fosterable content even if table syntax is unbalanced +!! options +parsoid=wt2html +!! input +{| +<td> +<td> +</td> + + + +|} +!! result +<table> + +<tbody> +<tr> +<td></td> + +<td> +</td></tr> + + + +</tbody></table> +!! end + + #-------------------------------------------------------------------- # Transclusion parameter whitespace stripping tests # Behavior is different for positional and named parameters -- To view, visit https://gerrit.wikimedia.org/r/80681 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4c607885ad52be3f39a1f72eb5ead9239e014820 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Parsoid Gerrit-Branch: master Gerrit-Owner: GWicke <[email protected]> Gerrit-Reviewer: Cscott <[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
