jenkins-bot has submitted this change and it was merged. Change subject: Remove (mw:TSRMarker meta token + add tsr info) for captions ......................................................................
Remove (mw:TSRMarker meta token + add tsr info) for captions * Unlike td & th tags, captions always have a closing end tag while eliminates the need for TSRMarker tags for these. * Leads to improved DSR for captions for this table: {| |+ a | b |} <caption data-parsoid='{"dsr":[3,7,2,0]}'> a</caption> versus <caption data-parsoid='{"dsr":[3,7,2,null]}'> a</caption> * The changes in the blacklist are due to these changes. Change-Id: I577799ad7eb6bbad6a688ba431143fcbefd4bb42 --- M lib/wt2html/pegTokenizer.pegjs.txt M lib/wt2html/tokenizer.utils.js M tests/parserTests-blacklist.js 3 files changed, 26 insertions(+), 27 deletions(-) Approvals: Arlolra: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/wt2html/pegTokenizer.pegjs.txt b/lib/wt2html/pegTokenizer.pegjs.txt index ed85ca6..e8128db 100644 --- a/lib/wt2html/pegTokenizer.pegjs.txt +++ b/lib/wt2html/pegTokenizer.pegjs.txt @@ -1570,8 +1570,7 @@ args:row_syntax_table_args? tagEndPos:("" { return endOffset(); }) c:nested_block_in_table* { - return tu.buildTableTokens("caption", "|+", args, [startOffset(), tagEndPos], endOffset(), c) - .concat([new EndTagTk('caption')]); + return tu.buildTableTokens("caption", "|+", args, [startOffset(), tagEndPos], endOffset(), c, true); } table_row_tag diff --git a/lib/wt2html/tokenizer.utils.js b/lib/wt2html/tokenizer.utils.js index 5bb8777..4488c9a 100644 --- a/lib/wt2html/tokenizer.utils.js +++ b/lib/wt2html/tokenizer.utils.js @@ -98,7 +98,7 @@ }; }, - buildTableTokens: function(tagName, wtChar, attrInfo, tsr, endPos, content) { + buildTableTokens: function(tagName, wtChar, attrInfo, tsr, endPos, content, addEndTag) { var a; var dp = { tsr: tsr }; @@ -123,27 +123,27 @@ } } - var tokens = [new TagTk(tagName, a, dp)].concat(content); + var dataAttribs = { tsr: [endPos, endPos] }; + var endTag; + if (addEndTag) { + endTag = new EndTagTk(tagName, [], dataAttribs); + } else { + // We rely on our tree builder to close the table cell (td/th) as needed. + // We cannot close the cell here because cell content can come from + // multiple parsing contexts and we cannot close the tag in the same + // parsing context in which the td was opened: + // Ex: {{echo|{{!}}foo}}{{echo|bar}} has to output <td>foobar</td> + // + // But, add a marker meta-tag to capture tsr info. + // SSS FIXME: Unsure if this is actually helpful, but adding it in just in case. + // Can test later and strip it out if it doesn't make any diff to rting. + endTag = new SelfclosingTagTk('meta', [ + new KV('typeof', 'mw:TSRMarker'), + new KV('data-etag', tagName), + ], dataAttribs); + } - // We rely on our tree builder to close the table cell (td/th) as needed. - // We cannot close the cell here because cell content can come from - // multiple parsing contexts and we cannot close the tag in the same - // parsing context in which the td was opened: - // Ex: {{echo|{{!}}foo}}{{echo|bar}} has to output <td>foobar</td> - // - // But, add a marker meta-tag to capture tsr info. - // SSS FIXME: Unsure if this is actually helpful, but adding it in just in case. - // Can test later and strip it out if it doesn't make any diff to rting. - tokens.push( - new SelfclosingTagTk('meta', [ - new KV('typeof', 'mw:TSRMarker'), - new KV('data-etag', tagName), - ], { - tsr: [endPos, endPos], - }) - ); - - return tokens; + return [new TagTk(tagName, a, dp)].concat(content, endTag); }, buildXMLTag: function(name, lcName, attribs, endTag, selfClose, tsr) { diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js index f4563f9..2d03df4 100644 --- a/tests/parserTests-blacklist.js +++ b/tests/parserTests-blacklist.js @@ -1469,16 +1469,16 @@ add("selser", "Unclosed and unmatched quotes [3,0,[2],0,[[2]],3,[3,0],0,4,4,0,0,3,2,0,3,[[4],2,4,0,3,0],2,3,3,[3,3,0]]", "\nt6n1bkvx9wq7u8fr'''''Bold italic text ''with italic deactivated'' in between.'''''\n\n'''mdiwcalkyki6bt9Bold text..'''\n\n'''\n\n1il337h4ozu84cxr\n\nowkwkmpgu45z5mi\n\n''Italic tag left open\n\n0jlauri2d7gjsjor\n\n<!-- Unmatching number of opening, closing tags: -->'''xapa2a5a6cdw8kt9'''lc002uv6d1dzpvis election fik23fdz9d89qkt9 beat s.\n\n8ykwjs7kuwg0hpvi\n\ns plain"); add("selser", "Unclosed and unmatched quotes [2,4,3,0,2,0,1,0,[3],0,[2],0,2,0,0,2,[2,2,4,0,1,0],2,4,3,4]", "re6gnnkhd1tnjyvi\n\n'''''Bold italic text '''with bold deactivated''' in between.'''''\n\nbdwnekfnkxei2j4i\n\nva244jbhttpdgqfr\n\n'''Bold text..\n\n..spanning two paragraphs (should not work).'''\n\nlrd6syi4ygugzaor''Italic tag left open\n\nknfaulivfgca0pb9\n\nNormal text.\n\n<!-- Unmatching number of opening, closing tags: -->h8w8s0eci66tuik9\n\nu9daa8hfmgm5z5mi'''This year'<nowiki/>'''s4k3bfthkfq1tt9s election am5ar352e2ltbj4i beat '''last year''''s.\n\nrgsn8f7qx23p7gb9\n\nlhg77py8ot21emi\n\n7h6jcsa4wmzsq0k9\n"); add("selser", "Unclosed and unmatched quotes [[1],2,4,0,[4],0,[4,0],0,[[2]],3,2,0,2,0,0,2,[0,2,2,0,1,0],0,1,0,2]", "'''''Bold italic text '''with bold deactivated''' in between.'''''\n\n91y6zy5s4079zfr\n\nmkyoq2vkvt0jatt9\n\n8yeajt4jwaru23xr\n\nn2z6ghxy6lp7gb9'''<nowiki/>'''\n\n'''9c8lhwf3v6zgp66rBold tag left open'''\n\nootbfqoaxawi2j4i\n\n''Italic tag left open\n\nvv89fig83pst6gvi\n\nNormal text.\n\n<!-- Unmatching number of opening, closing tags: -->73vckpnoy6s3v7vi\n\n'''This year'<nowiki/>'''eedgwt17jt9be29s election gqta5jrflissjor''should'' beat '''last year''''s.\n\n''Tom'''s car is bigger than '''''<nowiki/>'''Susan'''s.\n\nz1mgwtgr2xjhh0k9\n\nPlain ''italic'''s plain"); -add("selser", "A table with captions with non-default spaced attributes and a table row [[3,2,3,[4],4,[2,4]]]", "{|<!--90q42mbx340a4i-->\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\" |68x5dnp2q5xw29<!--msaci0wnxchgds4i--><!--fhl1z8tl9txu5wmi-->\n|-\n| foo<!--z5tecc0c7ynwmi-->\n|}"); +add("selser", "A table with captions with non-default spaced attributes and a table row [[3,2,3,[4],4,[2,4]]]", "{|<!--90q42mbx340a4i-->\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\"|68x5dnp2q5xw29<!--msaci0wnxchgds4i--><!--fhl1z8tl9txu5wmi-->\n|-\n| foo<!--z5tecc0c7ynwmi-->\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[0,2,4,0,3,[4,0]]]", "{|\n<!--8folgr0kquboi529-->|+style=\"color: red;\"|caption2<!--9isvnh2z6j2it3xr-->\n|+ style=\"color: red;\"| caption3<!--cegg9qdr9hjgu8fr-->\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[2,0,2,3,3,3]]", "{|<!--69d5z7pa8iio1or-->\n|+style=\"color: red;\"|caption2<!--1r97810ys18j8aor-->\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [2]", "ogl2d411a038r529\n{|\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\"| caption3\n|-\n| foo\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[4,[3],2,0,3,[[3,4],4]]]", "{|<!--glpyv8ws43elv7vi-->\n|+ style=\"color: red;\" |<!--977mpdg7bdg6i529-->\n|+ style=\"color: red;\"| caption3\n|-\n|vnlowwkt14hadcxr<!--tw8w8jwmz4p1fw29-->\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[2,2,0,4,2,[0,4]]]", "{|<!--hq2lymey7xxkcsor-->\n<!--q20r2b6ga9xry66r-->|+style=\"color: red;\"|caption2\n<!--kyojp7sr96v18aor--><!--bky3qng4ga2a9k9-->\n|-\n| foo<!--phpg9eaca86ez5mi-->\n|}"); -add("selser", "A table with captions with non-default spaced attributes and a table row [[0,[2],0,0,0,[[0,2],0]]]", "{|\n|+ style=\"color: red;\" |rsk37teyuq22csorcaption2\n|+ style=\"color: red;\"| caption3\n|-\n|vefem1fh6g1ll3di\n| foo\n|}"); -add("selser", "A table with captions with non-default spaced attributes and a table row [[2,0,3,[2],0,[2,0]]]", "{|<!--8q7n7m2tbswwb3xr-->\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\" |lcnpzckjupgphkt9 caption3\n<!--px2ept6jeswnrk9-->|-\n| foo\n|}"); +add("selser", "A table with captions with non-default spaced attributes and a table row [[0,[2],0,0,0,[[0,2],0]]]", "{|\n|+style=\"color: red;\"|rsk37teyuq22csorcaption2\n|+ style=\"color: red;\"| caption3\n|-\n|vefem1fh6g1ll3di\n| foo\n|}"); +add("selser", "A table with captions with non-default spaced attributes and a table row [[2,0,3,[2],0,[2,0]]]", "{|<!--8q7n7m2tbswwb3xr-->\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\"|lcnpzckjupgphkt9 caption3\n<!--px2ept6jeswnrk9-->|-\n| foo\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [1]", "{| data-foobar=\"o9k0fan234k7qfr\"\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\"| caption3\n|-\n| foo\n|}"); -add("selser", "A table with captions with non-default spaced attributes and a table row [[0,[2],0,2,3,[[2,0],0]]]", "{|\n|+ style=\"color: red;\" |w96hfg740cm78pvicaption2\n<!--s66fh5bg5g1wz5mi-->|+ style=\"color: red;\"| caption3\n|-\n|i7akogjci8i4fgvi\n| foo\n|}"); +add("selser", "A table with captions with non-default spaced attributes and a table row [[0,[2],0,2,3,[[2,0],0]]]", "{|\n|+style=\"color: red;\"|w96hfg740cm78pvicaption2\n<!--s66fh5bg5g1wz5mi-->|+ style=\"color: red;\"| caption3\n|-\n|i7akogjci8i4fgvi\n| foo\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[3,4,3,0,0,1]]", "{|<!--xb57b1mfbeh77gb9-->\n|+ style=\"color: red;\"| caption3\n|-\n| foo\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[0,0,0,1,4,3]]", "{|\n|+style=\"color: red;\"|caption2\n|+ style=\"color: red;\" data-foobar=\"4n9ju8e6u4ayk3xr\" | caption3<!--8vitqxcwje89f6r-->\n|}"); add("selser", "A table with captions with non-default spaced attributes and a table row [[0,0,2,[3],3,[[0,4],0]]]", "{|\n|+style=\"color: red;\"|caption2<!--4865t93rr418aor-->\n|+ style=\"color: red;\" |\n|-\n|n2z1139bdvuc8fr\n|}"); -- To view, visit https://gerrit.wikimedia.org/r/303709 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I577799ad7eb6bbad6a688ba431143fcbefd4bb42 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits