-
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
Two Types of Blocks for Better User and Developer Experience #371
Comments
You just described what the existing editor already does:
|
@joyously is this good or bad? :) |
Related: #104
How does this differ from
I too struggled with these extremes (#104 (comment)) reflected in your conclusion as the contrast between simple and advanced blocks. I'd taken aim at more of singular approach, first akin to your advanced block (HTML as a cache) and later toward leveraging markup after concerns were raised about syncing, data duplication, and revisioning post meta. Addressing the quoted text specifically, I eventually landed at what I think is a comfortable parsing approach in the hpq utility, which I find scales well to even complex markup. Here's the parse of the current top Hacker News articles: Demo: https://aduth.github.io/hpq/
I wouldn't go so far as to call gallery a simple example. 😄 When markup is complex enough that it can't easily be parsed, such as a gallery column count, I think it's entirely reasonable to mix hints into the attributes. We're running with this idea in #348, in that by treating render-time attributes as a bucket and diffing against parsed attributes, we can find the subset of "extra" attributes that need to be encoded (as of now into the comment syntax).
How did you arrive at this number?
What's a good example of a simple block, and what do you imagine the |
Instead of calling them Simple and Advanced, maybe you should think of them as Static and Dynamic.
|
Hi! I’ve been talking a bit with @mtias and @aduth in the past several weeks and the problem of representing blocks in the markup has become increasingly interesting. So, here’s an idea from an outsider – I may be missing a lot of finer details, but had to get it out of my head :-)
First, some definitions.
A block is a set of four functions:
And one more:
WPHTML
is the type of HTML that is understood by WordPress’sthe_content
filters, like converting empty lines to paragraphs, normal quotes to curly, parsing shortcodes, embeds, etc.Encoding user supplied data – the process of converting the object with data entered by the user to a string that makes easy to parse attributes and
WPHTML
. The current format is of the form markup .Flows
Here are the main flows that we need to cover:
forEditing
.forSaving
and the result is encoded in the post content.WPHTML
of a block in the non-visual editor, next to a block-aware visual editor.WPHTML
.WPHTML
of a block in an editor that doesn’t support blocks (through REST API, XML-RPC, e.g. mobile app, MarsEdit, etc.), no matter whether it’s visual or not.forRendering
we render the final HTML that will be shown in the browser.WPHTML
contains the final markup, we may skip this step.forRendering
we render the final HTML that will be shown in the browser.Implementation Approaches
When implementing those flows as a block developer, the hardest task is to decide what of the user-supplied data to keep in attributes and what to convert to
WPHTML
.Putting all the data into structured attributes will make
forEditing
andforSaving
trivial to implement and it will put the most weight toforRendering
to know about the markup. The approach of keeping all the data in attributes and none inWPHTML
also makes few of the flows a lot less desirable –edit-text
becomes a huge chore for simple blocks (imagine writing a whole paragraph in the form ), because wading through a special format when simple HTML would do is unknown (⇒ scary) to users and probably error-prone – messing up a less-forgiving structured format seems and easy task. Other flows are victims, too – view-blocks will always require the full rendering experience and without much markup the post content will become unusable for other services, except the WordPress.The other extreme is having as much as possible in the markup. While much better end user editing and third-party tools experience, this means heavy parsing of HTML and that’s a path leading to both enormous development complexity and high barrier to entry for the casual block author. Not to mention the disappointed users working with that half-working parsing implementations. Even something seemingly simple as a gallery be awkward to parse – do we find out the number of columns by guessing based on the CSS cut-off?
The truth, of course, is somewhere in the middle. But in what do we keep in attributes and what do we keep in markup for the ultimate trade-off and keeping everybody happy?
Whether that’s the best one or not, I don’t know, but here’s an idea: to have two types of blocks: Simple & Advanced.
Simple blocks
WPHTML
.forEditing
simple and robust, while not keeping long and confusing data in the block attributes. At the same time this lets users to edit the HTML directly, without affecting the block structure much – because of the direct correspondence, if a user adds and extra image after , we will still be able to allow them to edit the blockquote, without overriding their changes.WPHTML
in the post content is the finalWPHTML
.Advanced blocks
WPHTML
is just a cache.forEditing
doesn’t take into account any markup changes, but uses the attributes only. This keeps the implementation simple.What do you think?
The text was updated successfully, but these errors were encountered: