From 1de05a2339317d658cf127037abeb7a113814b58 Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Fri, 28 May 2021 13:47:50 -0700 Subject: [PATCH] Fix WYWIWYG Table cell adding new line in table cell (#15594) * fixes new line in table cell * add test and fix for table head --- .../contrib/notebook/browser/htmlMarkdownConverter.ts | 4 ++++ .../notebook/test/browser/htmlMarkdownConverter.test.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/sql/workbench/contrib/notebook/browser/htmlMarkdownConverter.ts b/src/sql/workbench/contrib/notebook/browser/htmlMarkdownConverter.ts index 84817196b2..35530f0ae1 100644 --- a/src/sql/workbench/contrib/notebook/browser/htmlMarkdownConverter.ts +++ b/src/sql/workbench/contrib/notebook/browser/htmlMarkdownConverter.ts @@ -176,6 +176,10 @@ export class HTMLMarkdownConverter { replacement: function (content, node, options) { // For elements that aren't lists, convert
into its markdown equivalent if (node.parentElement?.nodeName !== 'LI') { + // Keeps
in table cell/head in order to keep new linehow + if (node.parentElement?.nodeName === 'TD' || node.parentElement?.nodeName === 'TH') { + return '
'; + } return options.br + '\n'; } // One (and only one) line break is ignored when it's inside of a list item diff --git a/src/sql/workbench/contrib/notebook/test/browser/htmlMarkdownConverter.test.ts b/src/sql/workbench/contrib/notebook/test/browser/htmlMarkdownConverter.test.ts index 076a790c95..537b99a718 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/htmlMarkdownConverter.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/htmlMarkdownConverter.test.ts @@ -260,6 +260,13 @@ suite('HTML Markdown Converter', function (): void { assert.equal(htmlMarkdownConverter.convert(htmlString), `| Test | Test | Test |\n| :-: | --- | --- |\n| test | test | test |\n| test | test | test |\n| test | test | test |\n| test | test | test |`, 'Table with center align column header failed'); }); + test('Should transform table to keep
for new line in table head and cell', () => { + htmlString = '\n\n\n\n\n\n\n\n\n\n\n\n\n
testtest
test
\n'; + assert.equal(htmlMarkdownConverter.convert(htmlString), `| | | |\n| --- | --- | --- |\n| test | test
test | |`, 'Table with new line in cell failed'); + htmlString = '\n\n\n\n\n\n\n\n\n\n\n\n\n
TEST
TEST
TESTTEST
testtesttest
\n'; + assert.equal(htmlMarkdownConverter.convert(htmlString), `| TEST
TEST | TEST | TEST |\n| --- | --- | --- |\n| test | test | test |`, 'Table with new line in table head failed'); + }); + test('Should transform and tags', () => { htmlString = 'test string'; assert.equal(htmlMarkdownConverter.convert(htmlString), '**test string**', 'Basic bold test failed');