CI Markdown is a CodeIgniter library for parsing Markdown. It's a modified rendition of Michel Fortin's PHP Markdown.
See the ChangeLog for a complete list of PHP Markdown modifications.
- PHP 5.2x+
- CodeIgniter v2.1.0 to v3.x-dev
Save Markdown.php
to your CodeIgniter application/libraries
folder.
Load the CI Markdown library from your Controller.
$this->load->library('markdown');
Or auto-load it from your application/config/autoload.php
config file.
$autoload['libraries'] = array('markdown');
The parse() method accepts a single parameter for a Markdown formatted string. It returns an HTML formatted string
.
$markdown_formatted_text = '# Heading ' . "\n\n" . '## Sub-heading' . "\n\n";
echo $this->markdown->parse($markdown_formatted_text);
// outputs <h1>Heading</h1><h2>Sub-heading</h2>
The parse_file() method accepts a single parameter for a Markdown formatted file. It returns an HTML formatted string
.
$markdown_file_path = 'test.md';
echo $this->markdown->parse_file($markdown_file_path);
// outputs <h1>Hello world!</h1><h2>I was once in a file!</h2>
NOTE: If the Markdown file does not exist, false
is returned.
- See the ChangeLog for a detailed list of changes.
- Unit tests
Jon LaBelle contact@jonlabelle.com