Skip to content

Getting started ​

Complete installation, including the Markdown library. This example uses a normal PHP template and your existing application layout.

In src/View/AppView.php, load the helper and keep your existing initialization code:

php
public function initialize(): void {
    parent::initialize();

    $this->loadHelper('Markup.Markdown', ['debug' => false]);
}

Create templates/Pages/markup.php in a standard CakePHP application:

php
<?php
$source = '# Welcome' . "\n\n" . 'Some **bold** text and *italic* text.';
?>
<div class="article"><?= $this->Markdown->convert($source) ?></div>

Open /pages/markup, using the standard Pages route. For an application with custom routes, use an existing action and its matching PHP template. You should see a Welcome heading, bold text and italic text. The converter escapes raw HTML and blocks unsafe link schemes by default, so do not wrap its HTML output in h().

Conversion options can be supplied for a single call:

php
<?= $this->Markdown->convert($source, ['max_nesting_level' => 20]) ?>

For options shared by every conversion, see Configuration. To use another format, load its matching helper and follow the Markdown, BBCode, Djot or Carve guide. Their delimiters differ.

Released under the MIT License.