Skip to content

Commit

Permalink
refactor: support atypical whitespace in rte html value tags (#6661)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Oct 17, 2023
1 parent fc54a1d commit 4dcc890
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ export const RichTextEditorMixin = (superClass) =>
};
// Replace whitespace characters with placeholders before the Delta conversion to prevent Quill from trimming them
Object.entries(whitespaceCharacters).forEach(([character, replacement]) => {
htmlValue = htmlValue.replaceAll(character, replacement);
htmlValue = htmlValue.replaceAll(/>[^<]*</gu, (match) => match.replaceAll(character, replacement)); // NOSONAR
});

const deltaFromHtml = this._editor.clipboard.convert(htmlValue);
Expand Down
14 changes: 14 additions & 0 deletions packages/rich-text-editor/test/basic.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,20 @@ describe('rich text editor', () => {
expect(rte.htmlValue).to.equal(htmlWithCodeBlock);
});

it('should support double spaces inside html tags', () => {
const htmlWithCodeBlock = `<pre spellcheck="false">code\n</pre>`;
rte.dangerouslySetHtmlValue(htmlWithCodeBlock);
flushValueDebouncer();
expect(rte.htmlValue).to.equal(`<pre spellcheck="false">code\n</pre>`);
});

it('should support tabs inside html tags', () => {
const htmlWithCodeBlock = `<pre\tspellcheck="false">code\n</pre>`;
rte.dangerouslySetHtmlValue(htmlWithCodeBlock);
flushValueDebouncer();
expect(rte.htmlValue).to.equal(`<pre spellcheck="false">code\n</pre>`);
});

it('should return the quill editor innerHTML', () => {
expect(rte.htmlValue).to.equal('<p><br></p>');
});
Expand Down

0 comments on commit 4dcc890

Please sign in to comment.