-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Parser: Store attributes in unescaped JSON format #1213
Conversation
const o = {}; | ||
o[ key ] = untransformValue( value ); | ||
return o; | ||
function maybeJSON( s ) { |
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.
Can we report an error somehow?
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.
right now the error is reported as a null
value. many things, including the string null
is valid JSON. in that sense, I would like to propose that we only accept JSON objects, which would dramatically simplify the parser and semantics and serializer.
that would mean null
can also signify an error, or alternatively, on error we could send the string of the content which failed to parse.
Looks good, but it will break everything. Can we keep the old parser for a bit and use it as a fallback? On first save the format will be converted by the new serializer. |
thought this was why we are working on the prototype… 😉 |
Beware. I'm rebasing this now to remove the merge commit. |
@dmsnell now that the plugin was just released on WordPress.org, the back-compat for attributes probably should be added. |
0b00150
to
b6411b0
Compare
Rebased. Former |
lib/blocks.php
Outdated
@@ -102,7 +103,7 @@ function do_blocks( $content ) { | |||
global $wp_registered_blocks; | |||
|
|||
// Extract the blocks from the post content. | |||
$matcher = '/<!--\s*wp:([a-z](?:[a-z0-9\/]+)*)\s+((?:(?!-->).)*)\s*\/?-->(?:.*?<!--\s*\/wp:\g1\s+-->)?/'; | |||
$matcher = '/<!--\s*wp:([a-z](?:[a-z0-9\/]+)*)\s+((?:(?!-->).)*?)\s*\/?-->(?:.*?<!--\s*\/wp:\g1\s+-->)?/'; |
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.
we need to be extremely careful with combining wildcards. those +)*
are troublesome, and I don't see why we are introducing *?
- was it not working without the ?
? @westonruter
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.
@dmsnell The reason for this is the matches for a block like <!-- wp:core/latestposts {"poststoshow":3} /-->
. Given that example, without the change on this line it was resulting in a match like {"poststoshow":3} /
, which naturally is invalid JSON. So I was debating whether to rtrim
the /
or to make the pattern matching non-greedy. I decided on the latter, but you think the former is better then I'm happy to change.
@nb @jasmussen and @westonruter - I'm a bit mixed on "this will break things" don't we want to block all new usages of named attributes? should we really be providing a fallback to protect usage of the alpha release? |
Break it while we still can. I think the JSON pattern is a lot nicer. |
b6411b0
to
cf056f6
Compare
Rebased again. Former Build has been fixed. Tests have been updated. I'd like to get this merged so we can move forward with dynamic blocks. |
Yes, let's break the current blocks and release a plugin update quickly. |
I think we should do this but I am a bit mixed on the breakage as well. I am happy to let someone else make the call here, I will just note that it shouldn't be too difficult to insert a temporary hack to convert string attributes to the new format. |
I can understand the empathy for breakage, but we can't let the fact that we released the plugin into the repository hold us from making these necessary improvements, or even moving fast. This breakage should be expected under the beta moniker, and we even have an alert box on the publish button that warns that this a beta plugin. We need to stay nimble, and not worry too much about breakage, especially in this phase, or we might get mired in additional challenges. |
I'll remove my back-compat PHP parsing and rebase. |
79f3684
to
0004aaf
Compare
Rebased. Former |
'<p>The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of <em>pieces of content</em>—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you\'ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.</p>', | ||
'<!-- /wp:core/text -->', | ||
|
||
'<!-- wp:core/text -->', | ||
'<p>What you are reading now is a <strong>text block</strong>, the most basic block of all. The text block has its own controls to be moved freely around the post...</p>', | ||
'<!-- /wp:core/text -->', | ||
|
||
'<!-- wp:core/text align="right" -->', | ||
'<!-- wp:core/text { "align": "right" } -->', |
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.
Since default serialization wouldn't include whitespace between braces and after colon, should we similarly not do so here?
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.
Since the post-content.js
here is written by hand, it seems useful to have more spaces for readability when editing.
bc9ee22
to
5d5c07a
Compare
Rebased to fix merge conflict. Former |
5d5c07a
to
4dd0f22
Compare
Resolving conflicts and re-basing again… |
bdf86f0
to
f5900f6
Compare
Previously we borrowed the `name="value"` format of tag attributes from HTML. This caused some headache with blocks because of the different ways we are wanting to save data in the block comment headers, not the least of which reason is due to how data must or need not be escaped. In this change we overhaul the format of the data to allow for (mostly) unescaped JSON data in the block comment headers. Minimal escaping exists to prevent breaking the HTML comment and to prevent poorly-implemented tools from messing up the comments as well.
f5900f6
to
f63bbca
Compare
@see #1088
Previously we borrowed the
name="value"
format of tag attributes fromHTML. This caused some headache with blocks because of the different
ways we are wanting to save data in the block comment headers, not the
least of which reason is due to how data must or need not be escaped.
In this change we overhaul the format of the data to allow for (mostly)
unescaped JSON data in the block comment headers. Minimal escaping
exists to prevent breaking the HTML comment and to prevent
poorly-implemented tools from messing up the comments as well.