@remirror/extension-code-block
Unleash the inner coder with code blocks for your remirror editor.

Installation
yarn add refractor @remirror/extension-code-block
pnpm add refractor @remirror/extension-code-block
npm install refractor @remirror/extension-code-block
This is included by default when you install the recommended remirror
package. All exports are also available via the entry-point, remirror/extensions
.
Refractor is a peer dependency and must be installed to consume the package properly.
Usage
The following code sample will create a limited editor and run the available commands from this extension.
import jsx from 'refractor/lang/jsx';
import typescript from 'refractor/lang/typescript';
import { ExtensionPriority, RemirrorManager } from 'remirror';
import { CodeBlockExtension, CorePreset } from 'remirror/extensions';
const codeBlockExtension = new CodeBlockExtension({ supportedLanguages: [typescript, jsx] });
const corePreset = new CorePreset();
const manager = RemirrorManager.create([codeBlockExtension, corePreset]);
const element = document.createElement('div');
document.body.append(element);
manager.addView(element);
manager.store.commands.createCodeBlock({ language: 'markdown' });
manager.store.chain.updateCodeBlock({ language: 'js' }).formatCodeBlock().run();
Formatter
If you would like to format code, you can import from the @remirror/extension-code-block/formatter
endpoint.
The formatter requires prettier@3.2
to be installed as a peer dependency.