Subramanya Sastry has uploaded a new change for review. https://gerrit.wikimedia.org/r/291530
Change subject: T134139: Serialize content in HTML tables using HTML tags ...................................................................... T134139: Serialize content in HTML tables using HTML tags * Mixing HTML and wikitext tags will just result in a mess. * Added new parser tests that pass with this patch and fail without this patch. * TODO: Generalize this strategy to handle lists. Change-Id: I2b760a06d1c68cc10e07a9c75ff190aec0077676 --- M lib/html2wt/WikitextSerializer.js M lib/utils/DOMUtils.js M tests/parserTests.txt 3 files changed, 51 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/30/291530/1 diff --git a/lib/html2wt/WikitextSerializer.js b/lib/html2wt/WikitextSerializer.js index a63de6a..176c086 100644 --- a/lib/html2wt/WikitextSerializer.js +++ b/lib/html2wt/WikitextSerializer.js @@ -710,6 +710,12 @@ // for html-stx tags. But, <a> tags should never serialize as HTML. if (!handler && dp.stx === 'html' && nodeName !== 'a') { return htmlElementHandler; + } else if (DU.isTableTag(node) && DU.inHTMLTableTag(node)) { + // FIXME: This strategy is probably applicable more broadly + // (ex: list items in lists, etc.) + // If in a HTML table tag, serialize table tags in the table + // using HTML tags, instead of native wikitext tags + return htmlElementHandler; } // If parent node is a list or table tag in html-syntax, then serialize diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js index 346c0be..c1fe881 100644 --- a/lib/utils/DOMUtils.js +++ b/lib/utils/DOMUtils.js @@ -2195,6 +2195,21 @@ return text.replace(/<(\/?nowiki\s*\/?\s*)>/gi, '<$1>'); }, + isTableTag: function(node) { + return Consts.HTML.TableTags.has(node.nodeName); + }, + + inHTMLTableTag: function(node) { + var p = node.parentNode; + while (this.isTableTag(p)) { + if (this.isLiteralHTMLNode(p)) { + return true; + } + p = p.parentNode; + } + + return false; + }, }; /** diff --git a/tests/parserTests.txt b/tests/parserTests.txt index b6a857a..615f1c9 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -7182,6 +7182,36 @@ |} !! end +!! test +Serialize new table rows in a HTML table using HTML tags +!! options +parsoid={ + "modes": ["wt2wt", "selser"], + "changes": [ + [ "tr", "before", "<tr><td>X</td></tr>" ] + ] +} +!! wikitext +<table><tr><td>a</td></tr></table> +!! wikitext/edited +<table><tbody><tr><td>X</td></tr><tr><td>a</td></tr></tbody></table> +!! end + +!! test +Serialize new table cells in a HTML row using HTML tags +!! options +parsoid={ + "modes": ["wt2wt", "selser"], + "changes": [ + [ "td", "before", "<td>X</td>" ] + ] +} +!! wikitext +<table><tr><td>a</td></tr></table> +!! wikitext/edited +<table><tbody><tr><td>X</td><td>a</td></tr></tbody></table> +!! end + ### ### Internal links ### -- To view, visit https://gerrit.wikimedia.org/r/291530 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2b760a06d1c68cc10e07a9c75ff190aec0077676 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits