Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a default editor for code blocks, including when a language isn't specified #114

Closed
FinlayBP opened this issue Oct 10, 2023 · 2 comments · Fixed by #115
Closed

Allow a default editor for code blocks, including when a language isn't specified #114

FinlayBP opened this issue Oct 10, 2023 · 2 comments · Fixed by #115
Labels

Comments

@FinlayBP
Copy link
Contributor

I'm currently running the code block and code mirror plugins as follows:

codeBlockPlugin({ defaultCodeBlockLanguage: 'txt' }),
codeMirrorPlugin({
  codeBlockLanguages: {
    txt: 'text',
    js: 'JavaScript',
    ts: 'TypeScript',
    tsx: 'TypeScript (React)',
    jsx: 'JavaScript (React)',
    css: 'CSS',
    python: 'Python',
    bash: 'Bash',
  },
}),

But when users add empty backticks without a language specified:

` ` `
blah
` ` `

They currently recieve an error boundary because Error: No CodeBlockEditor registered for language=null meta=null. Perhaps there could be a defaultCodeBlockEditor just like there's a defaultCodeBlockLanguage?

I imagine this would also remove the need to specify a large object of codeBlockLanguages if I want to use the codeMirrorPlugin for everything.

I had a go at the following as per the discussion in #95 (comment), but CodeMirrorEditor isn't exported at the moment so this doesn't work:

codeBlockEditorDescriptors: [
  {
    priority: 100,
    match: () => true,
    Editor: CodeMirrorEditor,
  },
],
@petyosi
Copy link
Contributor

petyosi commented Oct 10, 2023

True, makes sense. Want to open a PR for the code mirror editor export? I feel like this is the easiest solution.

@github-actions
Copy link

🎉 This issue has been resolved in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants