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

automatic conversion of html entities after reloading the page in the editor #15792

Open
GitHub-Mike opened this issue May 23, 2019 · 3 comments
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended

Comments

@GitHub-Mike
Copy link

The used html entities (curly braces) are automatically converted to "normal" characters after reloading the page in the editor.
Tested in code and paragraph block.

  1. Go to 'hello world'
  2. Click on 'edit'
  3. insert '&#123text&tinymce-single: add toolbar styles from main prototype #125' (code or visual view)
  4. save changes
  5. view page
  6. edit page
  7. new text is: '{text}'

No automatic conversion of html entities after opening or editing the content in the editor.

A solution via a filter hook would certainly be useful and could cause an optional global deactivation of the conversion.

  • WIN10
  • Chrome
  • 74.0.3729.169
  • WordPress 5.2.1–de_DE
@gziolo gziolo added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Rich text /packages/rich-text Needs Technical Feedback Needs testing from a developer perspective. labels May 23, 2019
@draganescu draganescu added [Type] Bug An existing feature does not function as intended and removed Needs Technical Feedback Needs testing from a developer perspective. labels Jun 13, 2019
@draganescu
Copy link
Contributor

draganescu commented Jun 13, 2019

Hi @GitHub-Mike,

This looks like an inconsistent behaviour:

  • pasting {text{ in visual or text mode replaces HTML entities on blur or on save + reload, but not on save alone, causing bad UX
  • pasting an incorrect {text&#123 (no semicolon at the end) replaces the 1st HTML entity and when correcting the second one it doesn't get replaced.

We need to see if it is possible to not replace HTML entities at all or at least if we do to do it consistently.

Note: the classic editor is even more unpredictable, pasting &#123text&#125 results in {}, the word text is gone and it converts the entities even though they are malformed (missing semicolon).

@GitHub-Mike
Copy link
Author

GitHub-Mike commented Jun 13, 2019

Hi @draganescu,

The semicolon was only forgotten when creating this post, but not in the code of the editor! (I should have formatted it as code here, otherwise the curly braces will be converted here as well)

Yes, the conversion happens by the way when switching from the text to the visual view.

It would be nice if there would be a way to disable the automatic conversion completely.

Later you could restrict this to certain entities.

@youknowriad
Copy link
Contributor

The main reason here is that when parsing a block that relies on html sourced attributes, hpq (our parser library) uses element.innerHTML to extract the HTML from the block attribute (inserting the HTML into a random element and extracting the bits we need), browsers though automatically convert HTML entities in their DOM APIs.

So a potential solution would be to avoid using the browser APIs to parse the block attributes, but I don't know exactly if there's an alternative there that doesn't involve writing a custom HTML parser (which sounds too heavy for the issue at hand both in terms of maintainability and performance).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants