-
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
Block parsing and serialization/deserialization #391
Comments
It's a good idea to compare these "requirements" with the current parsing/serialization approach.
We have the
For now, there's not fallback to "freeform" block if the extracted
Wether the internal parsing is done in a single or two steps is not an issue for me. What we really need is a Now we have this
For now, the serialization happens in a separate method called
Why is this an issue, this could be a good way to update the "legacy" posts iteratively but anyway, doesn't seem too hard to do. I see where you're trying to go with this. Instead of having our current Anyway, I'd be curious if you have any technical idea on how to do this. |
I've been looking into some options over the past few days... I am starting to agree with you that we may have multiple steps internally (one to split the post content into blocks, and another to parse/validate the blocks' content). However I still think it's pretty important to present a one-step API to parse a list of blocks from a
Yes, basically. The largest issue I see with our current structure is the For example, an Also, the We could address these kinds of issues separately, but I think a much better solution is adding some kind of schema for acceptable markup.
This is still pretty fuzzy to me - it needs to be something with a pretty simple interface, that plugin developers can understand and use quickly. I think |
Migrating discussion from #426 (comment) to here, the JSX proposal was intriguing to me, particularly in how it might eliminate the need for https://gist.github.com/aduth/6f039e7da2a312a1689c4ace2a2d062c With heavy reference toward patterns prescribed by RELAX NG: http://books.xmlschemata.org/relaxng/relax-CHP-3-SECT-2.html |
I quite like this proposal, overall it's a much cleaner iteration on my initial thoughts. The main drawback I see is that we no longer have the <Element>
<Choice as="tagName" required>
<Name>h1</Name>
<Name>h2</Name>
<Name>h3</Name>
<Name>h4</Name>
</Choice>
<Attribute name="style">
<Match
pattern="\btext-align:\s*([^;]+)"
index="1"
as="align"
default="left" />
</Attribute>
<Text as="content" />
</Element> This One other thing I didn't see addressed was how to grab an entire tag and its descendant tree as HTML/object content. What about |
The book (which is a fantastic resource) has another example of the choice pattern: http://books.xmlschemata.org/relaxng/relax-CHP-6-SECT-3.html Applied to our case, this might be the way to handle an optional <Choice>
<Element name="img">
<Attribute name="src" as="url" required />
<Attribute name="alt" as="alt" />
</Element>
<Element name="figure">
<Element name="img">
<Attribute name="src" as="url" required />
<Attribute name="alt" as="alt" />
</Element>
<Optional>
<Element name="figcaption">
<Text as="caption" />
</Element>
</Optional>
</Element>
</Choice> (Optionally considering a parallel to |
Related project: https://github.com/mangalam-research/salve |
Which milestone would you assign this and the related ticket to? Beta? |
That works for now, though this ticket will touch on a lot of things and we might have to move it later. |
Brain-dump, specifically on the topic of extracting values from markup: At this time there's a bit of a fork in the road with #892 and #914. I find myself looking back at #892 and trying to feel my way through source matching once more. Issues with our current iteration are enumerated in #865. The ideas explored in #892 as an alternative may not really put us in much better a position except in clarifying intent and separating us further from the DOM. Verbose selectors like ESLint recently released an AST selectors feature, which I find to be interesting, specifically in how they apply CSS-like selectors to an AST. In their case it's the parsed JavaScript AST, but I think we'd be equally in a position to apply it to one of parsed blocks, like the structure explored in @dmsnell's wp-post-grammar. I think there's an appeal in how it could allow very concise selection while remaining unbound to a DOM, e.g. There's still the distinction between source matching and It might come down to deciding just how much flexibility we want to allow in Some use-cases like the one described in #914 (comment) could surface some unexpected consequences of adopting an expressive structure; unexpected in the sense that it appears foreign to see descendants of an |
Something like this would go part of the way towards solving my concern that we are not doing enough to validate the markup that appears inside of blocks. (To me this is still the most appealing aspect of #914). It looks like this wouldn't handle extra tags entirely though (
There are other ways around this. For example: allow specifying multiple schemas, one of which is the "canonical" version that is always used to save a block after it is modified. Avoiding something like |
Closing; this discussion has served its purpose and further tasks should be split out into separate, smaller issues. |
I think we need an improved design for block parsing and serialization/deserialization. This can be thought of as a follow-up / companion issue to #390 which discusses data storage.
I think this is an important set of technical decisions to get right before people start building plugins on top of our new structure. Here is the way I would like to see this work:
figure
andfigcaption
elements that point to WP images, probably usingdata-
attributes to describe things like image IDs.There is a lot to flesh out here, and a lot to be done, but I think that in the long run we will be much better served by providing standard and robust ways for blocks to parse their content now.
The text was updated successfully, but these errors were encountered: