Skip to content

refactor: support atypical whitespace in rte html value tags #6661

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

Merged
merged 3 commits into from
Oct 17, 2023
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
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex matches content only (tags are ignored):

Screenshot 2023-10-17 at 16 10 04

});

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