-
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
[WIP] Try: Use JSON to encode block attribute values #1088
Conversation
❤️ the idea, I feel this will make things a lot simpler on so many levels:
|
thanks @nb for the comments.
I'm not sure I agree on this
for sure. of course, simply storing JSON in the existing attributes lets us do this already
yes. 👍
I doubt this would speed up the parse because we'd be moving from native JSON parsing in the browser (really really fast) to parsing in JavaScript.
yeah I think so, through I don't see escaping as a big deal. there should be almost no exceptions on escaping that I can think of (single and double quote characters) so I'm not sure this is a big advantage here. more so it brings some new challenges because while JSON and POJOs (plain-old JavaScript objects) are similar, JSON has more constraints and we'd need to make sure we carefully consider which specifications we want to implement. thanks! |
Almost :)
Adds another branch – you know the long-term effect on logic branching, especially at such a higher level.
This is one of the strongest points for me – parsing consistency (in |
Proposed by @nb maybe online somewhere or maybe in person… <!-- wp:core/text {
description: "content is a valid JSON object or POJO"
terms: {
POJO: "Plain-old-javascript object. Like JSON but with fewer double-quotes"
}
} -->
Just some content
<!-- /wp:core/text --> It would be nice to know what kind of "gotcha"s we might encounter doing unserialized JSON/JS in the HTML comment. Further, should we include @westonruter's import of the JSON grammar? (at first I thought probably not, but now that we're discussing actual unescaped JSON I could easily see it being valuable)
|
SpecThe HTML spec on comments is pretty quick to read:
I'll attempt to TL;DR:
Here's an example HTML to highlight problematic comments which can be pasted into a validator: <!doctype html>
<html>
<head><title>Title</title></head>
<body>
<!-- VALID -->
<!--
<Everything/> else is -\- `{ fair: "game" }`.
Starting and ending with fixed character such as " " is a good practice.
The remaining problem is two sequential "-" characters.
-->
<!--> INVALID -->
<!---> INVALID -->
<!-- INVALID -- -->
<!-- INVALID --->
</body>
</html> SuggestionsThe peculiarities of opening and closing sequences are easily mitigated by opening comments with something static, this appears to be either That means the only invalid sequence that concerns us is A few proposals to consider are:
"--" === "-\-" // true
"--" === "\u002D\u002D" // true |
@sirreal thanks so much for finding and summarizing the spec. looks to me like replacing the hyphens with the Unicode literal would be best. we could run into other troubles with strings of dashes, like though I would propose we use |
@nb after talking with you and fighting your very good challenges, we arrived on this transform… const serializeAttrs = attrs => JSON.stringify( attrs )
.replace( /--/g, '\\u002d\\u002d' ) // don't break HTML comments
.replace( /</g, '\\u003c' ) // don't break standard-non-compliant tools
.replace( />/g, '\\u003e' ) // ibid
.replace( /&/g, '\\u0026' ) // ibid |
❤️ And |
@nb check out #1213 where I have implemented this idea
yep, though it happens in the parser and the app need not change it. this was a choice I made because I didn't want the parser to produce an output which needed further processes sing to be a basic reasonable output |
Closing in favor of #1213. Love the outcome here guys. 👍 |
Depends on #1087, among many other things, including a PHP parser generator for the PEG.js grammar to be utilized in the
do_blocks
PHP function.Fixes #1086.