Package Data | |
---|---|
Maintainer Username: | kaoken |
Package Create Date: | 2017-07-14 |
Package Last Update: | 2020-02-22 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-21 03:00:26 |
Package Statistics | |
---|---|
Total Downloads: | 83 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This target Laravel 5.5 and higher, making PHP version markdown-it easy to use with Laravel.
Table of content
composer:
Add to composer.json
as follows
"require": {
...
"kaoken/laravel-markdown-it":"^1.0"
}
Then update!
composer update
config\app.php
as follows: 'providers' => [
...
Kaoken\LaravelMarkdownIt\MarkdownItServiceProvider::class,
],
'aliases' => [
...
'MarkdownIt' => Kaoken\LaravelMarkdownIt\Facade\MarkdownIt::class,
],
php artisan vendor:publish
By executing the above command, markdownit.php
is created in theconfig
directory.
All options and rules are enabled by default. This is equivalent to hoge ['options_rules_group'] ['default']
in config \ markdownit.php
below.
For a description of the options ("options "
) and rules ("enable "
, "disable "
), see the comments for each parameter of hoge ['options_rules_group'] ['default']
.
If you want to add new options and rules, rewrite the contents of 'example'
by removing the comments belowAdd options and rules
in the comments below.
<?php
return [
'set_options_rules' => 'default',
'options_rules_group' =>[
'default' => [
'options'=> [
'html'=> true, // Enable HTML tags in source
'xhtmlOut'=> true, // Use '/' to close single tags (<br />)
'breaks'=> true, // Convert '\n' in paragraphs into <br>
'langPrefix'=> 'language-', // CSS language prefix for fenced blocks
'linkify'=> true, // autoconvert URL-like texts to links
// Enable some language-neutral replacements + quotes beautification
'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.
//
// function (/*str, lang*/) { return ''; }
//
'highlight'=> null,
'maxNesting'=> 100 // Internal protection, recursion limit
],
/**
* Manage rules!
* `'enable'` adds the rule you want to enable.
* `'disable'` adds the rule you want to disable.
* default all rules are enabled.
* @see https://github.com/markdown-it/markdown-it/tree/master/benchmark/samples
*/
'enable' => [
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-autolink.md
*/
'autolink',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-backticks.md
*/
'backticks',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-bq-flat.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-bq-nested.md
*/
'blockquote',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-code.md
*/
'code',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-em-flat.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-em-nested.md
*/
'emphasis',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-entity.md
*/
'entity',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-escape.md
*/
'escape',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-fences.md
*/
'fence',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-heading.md
*/
'heading',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-hr.md
*/
'hr',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-html.md
*/
'html_block',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-html.md
*/
'html_inline',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-links-flat.md
*/
'image',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-lheading.md
*/
'lheading',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-links-flat.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-links-nested.md
*/
'link',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-list-flat.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-list-nested.md
*/
'list',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/inline-newlines.md
*/
'newline',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-ref-flat.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-ref-list.md
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-ref-nested.md
*/
'reference',
/**
* @see https://github.com/markdown-it/markdown-it/blob/master/benchmark/samples/block-tables.md
*/
'table'
],
'disable' => [
]
],
/**
* Add options and rules.
*/
/*
'example' => [
'options'=> [
'html'=> false,
'xhtmlOut'=> false,
'breaks'=> false,
'langPrefix'=> 'language-',
'linkify'=> false,
'typographer'=> false
],
'enable' => [
'backticks',
'blockquote',
'emphasis',
'heading',
'list',
'newline',
],
'disable' => [
'autolink',
'code',
'entity',
'escape',
'fence',
'hr',
'html_block',
'html_inline',
'image',
'lheading',
'link',
'reference',
'table'
]
]
*/
]
];
use MarkdownIt;
class hoge{
public function test(){
// Already a group of `default` options and rules have been set.
$result1 = MarkdownIt::render('# markdown-it rulezz!');
// `example`options and groups of rules are set.
$result2 = MarkdownIt::setOptionsRules("example")
->render('# markdown-it rulezz!');
}
}
Single line rendering, without paragraph wrap:
use MarkdownIt;
class hoge{
public function test(){
// Already a group of `default` options and rules have been set.
$result1 = MarkdownIt::renderInline('__markdown-it__ rulezz!');
// `example`options and groups of rules are set.
$result2 = MarkdownIt::setOptionsRules("example")
->renderInline('__markdown-it__ rulezz!');
}
}
linkify: true
Set linkify-it to access the linkify instance.
use MarkdownIt;
class hoge{
public function test(){
// disables .py as top level domain
MarkdownIt::linkify()->tlds('.py', false);
}
}
Thanks to the authors of the original implementation in Javascript, markdown-it:
and to John MacFarlane for his work on the CommonMark spec and reference implementations.
Related Links: