JSPM

@remirror/extension-code-block

1.0.0-next.55
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44971
  • Score
    100M100P100Q162850F
  • License MIT

Unleash the inner coder with code blocks for your remirror editor.

Package Exports

  • @remirror/extension-code-block
  • @remirror/extension-code-block/dist/extension-code-block.browser.cjs.js
  • @remirror/extension-code-block/dist/extension-code-block.browser.esm.js
  • @remirror/extension-code-block/dist/extension-code-block.cjs.js
  • @remirror/extension-code-block/dist/extension-code-block.esm.js

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.

Version Weekly Downloads Bundled size Typed Codebase MIT License

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

This is included by default when you install the recommended remirror package. All exports are also available via the entry-point, remirror/extension/code-block.

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 { ExtensionPriority, RemirrorManager } from 'remirror/core';
import { CodeBlockExtension } from 'remirror/extension/code-block';
import { CorePreset } from 'remirror/preset/core';

// 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.append(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();