Package Exports
- @remirror/extension-code-block
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@remirror/extension-code-block) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@remirror/extension-code-block
Unleash the inner coder with code blocks for your remirror editor.
Installation
yarn add refractor @remirror/extension-code-block@next @remirror/pm@next # yarn
pnpm add refractor @remirror/extension-code-block@next @remirror/pm@next # pnpm
npm install refractor @remirror/extension-code-block@next @remirror/pm@next # npm
Refractor is a peer dependency and is needed when adding extra language support.
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 { RemirrorManager, ExtensionPriority } from '@remirror/core';
import { CorePreset } from '@remirror/preset-core';
import { CodeBlockExtension } from '@remirror/extension-code-block';
// Create the codeBlock extension
const codeBlockExtension = new CodeBlockExtension({ supportedLanguages: [typescript, jsx] });
const corePreset = new CorePreset();
// Create the Editor Manager with the codeBlock extension passed through.
const manager = RemirrorManager.create([codeBlockExtension, corePreset]);
// Pass the dom element to the editor. If you are using `@remirror/react` or
// other framework wrappers then this is handled for you.
const element = document.createElement('div');
document.body.appendChild(element);
// Add the view to the editor manager.
manager.addView(element);
// Access the code block commands
manager.store.commands.createCodeBlock({ language: 'markdown' });
// Also supports chaining
manager.store.chain.updateCodeBlock({ language: 'js' }).formatCodeBlock().run();
Credits
This package was bootstrapped with monots.