CakePHP plugin for markup (parsing and displaying)

Installs: 1 982

Dependents: 1

Suggesters: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0


0.2 2019-03-22 00:27 UTC


Build Status Coverage Status Minimum PHP Version License Total Downloads Coding Standards

A CakePHP plugin to

  • easily use code syntax highlighters.

This branch is for CakePHP 3.6+.


composer require dereuromark/cakephp-markup


bin/cake plugin load Markup



// You must load the helper before
$this->loadHelper('Markup.Highlighter', $optionalConfigArray);

// In our ctp file we can now highlight some code snippet
$string = <<<'TEXT'
$result = 'string' . $this->request->query('key'); // Some comment

echo $this->Highlighter->highlight($string, ['lang' => 'php']);

Supported Highlighters


Using native PHP syntax highlighting this default highlighter does not need any dependencies. Just add some basic CSS styling for all <pre> tags.

The output will be automatically escaped (safe) HTML code, e.g. for php language code:

<pre class="lang-php"><code>
<span style="color: #000000">$key&nbsp;=&nbsp;'string'&nbsp;.&nbsp;$this-&gt;something-&gt;do(true);&nbsp;//&nbsp;Some&nbsp;comment</span>


Using only JS via or this parser is lightweight on the server side. It requires a CSS and JS file on top to do client-side highlighting "just in time".

// Helper option
'highlighter' => 'Markup\Highlighter\JsHighlighter',

The output for php language code will be wrapped in

<pre><code class="language-php">...</code></pre>

tags, for example. Do not forget to add your custom code style CSS file and the JS code as documented at or

Write your own highlighter

You just have to implement the HighlighterInterface and ideally extend the abstract Highlighter class. Then you can simply switch your code highlighting on demand or globally with Configure:

// Configure
'Highlighter' => [
    'highlighter' => 'VendorName\PluginName\CustomHighlighter',

You should be able to easily use any custom highlighter this way.

If you are looking for a good auto-detection highlighter, take a look at In case you need the full options stack, it would be best to write a custom one here, otherwise a basic code template <pre class="prettyprint">{{content}}</pre> for JsHighlighter should do the trick.

Additional Configuration

You can switch the template to use <div> instead of <pre> for example:

// Helper option
'templates' => [
    'code' => '<div{{attr}}>{{content}}</div>',


  • Add more highlighters (you can also just link your own here)
  • Add markup parsers and possibly View classes (BBCode, Markdown, ...)