Adds syntax highlighting to pre code blocks using highlight.js. Inserts a language selector on each code block and re-highlights on edit. No toolbar button — enable the plugin and load highlight.js.
Requires highlight.js on the page (window.hljs). Works on code blocks created in the editor or pasted from clipboard.
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/highlight.min.js"></script>
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/code-highlighter/code-highlighter.js"></script>
const app = Redactor('#entry', {
plugins: ['codeHighlighter'],
content: '<pre><code class="language-javascript">const greeting = "Hello";\n\nconsole.log(greeting);</code></pre>'
});
string[])
['css', 'html', 'javascript', 'scss']Redactor('#entry', {
plugins: ['codeHighlighter'],
codeHighlighter: {
languages: ['javascript', 'typescript', 'html', 'css', 'json']
}
});
This plugin does not define language strings.
This plugin does not emit events.
This plugin does not expose a public API.