Table with no headings gets corrupted when editing (#13293)

* fix data loss issue when modifying table with no headings

* fix comment

* Add tests and extra empty space to empty header format
This commit is contained in:
Barbara Valdez
2020-11-09 09:42:42 -08:00
committed by GitHub
parent fa9a38d74a
commit 3f76d343a5
2 changed files with 26 additions and 2 deletions

View File

@@ -95,10 +95,19 @@ rules['table'] = {
filter: function (node) {
return node.nodeName === 'TABLE' && isHeadingRow(node.rows[0]);
},
replacement: function (content) {
replacement: function (content, node) {
// Ensure there are no blank lines
content = content.replace('\n\n', '\n');
// if the headings are empty, add border line and headings to keep table format
if (node.tHead.innerText === '') {
let emptyHeader = '\n\n|';
let border = '\n|';
for (let i = 0; i < node.rows[0].childNodes.length; i++) {
emptyHeader += ' |';
border += ' --- |'
}
return emptyHeader + border + content + '\n\n';
}
return '\n\n' + content + '\n\n';
}
};