Highlighter

This plugin highlights the code inside pre tags in the editor and uses highlight.js for it.

Code

<!DOCTYPE html>
<html>
    <head>
        <title>Redactor</title>
        <meta charset="utf-8">

        <!-- css -->
        <link rel="stylesheet" href="/your-folder/redactor.css" />

        <!-- highlight.js -->
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    </head>
    <body>
        <!-- element -->
        <textarea id="entry">...</textarea>

        <!-- js -->
        <script src="/your-folder/redactor.js"></script>
        <script src="/your-folder/plugins/highlighter/highlighter.js"></script>

        <!-- call -->
        <script>
        Redactor('#entry', {
            plugins: ['highlighter']
        });
        </script>
    </body>
</html>

Usage

In addition to the plugin, you need to connect highlight.js files to the page:


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>

In the editor, use only pre tags with a code tag inside for the highlighting to work correctly:


<pre><code></code></pre>

You can also use a code tag specifying the highlighting language:


<pre><code class="language-javascript"></code></pre>

By default, the plugin has a setting to select the following highlighting languages:


['css', 'html', 'javascript', 'scss']

You can specify your own set of languages to select, for example like this:


Redactor('#entry', {
    plugins: ['highlighter'],
    highlighter: {
        languages: ['css', 'html', 'javascript', 'scss', 'php', 'python']
    }
});