Skip to content

Adding toExternalHTML to ReactCustomInlineContentImplementation #1658

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

Open
mbresson opened this issue May 4, 2025 · 1 comment
Open

Adding toExternalHTML to ReactCustomInlineContentImplementation #1658

mbresson opened this issue May 4, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@mbresson
Copy link

mbresson commented May 4, 2025

Why

Currently, for custom block types, it is possible to implement toExternalHTML as part of their ReactCustomBlockImplementation, so that the HTML can be output to e.g. a custom tag (e.g. a <video> tag for a custom Video block). This is useful especially when parsing back this HTML to blocks, thanks to the parse function.

However, we do not have the same ability for custom inline content. Let’s say that we have a Mention custom inline content (as in the docs 🙂) then when BlockNoteJS exports this to HTML, it uses its render method, which can be inconvenient.
A good example is when you want the HTML to be parsed or reused by other tools, it would be nice, in the example of our Mention inline content, to be able to export it to a <span class="mention" user="steve"></span>.

Ideal solution

Example with the Mention inline content from the docs:

export const Mention = createReactInlineContentSpec(
  {
    type: "mention",
    propSchema: {
      user: {
        default: "Unknown",
      },
    },
    content: "none",
  },
  {
    render: (props) => (
      <span style={{ backgroundColor: "#8400ff33" }}>
        @{props.inlineContent.props.user}
      </span>
    ),
    toExternalHTML: (props) => (
      <span className="mention" user={props.user}></span>
    ),
  }
);

Thanks!

@mbresson mbresson added the enhancement New feature or request label May 4, 2025
@YousefED
Copy link
Collaborator

YousefED commented May 5, 2025

Thanks for the input - it's on our radar to review and improve this - likely this summer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants