mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.91k stars 145 forks source link

[BUG] allowedHeadingLevels not working with markdown shortcuts #559

Open gaki2 opened 2 months ago

gaki2 commented 2 months ago

If you want to ask for support or request features, sponsor the project and contact me over email.

Describe the bug

After setting allowedHeadingLevels [1,2], but ### + spacebar shortcut makes h3 tag. also h4, h5, h6.


export default function InitializedMDXEditor({
  editorRef,
  ...props
}: { editorRef: ForwardedRef<MDXEditorMethods> | null } & MDXEditorProps) {
  return (
    <MDXEditor
      plugins={[
        headingsPlugin({
          allowedHeadingLevels: [1, 2],
        }),
        markdownShortcutPlugin(),
      ]}
      {...props}
      ref={editorRef}
    />
  );
}

Reproduction Start from https://codesandbox.io/p/sandbox/mdx-editor-base-q8s7zr?file=/src/App.tsx to reproduce the problem so that I can observe the issue on my side and make sure that the fix reliably addresses it.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

I set allowedHeadingLevels = [1,2] but ### or #### or ##### or ###### still working.

Screenshots If applicable, add screenshots to help explain your problem.

https://github.com/user-attachments/assets/7e5f5c99-789f-4bc4-a682-fe760de621c5

Desktop (please complete the following information):

petyosi commented 2 months ago

Agreed. One more point towards moving the markdown shortcuts from lexical into the mdxeditor code. Misfortunate.