Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table optimization after new line inserted #35

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ function convertHTML(blot, index, length, isRoot = false) {
return parts.join('');
}

handleTableBlots(blot);
const domNode = extractNodeFromBlot(blot);

const { outerHTML, innerHTML } = blot.domNode;
const { outerHTML, innerHTML } = domNode;
const [start, end] = outerHTML.split(`>${innerHTML}<`);
if (start.indexOf('<table') === 0) {
return `${start.replace(/(\sdata-.+?=["'].*?["'])/g, '')}>${parts
Expand All @@ -338,16 +338,25 @@ function handleBreakLine(linkedList, parts) {
}
}

function handleTableBlots(blot) {
function extractNodeFromBlot(blot) {
const domNode = blot.domNode.cloneNode(true);

return removeTableServiceClasses(blot, domNode);
}

function removeTableServiceClasses(blot, domNode) {
const BLOTS_WITH_SERVICE_CLASS = [
'tableCellLine',
'tableHeaderCellLine',
'tableCell',
'tableHeaderCell',
];
if (BLOTS_WITH_SERVICE_CLASS.indexOf(blot.statics.blotName) > -1) {
removeClass(blot.domNode, blot.statics.className);

if (BLOTS_WITH_SERVICE_CLASS.includes(blot.statics.blotName)) {
removeClass(domNode, blot.statics.className);
}

return domNode;
}

function combineFormats(formats, combined) {
Expand Down
27 changes: 27 additions & 0 deletions test/unit/modules/table_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,33 @@ describe('Table Module', function() {
true,
);
});

it('insertText inside after getSemanticHtml', function() {
this.quill.getSemanticHTML(0, this.quill.getLength() + 1);
this.quill.insertText(8, '\n');
expect(this.quill.root).toEqualHTML(
`
<table>
<tbody>
<tr>
<td><p>a1</p></td>
<td><p>a2</p></td>
<td>
<p>a3</p>
<p><br></p>
</td>
</tr>
<tr>
<td><p>b1</p></td>
<td><p>b2</p></td>
<td><p>b3</p></td>
</tr>
</tbody>
</table>
`,
true,
);
});
});

describe('customize table', function() {
Expand Down