mdx-editor / editor

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

No way to disable "underline" entirely #467

Closed deymundson closed 1 month ago

deymundson commented 1 month ago

Describe the bug I am attempting to configure the editor to support only a sub-set of possible markdown. One of the features I would like to remove is the ability to underline text. I was able to use the toolbar primitives to create a custom formatting toggle that only includes Bold and Italic buttons, and was able to ensure HTML cannot be used by setting suppressHtmlProcessing={true}, however, it is still possible to underline text by selecting the text and hitting Ctrl-U. The markdown produced then includes <u>text</u>, even though suppressHtmlProcessing is true.

Expected behavior I'm not entirely sure what the correct fix for this would be... a couple options I can think of would be:

  1. Ensure <u></u> cannot be produced when suppressHtmlProcessing is true.
  2. Add an options prop to the BoldItalicUnderlineToggles, much like the ListsToggle, and then only enable the keyboard shortcuts for those options selected.
petyosi commented 1 month ago

You can achieve this with your own plugin - you need to register two things, basically:

Refer to the docs for more details on the matter.

As a general note: the toolbar is an "accessory"; its contents are by no means hard-bound to the editor capabilities, nor they can enable or restrict certain behavior.

wouterlemcke commented 2 weeks ago

I need this as well. I've been struggling with it for a day now, but cannot really put the pieces together from the docs. Could you provide me/us with an example?