• Hello,

    I’m developing a simple plugin that interacts with Gutenberg editor. The plugins make an ajax call to an API and return a variable (data.description) as HTML text. That text could be anything, but it’s HTML formatted.

    Ex:

    
    <p>Some text here</p>
    <h2>Let's say it's an H2 heading</h2>
    <ul>Unordered list</ul>
    

    I’m trying to figure out how to, for each HTML entity in the variable to create the respective block to properly work with Gutenberg editor.

    The following code:

    
    let block = wp.blocks.createBlock( 'core/paragraph', { content: data.description } );
    wp.data.dispatch( 'core/editor' ).insertBlocks( block );
    

    Creates the fully HTML string as one paragraph. That will include any HTML tag. How can I achieve something like if <p> add that text as core/paragraph, if

      , use the core list API reference, etc?

      Any help is appreciated

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Properly use wp.blocks.createBlock’ is closed to new replies.