Kisphp Markdown Parser is a highly customizable and extendable markdown parser written in PHP allowing you to add custom html markup to easy integrate it in your website's layout
Kisphp Markdown Parser is in beta version and documentation might change daily.
To install Kisphp Markdown Parser add the following line to your composer.json
file
"require": {
"kisphp/markdown-parser": "dev-master"
}
or simply run in terminal the following command
composer require kisphp/markdown-parser
To integrate the parser in your project is very simple, you just need 2 lines of code:
// create markdown object
$markdown = \Kisphp\MarkdownFactory::createMarkdown();
// parse markdown text
$markdownHtml = $kisphp->parse($markdownText);
Extending the class is very easy. First you need to create your own Factory that will extend MarkdownFactory
class from repository:
<?php
namespace Project;
use Kisphp\MarkdownFactory;
class ProjectFactory extends MarkdownFactory
{
/**
* @return array
*/
protected function getAvailableNamespaces()
{
// here you register your own parser block namespaces before the core ones.
$projectNamespaces = [
'Project\\Blocks\\',
];
// get core block namespaces list
$coreNamespaces = parent::getAvailableNamespaces();
return array_merge($coreNamespaces, $projectNamespaces);
}
}
Now the system will know that you provide your own block types and will use them prior to core blocks. Also you can extend core blocks to add your own styling or logic.
To extend block classes is very easy. All you have to do is to extend the core block classes and change the html for returned tags.
As an example we'll extend the ParagraphBlock
to add a css class to every paragraph in the page. First, you'll need to create your own block class with the same name that core block has. For begining we'll create our ParagraphBlock class in our project's namespace.
// /path/to/project/src/Project/Blocks/BlockParagraph.php
<?php
namespace Project\Blocks;
use Kisphp\Blocks\BlockParagraph as Paragraph;
class BlockParagraph extends Paragraph
{
public function getStartTag()
{
// return a different markup for paragraphs
return '<p class="text-danger">';
}
}
Now, the generated html will have the specified css class in all paragraphs.