1. Go to this page and download the library: Download kaoken/markdown-it-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kaoken / markdown-it-php example snippets
$md = new MarkdownIt();
$result = $md->render('# markdown-it rulezz!');
$md = new MarkdownIt();
$result = $md->renderInline('__markdown-it__ rulezz!');
// commonmark mode
$md = new MarkdownIt('commonmark');
// default mode
$md = new MarkdownIt();
// enable everything
$md = new MarkdownIt([
"html"=> true,
"linkify"=> true,
"typographer"=> true
]);
// full options list (defaults)
$md = new MarkdownIt([
"html"=> false, // Enable HTML tags in source
"xhtmlOut"=> false, // Use '/' to close single tags (<br />).
// This is only for full CommonMark compatibility.
"breaks"=> false, // Convert '\n' in paragraphs into <br>
"langPrefix"=> 'language-', // CSS language prefix for fenced blocks. Can be
// useful for external highlighters.
"linkify"=> false, // Autoconvert URL-like text to links
// Enable some language-neutral replacement + quotes beautification
// For the full list of replacements, see https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js
"typographer"=> false,
// Double + single quotes replacement pairs, when typographer enabled,
// and smartquotes on. Could be either a String or an Array.
//
// For example, you can use '«»„“' for Russian, '„“‚‘' for German,
// and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
"quotes"=> '“”‘’',
// Highlighter function. Should return escaped HTML,
// or '' if the source string is not changed and should be escaped externaly.
// If $result starts with <pre... internal wrapper is skipped.
"highlight"=> function (/*str, lang*/) { return ''; }
]);
$md = new MarkdownIt()
->plugin(plugin1)
->plugin(plugin2, opts, ...)
->plugin(plugin3);
// Actual default values
$md = new MarkdownIt([
"highlight"=> function ($str, $lang) {
if ( $lang ) {
try {
return highlight_string($str);
} catch (Exception $e) {}
}
return ''; // use external default escaping
}
]);