I am working on a Gutenberg sidebar plugin which does some text analysis and based on that, it needs to annotate text in the paragraph blocks. This is the easier part and is achieved using the Annotations API by iterating over each block like this:
wp.data.dispatch( 'core/annotations' ).__experimentalAddAnnotation( {
source: "my-annotations-plugin",
blockClientId: wp.data.select( 'core/editor' ).getBlockOrder()[0],
richTextIdentifier: "content",
range: {
start: 50,
end: 100,
},
} );
Now, the challenge that I am facing is persisting these annotations (as that's the requirement of the plugin). I figured out that Annotations API internally uses applyFormat method of @wordpress/rich-text package but I am not able to figure out how to use applyFormat directly. The documentation is in-adequate and lacks code examples.
If you have worked with this it would help to have sample working (ES5 or ES6) code to use applyFormat in the right way.