sanity-io / sanity-plugin-markdown

Markdown support in the Sanity Studio
MIT License
50 stars 8 forks source link

No option to enable spell check #80

Closed luke-h1 closed 1 year ago

luke-h1 commented 1 year ago

Hey, just wondering if it's a possibility to allow the option to enable spell checks within the internal implementation of the Easy MDE component? Looking at the project it seems this would be possible to expose to consumers: https://github.com/sanity-io/sanity-plugin-markdown/blob/489e9f04a7720a542784ec64ca7873b816ab2526/src/components/MarkdownInput.tsx#L65

luke-h1 commented 1 year ago

This can be achieved by building a custom component and passing this to the markdownSchema option in sanity.config.ts:

// CustomMarkdownInput.tsx
import { useMemo } from 'react'
import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'

export function CustomMarkdownInput(props: JSX.IntrinsicAttributes & MarkdownInputProps) {
  const reactMdeProps: MarkdownInputProps['reactMdeProps'] =
    useMemo(() => {
      return {
        options: {
          toolbar: ['bold', 'italic'],
          spellChecker: true,

          // more options available, see:
          // https://github.com/Ionaru/easy-markdown-editor#options-list
        },
        // more props available, see:
        // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor
      }
    }, [])

  return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />
}
// sanity.config.ts

    markdownSchema({input: CustomMarkdownInput}),