Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Apr 19, 2017

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

@dmsnell dmsnell requested review from mcsf, nylen, mtias and aduth April 19, 2017 14:32
@dmsnell dmsnell force-pushed the add-core-blocks branch 2 times, most recently from 3adcc9e to 3e17295 Compare April 19, 2017 14:34
src/post.pegjs Outdated
type: 'WP_Block__Image',
src: b.children[ 0 ].attrs.src,
caption: b.children[ 1 ]
} }
Copy link
Member Author

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

@dmsnell dmsnell force-pushed the add-core-blocks branch 3 times, most recently from c5621d9 to f2ed25a Compare April 19, 2017 14:39
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
@aduth
Copy link

aduth commented Apr 19, 2017

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?

@dmsnell
Copy link
Member Author

dmsnell commented Apr 19, 2017

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 String > List of Blocks parser core and then another level which turns those building blocks into a list of blocks and specific blocks.

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.

@nylen
Copy link

nylen commented Apr 27, 2017

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.

@dmsnell
Copy link
Member Author

dmsnell commented May 19, 2017

closing as no longer relevant

@dmsnell dmsnell closed this May 19, 2017
@dmsnell dmsnell deleted the add-core-blocks branch May 19, 2017 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants