Skip to content

Block validation: exclude data attributes / add support for custom validators #8532

Description

@AndiDittrich

Dear Gutenberg Team,

i'm currently developing a Gutenberg Plugin to integrate EnlighterJS Syntax Highlighter into to editor and ran into serious trouble regarding the "block/element validation":

Because of the strict 1:1 structure validation there seems to be no possibility? to add optional attributes to the elements generated by the save function.
The editor always throws element validation errors in case custom attributes are added (e.g. manually by a user - which might be legitimate).

Of course, its possible to add all allowed attributes to the output...but this will mess-up the generated html with a lot of unused attributes

Example HTML Structure

<pre 
data-enlighter-language="less" 
data-enlighter-highlight="2" 
data-enlighter-lineoffset="" 
data-enlighter-linenumbers="" 
data-enlighter-title="">
...
</pre>

Typical Validation Error

gutenberg_validation_error

Suggestions

  • Exclude data- attributes from validation (they represent an elements state, not its structure)
  • Add support for custom block validation methods (within registerBlockType) to allow users to override the default behaviour
  • Maybe use the attribute schema to validate the structure, including an optional flag

best regards, Andi

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Paste[Status] DuplicateUsed to indicate that a current issue matches an existing one and can be closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions