Skip to content

Custom InlineContent types #267

Closed

Description

@matthewlipski

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.

Activity

  1. man-shar commented on Nov 1, 2023

    @man-shar

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

  2. matthewlipski commented on Nov 5, 2023

    @matthewlipski
    CollaboratorAuthor

    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.

  3. man-shar commented on Nov 6, 2023

    @man-shar

    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?

  4. matthewlipski commented on Nov 7, 2023

    @matthewlipski
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions