-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Framework: Use custom serializer for texturize compatibility #5897
Conversation
9e38198
to
54f81ed
Compare
@@ -60,6 +60,6 @@ <h2>This is a <em>heading</em></h2> | |||
<!-- /wp:paragraph --> | |||
|
|||
<!-- wp:image --> | |||
<figure class="wp-block-image"><img src="https://lh4.googleusercontent.com/ID" alt="" /></figure> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alt=""
is an accessibilty concern, I believe these should be kept somehow?
element/test/index.js
Outdated
|
||
expect( result ).toBe( | ||
'<a href="/index.php?foo=bar&qux=<"scary">" style="background-color:red">' + | ||
'&copy (sic) © © 2018 <"WordPress" & Friends>' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird that the closing >
is not automatically converted. I know this is not needed in the minimal requirements but how does the current editor work? Should we be consistent?
54f81ed
to
80bfcc1
Compare
From a content creator perspective, yes,
https://blog.whatwg.org/omit-alt
https://html.spec.whatwg.org/multipage/images.html#alt However, the specification does continue to describe an interpretation of
https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element One difference between this serializer and React's is that when an attribute is empty and not meaningful (either boolean or Alternatively, we could maintain a separate set of attributes for which the empty value implies significance, such as One of my motivations was to avoid exceptions as much as possible, except where strictly needed. |
Personally I'd prefer correctness over consistency in this case. I don't feel strongly compelled to encode where not strictly necessary, for no other reason than because it may have been done in the classic editor. |
80bfcc1
to
17b1397
Compare
Another thing I'll plan to add here: I think we can bake in support for Lines 101 to 106 in 161f3f0
|
This is looking great.
Let us know once you'd like that reviewed too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eager to see this one merged!
Nice work here! |
@lancewillett you've run into some typography related issues before, would love if you can test this (curly quotes, etc) again when it lands on 2.6. |
Left a comment after updating the plugin to 2.6.0 and confirming the expected behavior: #3353 (comment) |
Closes #3353
Previously: #4049
This pull request seeks to introduce a custom element serializer, removing dependency on
react-dom/server
(forrenderToStaticMarkup
) and improving compatibility with WordPress'wptexturize
behavior.Unlike #4049, it does not allow content to remain completely unescaped. Instead, it performs the minimal escaping as prescribed by the HTML specification:
Source: https://w3c.github.io/html/syntax.html#writing-html-documents-elements
Therefore, unlike #4049, it should not suffer from unintentional HTML on the front-end (#4049 (comment)).
This pull request also includes related improvements to block validation, allowing boolean attributes with differing values to be treated as equivalent, as a boolean attribute is effective by its mere presence, regardless of value:
It is important to note that while it it is expected to be, there is no presumption that the markup produced by this serializer must be safe. Server validation still occurs, and there is no effective difference to saving markup produced by this serializer and that added as arbitrary HTML to the classic editor's Text mode.
Unlike #4049, this does nothing to change or support additional shapes for Editable value, though it can be extended in the future to support such needs if desired.
Testing instructions:
Verify that no block invalidations occur upon saving and reloading the post. Demo content is a good place to start.
Verify that adding potentially "unsafe" characters (e.g. ampersand or less-than) to text, or other attributes (ampersand or quotes in additional class name) are properly escaped in serialized content (can verify in Code mode).