Block Code

Adds a block control button for editing the raw HTML of the current block in a textarea. Replaces the block content on save.

Select a block, open the control dropdown, and choose Edit Code to view and edit the block HTML source. When the editor codemirror option is enabled, the textarea is upgraded to CodeMirror automatically.

Load the bundle

<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/block-code/block-code.js"></script>

Initialization

const app = Redactor('#entry', {
    plugins: ['blockCode']
});

Options

  • icon (string)
    • SVG icon HTML for the block control button.

CodeMirror

Block Code uses a plain <textarea> by default. To enable syntax-aware editing, set the editor-level codemirror option — the plugin upgrades the field when CodeMirror is available.

Redactor('#entry', {
    plugins: ['blockCode'],
    codemirror: {
        mode: 'htmlmixed',
        lineNumbers: true
    }
});

Language strings

en: {
    blockCode: {
        'edit-code': 'Edit Code'
    }
}

Events

This plugin does not emit events.

API

This plugin does not expose a public API.