Fix WYWIWYG Table cell adding new line in table cell (#15594)

* fixes new line in table cell

* add test and fix for table head
This commit is contained in:
Vasu Bhog
2021-05-28 13:47:50 -07:00
committed by GitHub
parent c6fec97819
commit 1de05a2339
2 changed files with 11 additions and 0 deletions

View File

@@ -176,6 +176,10 @@ export class HTMLMarkdownConverter {
replacement: function (content, node, options) {
// For elements that aren't lists, convert <br> into its markdown equivalent
if (node.parentElement?.nodeName !== 'LI') {
// Keeps <br> in table cell/head in order to keep new linehow
if (node.parentElement?.nodeName === 'TD' || node.parentElement?.nodeName === 'TH') {
return '<br>';
}
return options.br + '\n';
}
// One (and only one) line break is ignored when it's inside of a list item

View File

@@ -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 <br> for new line in table head and cell', () => {
htmlString = '<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody><tr>\n<td>test</td>\n<td>test<br>test</td>\n<td></td>\n</tr>\n</tbody></table>\n';
assert.equal(htmlMarkdownConverter.convert(htmlString), `| | | |\n| --- | --- | --- |\n| test | test<br>test | |`, 'Table with new line in cell failed');
htmlString = '<table>\n<thead>\n<tr>\n<th>TEST<br>TEST</th>\n<th>TEST</th>\n<th>TEST</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>test</td>\n<td>test</td>\n<td>test</td>\n</tr>\n</tbody></table>\n';
assert.equal(htmlMarkdownConverter.convert(htmlString), `| TEST<br>TEST | TEST | TEST |\n| --- | --- | --- |\n| test | test | test |`, 'Table with new line in table head failed');
});
test('Should transform <b> and <strong> tags', () => {
htmlString = '<b>test string</b>';
assert.equal(htmlMarkdownConverter.convert(htmlString), '**test string**', 'Basic bold test failed');