Skip to content
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

Custom InlineContent types #267

Closed
matthewlipski opened this issue Jul 7, 2023 · 4 comments · Fixed by #426
Closed

Custom InlineContent types #267

matthewlipski opened this issue Jul 7, 2023 · 4 comments · Fixed by #426
Labels
documentation Improvements or additions to documentation enhancement New feature or request prio:mid Medium priority

Comments

@matthewlipski
Copy link
Collaborator

Alongside custom block types, custom InlineContent types would allow for more extensibility within BlockNote. This would allow consumers to implement features like comments and spellcheck.

It would also be worth considering custom marks/styles while working on this issue.

@matthewlipski matthewlipski added documentation Improvements or additions to documentation enhancement New feature or request prio:mid Medium priority labels Jul 7, 2023
@man-shar
Copy link

man-shar commented Nov 1, 2023

Is this something that's being worked on actively already? If not, I'd love to try and implement the custom marks support.

@matthewlipski
Copy link
Collaborator Author

We're currently working on fixing the clipboard & HTML/Markdown conversion, so go ahead! I would start by taking a look at the custom blocks API (block.ts for vanilla, ReactBlockSpec.ts for React) and doing something similar for marks/inline nodes, i.e. converting to the TipTap API, storing a schema, typing, etc.

@man-shar
Copy link

man-shar commented Nov 6, 2023

Great, thanks! Last week, I did end up implementing this as a new Tiptap node like so:

import { Node, mergeAttributes } from "@tiptap/core";
import { ReactNodeViewRenderer } from "@tiptap/react";
import CustomInlineNodeView from "./CustomInlineNodeView";

export const CustomInlineNode = Node.create({
  name: "custom-inline-node",
  group: "inline",
  inline: true,
  selectable: false,
  atom: true,
  draggable: true,
  addAttributes() {
    return {
      
    };
  },
  parseHTML() {
    return [
      {
        tag: "custom-inline-node",
      },
    ];
  },
  renderHTML({ HTMLAttributes }) {
    return ["custom-inline-node", mergeAttributes(HTMLAttributes)];
  },
  addNodeView() {
    return ReactNodeViewRenderer(CustomInlineNodeView);
  },
});
const editor = useBlockNote({
    ...,
    _tiptapOptions: {
      extensions: [CustomInlineNode],
    },
  });

It seems to work fine. Though my use case was dragging and dropping these nodes from somewhere else into the text. I'm wondering if it's worth adding this as an example somewhere for the time being?

@matthewlipski
Copy link
Collaborator Author

Oh awesome! I guess there are still probably some quirks when converting the node to InlineContent[] or converting to HTML, but good to see that it's not too much hassle to get it working. I think for now it's ok if ppl just get linked to this issue if they ask about custom inline nodes in discord, and make a documentation page once we can make custom inline content types using the BlockNote API rather than using TipTap's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request prio:mid Medium priority
Projects
None yet
2 participants