-
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: Use an HTML like attribute syntax for comment attributes #626
Conversation
Can you elaborate on what specific benefits you see to these changes If there were one pain point I'd like to see solved, it would be being able to make some distinctions on types, specifically numbers. |
blocks/api/test/parser.js
Outdated
@@ -150,7 +150,7 @@ describe( 'block parser', () => { | |||
} ); | |||
|
|||
const parsed = parse( | |||
'<!-- wp:core/test-block smoked:yes -->' + | |||
'<!-- wp:core/test-block smoked="yes" url="http://google.com" -->' + |
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.
What does this new url
attribute add? Let's have a test for spaces and some special characters like '&
instead.
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.
Yes, handling spaces and special chars like these is one of the reasons I made this switch
I'd recommend looking back at wp-post-grammar where I've replaced the colon-separated attributes with HTML like attributes for an implementation that can handle different quote styles |
blocks/api/parser.js
Outdated
@@ -221,4 +221,4 @@ export function parseWithGrammar( content ) { | |||
}, [] ); | |||
} | |||
|
|||
export default parseWithTinyMCE; | |||
export default parseWithGrammar; |
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.
Shouldn't matter either way, but is this change intentional?
Separately, it might be nice to run the CI build against both parsers.
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.
Not intentional, I was switching to try both.
Here are a couple of benefits of moving to HTML-like attribute syntax:
I think this is reasonable as an incremental improvement that will allow us to implement the embed block with cleaner serialized markup. |
Yes, storing spaces, tabs ... inside args and remove the ambiguity between the ':' of the name, value separation and any ':' in the attribute value (urls).
Yes, this is another pain point to be solved but I think your idea in #609 is a great solution for this. |
Updated, I've used the proposed grammar by @dmsnell. It's way better. |
6749051
to
6331eb3
Compare
Latest changes look good, nice work on testing both parsers at the same time. Another potential benefit of HTML-like attribute syntax is that we are intentionally limiting the data types of attributes (currently, to either strings or pseudo-boolean values). If we do allow storing arbitrary data structures it seems like this could quickly get out of hand. |
It appears we overlooked updating the serializer here: https://github.com/WordPress/gutenberg/blob/1cb599d/blocks/api/serializer.js#L62 You can see some breakage when switching to and from the Text mode (Edit: Appears you have to make a change in Text mode before switching back to Visual). |
What do y'all feel about not pulling in the boolean flag syntax for HTML attributes. <item checked /> my reason for not wanting to do so is twofold:
cc: @mtias |
I'd actually overlooked that this had been introduced here. I too feel it's a bit odd to support now two types (strings, booleans) but not others (numbers). And that there'd not been a use-case driving its inclusion. |
I think HTML like attribute syntax is more solid than our current attributes syntax.