-
Notifications
You must be signed in to change notification settings - Fork 4
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
Adds two core blocks beyond generic blocks #18
Conversation
3adcc9e
to
3e17295
Compare
src/post.pegjs
Outdated
type: 'WP_Block__Image', | ||
src: b.children[ 0 ].attrs.src, | ||
caption: b.children[ 1 ] | ||
} } |
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.
@nylen this isn't the prettiest but it is declarative and the transformation is explicit. as long as we stick with a straightforward logical expression and don't do anything stateful or complex it's kind of readable.
honestly I don't think this level of parsing is appropriate for String -> Blocks
but should probably be carried out higher up String -> GenericBlocks -> SpecificBlocks
just for performance and coupling issues. this would let us introduce a DSL or query language above without messing with the parser or its performance
c5621d9
to
f2ed25a
Compare
Adds image and quote blocks. Meant for experimenting with possible parse ideas. This directly embeds certain core block types into the spec parser. The benefit is that we have tight coupling and integration of those block types. The cost is that we have tight coupling and integration of those block types. There's a bit more flexibility in integrating this higher-level parser into the string parser, but I think it may be just as easy to include a JS pass over the parse tree to convert generic into more specific nodes. This is pretty verbose now but I could imagine a basic DSL (or an existing one) to compare tree structure and (choke) load data from HTML ``` [ 'core/image', or( !! caption, [ [ 'img', { src: [ 'url', types.url ] } ] ], [ [ 'figure', [ [ 'img', { src: [ 'url', types.url ] } ], [ 'figcaption', 'caption' ] ] ] ] ) ] >>> { type: 'core/image', url: '...', caption: [ // subtree inside of caption tag, maybe blocks ] } ``` ^^^ that's just playing around, but the idea could be used to both load and generate the serialized data
f2ed25a
to
41f278d
Compare
Related discussion: WordPress/gutenberg#391 Understanding it's experimental, what would be the future for allowing plugin authors to extend this with their own blocks? Would your DSL idea allow for defining the structure of a block outside the grammar spec itself? Am I am a block implementer expected to be exposed to the grammar syntax in any way? |
I think it's a dead end for plugin authors. I could plausibly see the core block types as part of the parse but I think we ultimately need two stages: a tight fast the DSL was mainly discussed because of the concept of storing data in HTML. if we do that we need a way to validate and extract that data and describing complex data types is hard without the DSL. |
Sorry for the late comment here, but I think the responsibility of the parser should be just to parse a tree of HTML and block-delimiter nodes, then we should hand this off to a separate layer to confirm that what appears inside each block is actually valid. One big reason for this is to make it easy for plugin authors; another is that these do feel like separate tasks. |
closing as no longer relevant |
Adds image and quote blocks.
Meant for experimenting with possible parse ideas.
This directly embeds certain core block types into the spec parser. The
benefit is that we have tight coupling and integration of those block
types. The cost is that we have tight coupling and integration of those
block types.
There's a bit more flexibility in integrating this higher-level parser
into the string parser, but I think it may be just as easy to include a
JS pass over the parse tree to convert generic into more specific nodes.
This is pretty verbose now but I could imagine a basic DSL (or an
existing one) to compare tree structure and (choke) load data from HTML
^^^ that's just playing around, but the idea could be used to both load
and generate the serialized data