BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Attach metadata to blocks and inline contents

Open ClementEXWiki opened this issue 7 months ago • 1 comments

Is your feature request related to a problem? Please describe. Make it possible to attach metadata (e.g. a JS value) to any block or inline content in BlockNote's AST.

Example: we currently transform some elements from an in-house syntax to native BlockNote elements such as paragraphs, lists or links, but we need to preserve the exact syntax that was used to build them when we save content from the editor. The only way to achieve this is to attach some metadata (here, the raw source used for the transform) to get it back later.

Another example: we'd like to distinguish links pointing to an external URL and links pointing to an internal document. Both use an URL inside the editor, but we'd like to make them hold different data, the internal links requiring some reference informations inside them. And building a different link inline content type isn't an ideal solution obviously.

Describe the solution you'd like Enable attaching JS values to any element. Ideally, this would be any JSON-compatible structure, but it would work even with a simple Record<string, string>.

In the AST, this could look like this:

{
    type: 'paragraph',
    styles: { /* ... */ },
    content: [
        {
            type: 'text',
            styles: { /* ... */ },
            content: 'Hello world!',
            // New
            metadata: { /* ... */ }
        }
    ],
    // New
    metadata: { /* ... */ }
}

This could be typed as a metadata?: Record<string, string> for instance, in order to still get some level of type safety.

Describe alternatives you've considered I don't see any alternative to this problem.

Additional context N/A

Bonus [ ] I'm a sponsor and would appreciate if you could look into this sooner than later 💖

ClementEXWiki avatar Jul 10 '25 12:07 ClementEXWiki