jenkins-bot has submitted this change and it was merged. Change subject: T149209: Deal with newlines in <td> and <th> cells ......................................................................
T149209: Deal with newlines in <td> and <th> cells * Ensures that both non-selser and selser code is functional. * New tests added for both selser and non-selser modes. * T151911 deals with a bad parse of table cells which has a bearing on the fix in this patch. When T151911 is fixed, the code in this patch will need to be updated. Change-Id: Ifc0b75b9ad6cb367afbd95ffa403d645b593deab --- M HISTORY.md M lib/html2wt/DOMHandlers.js M lib/html2wt/WTSUtils.js M tests/parserTests.txt 4 files changed, 118 insertions(+), 7 deletions(-) Approvals: Arlolra: Looks good to me, approved jenkins-bot: Verified diff --git a/HISTORY.md b/HISTORY.md index 4f5bf8b..e9a9bac 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ * T110910: Implement <gallery> extension natively inside Parsoid * T150213: Suppress logs for known unknown contentmodels + * T149209: Handle newlines in <td> and <th> cells 0.6.1 / 2016-11-14 ================== diff --git a/lib/html2wt/DOMHandlers.js b/lib/html2wt/DOMHandlers.js index 68cb26a..12c251c 100644 --- a/lib/html2wt/DOMHandlers.js +++ b/lib/html2wt/DOMHandlers.js @@ -749,13 +749,25 @@ handle: Promise.method(function(node, state, wrapperUnmodified) { var dp = DU.getDataParsoid(node); var usableDP = stxInfoValidForTableCell(state, node); + var attrSepSrc = usableDP ? (dp.attrSepSrc || null) : null; var startTagSrc = usableDP ? dp.startTagSrc : ''; - var attrSepSrc = usableDP ? dp.attrSepSrc : null; - var src = (usableDP && dp.stx_v === 'row') ? '!!' : '!'; + if (!startTagSrc) { + startTagSrc = (usableDP && dp.stx_v === 'row') ? '!!' : '!'; + } + + // T149209: Special case to deal with scenarios + // where the previous sibling put us in a SOL state + // (or will put in a SOL state when the separator is emitted) + if (state.onSOL || state.sep.constraints.min > 0) { + // You can use both "!!" and "||" for same-row headings (ugh!) + startTagSrc = startTagSrc.replace(/!!/, '!') + .replace(/\|\|/, '!') + .replace(/{{!}}{{!}}/, '{{!}}'); + } // If the HTML for the first th is not enclosed in a tr-tag, // we start a new line. If not, tr will have taken care of it. - return serializeTableTag(startTagSrc || src, attrSepSrc || null, + return serializeTableTag(startTagSrc, attrSepSrc, state, node, wrapperUnmodified).then(function(tableTag) { WTSUtils.emitStartTag(tableTag, node, state); var thHandler = state.serializer.wteHandlers.thHandler @@ -787,13 +799,23 @@ handle: Promise.method(function(node, state, wrapperUnmodified) { var dp = DU.getDataParsoid(node); var usableDP = stxInfoValidForTableCell(state, node); + var attrSepSrc = usableDP ? (dp.attrSepSrc || null) : null; var startTagSrc = usableDP ? dp.startTagSrc : ''; - var attrSepSrc = usableDP ? dp.attrSepSrc : null; - var src = (usableDP && dp.stx_v === 'row') ? '||' : '|'; + if (!startTagSrc) { + startTagSrc = (usableDP && dp.stx_v === 'row') ? '||' : '|'; + } + + // T149209: Special case to deal with scenarios + // where the previous sibling put us in a SOL state + // (or will put in a SOL state when the separator is emitted) + if (state.onSOL || state.sep.constraints.min > 0) { + startTagSrc = startTagSrc.replace(/\|\|/, '|') + .replace(/{{!}}{{!}}/, '{{!}}'); + } // If the HTML for the first td is not enclosed in a tr-tag, // we start a new line. If not, tr will have taken care of it. - return serializeTableTag(startTagSrc || src, attrSepSrc || null, + return serializeTableTag(startTagSrc, attrSepSrc, state, node, wrapperUnmodified).then(function(tableTag) { var inWideTD = (tableTag.length > 1); WTSUtils.emitStartTag(tableTag, node, state); diff --git a/lib/html2wt/WTSUtils.js b/lib/html2wt/WTSUtils.js index ba8b0e3..186c695 100644 --- a/lib/html2wt/WTSUtils.js +++ b/lib/html2wt/WTSUtils.js @@ -81,7 +81,8 @@ // If previous sibling is unmodified, nothing to worry about. if (!DU.isMarkerMeta(prev, "mw:DiffMarker") && - !DU.hasInsertedDiffMark(prev, env)) { + !DU.hasInsertedDiffMark(prev, env) && + !DU.directChildrenChanged(prev, env)) { return true; } diff --git a/tests/parserTests.txt b/tests/parserTests.txt index 26d0540..f9755c6 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -26553,6 +26553,93 @@ !! end !! test +T149209: WTS: Handle newlines in table cells properly +!! options +parsoid=html2wt +!! html/parsoid +<table> +<tbody> +<tr><td>a +b +</td><td data-parsoid='{"stx_v":"row"}'>c</td></tr> +<tr><td><p>x</p> +</td><td data-parsoid='{"stx_v":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr> +</tbody></table> +<table> +<tbody> +<tr><th>a +b +</th><th data-parsoid='{"stx_v":"row"}'>c</th></tr> +<tr><th><p>x</h> +</th><th data-parsoid='{"stx_v":"row"}'>y</th></tr> +</tbody></table> +!! wikitext +{| +|a +b +|c +|- +|x +{{!}}y +|} +{| +!a +b +!c +|- +!x +!y +|} +!! end + +!! test +T149209: Selser: Handle newlines in table cells properly +!! options +parsoid={ + "modes": ["selser"], + "changes": [ + [ "#h1", "html", "a\nb\n" ], + [ "#h2", "html", "a\nb\n" ], + [ "#c1", "html", "a\nb\n" ], + [ "#c2", "html", "<p>a</p>" ], + [ "#c3", "html", "<p>a</p>" ] + ] +} +!! wikitext +{| +! id="h1" |edit-me!!1 +|- +! id="h2" |edit-me||2 +|- +| id="c1" |edit-me||3 +|- +| id="c2" |edit-me||4 +|- +| id="c3" |edit-me||p||q||r +|} +!! wikitext/edited +{| +! id="h1" |a +b +!1 +|- +! id="h2" |a +b +!2 +|- +| id="c1" |a +b +|3 +|- +| id="c2" |a +|4 +|- +| id="c3" |a +|p||q||r +|} +!! end + +!! test HTML id attribute with Parsoid-like element ids should not be serialized to wikitext !! options parsoid=html2wt -- To view, visit https://gerrit.wikimedia.org/r/322955 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifc0b75b9ad6cb367afbd95ffa403d645b593deab Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: C. Scott Ananian <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