Skip to content

How to generate automatic IDs for headings #1520

Closed Answered by rusign
rusign asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for your help,
I checked the createNodeIdPlugin but it was fitting my needs,
I found another way to do what I wanted to do, on my Headings Plugins I'm overriding the props to implement the generated ID inside the element
example :

export const createH2Plugin = createPluginFactory<HotkeyPlugin>({
  key: RichTextKey.ELEMENT_H2,
  isElement: true,
  handlers: {
    onKeyDown: onKeyDownToggleElement,
  },
  options: {
    hotkey: ['mod+opt+2', 'mod+shift+2'],
  },
  deserializeHtml: {
    rules: [
      {
        validNodeName: 'H2',
      },
    ],
  },
  props: (props) => {
    return {
      ...props,
      element: {
        ...props.element,
        id: generateIdFromNodeChildr…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rusign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants