Skip to content

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

Merged
tomivirkki merged 3 commits into
mainfrom
refactor/rte/whitespace-in-tags
Oct 17, 2023
Merged

tomivirkki merged 3 commits into
mainfrom
refactor/rte/whitespace-in-tags

Conversation

@tomivirkki

Copy link
Copy Markdown
Member

Description

One more improvement to the <vaadin-rich-text-editor> HTML -> Delta conversion whitespace handling.

This PR updates the logic to only match content outside HTML tags.

This is to allow unconventional, but still legal white space inside the HTML tags, for example (double-space between the tag name and the attribute):

<pre  spellcheck="false">code\n</pre>

Type of change

Bugfix

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

// 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
Copy Markdown
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

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.3.0.alpha1 and is also targeting the upcoming stable 24.3.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants