Skip to content

Commit ef6e2e8

Browse files
authored
fix: remove empty spans used by Quill from htmlValue (#6434)
1 parent dd0ae1a commit ef6e2e8

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/rich-text-editor/src/vaadin-rich-text-editor.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
935935

936936
// Remove Quill classes, e.g. ql-syntax, except for align
937937
content = content.replace(/\s*ql-(?!align)[\w-]*\s*/gu, '');
938+
// Remove meta spans, e.g. cursor which are empty after Quill classes removed
939+
content = content.replace(/<\/?span[^>]*>/gu, '');
938940

939941
// Replace Quill align classes with inline styles
940942
[this.__dir === 'rtl' ? 'left' : 'right', 'center', 'justify'].forEach((align) => {

‎packages/rich-text-editor/test/basic.test.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,15 @@ describe('rich text editor', () => {
681681
expect(rte.htmlValue).to.equal('<h3><em>Foo</em>Bar</h3>');
682682
});
683683

684+
it('should filter out empty span elements from the resulting htmlValue', () => {
685+
rte.dangerouslySetHtmlValue(
686+
'<p><strong>Hello </strong></p><p><strong><span class="ql-cursor"></span>world</strong></p>',
687+
);
688+
flushValueDebouncer();
689+
// Empty span should be stripped
690+
expect(rte.htmlValue).to.equal('<p><strong>Hello </strong></p><p><strong>world</strong></p>');
691+
});
692+
684693
it('should return the quill editor innerHTML', () => {
685694
expect(rte.htmlValue).to.equal('<p><br></p>');
686695
});

0 commit comments

Comments
 (0)