PHP code example of tomakee / laravel-markdown-wrapper

1. Go to this page and download the library: Download tomakee/laravel-markdown-wrapper 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/ */

    

tomakee / laravel-markdown-wrapper example snippets


//config/app.php
return [
    'providers' => [
        ...
        Tomakee\Markdown\MarkdownServiceProvider::class,
    ],
    ...
];

//parse markdown text
$html = markdown('some markdown text.');

//change parser config
$parser = markdown_config('hard_wrap', false);
$html = $parser->parse('some markdown text.');

//change parser config and parse markdown
$html = markdown_config(['hard_wrap' => false, 'code_class_prefix' => 'prefix-'])
        ->parse('some markdown text.');

//parse markdown file
$html = markdown_file('path.to.markdownfile');  //path format is same as Laravel view.

//You can set different resources path.
//But if your project always use different path from default,
//change the config setting (app/config/markdown.php).

$html = markdown_file('path.to.markdownfile', [resources path,,,,]);

$html = markdown_capture(function () {
    echo 'some markdown text.';
});

//with params
$html = markdown_capture(function () use ($args1, $args2) {
    echo $args1 . $args2 . 'some markdown text.';
});

use Tomakee\Markdown\Facades\Markdown;

//parse markdown text
$html = Markdown::parse('some markdown text.');

//parse markdown file
$html = Markdown::file('path.to.markdownfile');  //path format is same as Laravel view.

//You can set different resources path.
//But if your project always use different path from default,
//change the config setting (app/config/markdown.php).

$html = Markdown::file('path.to.markdownfile', [resources path,,,]);

//change parser config
$html = Markdown::setConfig('hard_wrap', false)
    ->parse('some markdown text.');

//temporary change parser config
$html = Markdown::setConfig('hard_wrap', false)->parse('some markdown text.');
Markdown::setConfig('hard_wrap', true);

//direct access to the original parser methods if you need
Markdown::PARSER_METHOD();

//get instance
$instance = app('markdown');
//or
$instance = app('Tomakee\Markdown\Parser');

//parse markdown text
$html = app('markdown')->parse('some markdown text.');

//parse markdown file
$html = app('markdown')->file('path.to.markdownfile');  //path format is same as Laravel view.

//You can set different resources path.
//But if your project always use different path from default,
//change the config setting (app/config/markdown.php).

$html = app('markdown')->file('path.to.markdownfile', [resources path,,,]);

//change parser config
$html = app('markdown')->setConfig('hard_wrap', false)
    ->parse('some markdown text.');

//temporary change parser config
$html = app('markdown')->setConfig('hard_wrap', false)
    ->parse('some markdown text.');
app('markdown')->setConfig('hard_wrap', true);

//direct access to the original parser methods if you need
app('markdown')->PARSER_METHOD();

[
    'default'    => 'github',
    'resources'  => [resource_path('views')],
    'extensions' => ['md', 'md.blade.php', 'blade.php', 'php'],
    [
        'id'      => 'github',
        'parser'  => \cebe\markdown\GithubMarkdown::class,
        'methods' => [
                'single' => 'parseParagraph',
                'multi'  => 'parse',
        ],
        'config'  => [
                'html5'               => true,
                'enableNewlines'      => true,
                'keepListStartNumber' => false,
        ],
    ],
];
bash
cd LARAVEL_PROJECT_DIR
composer 

@markdown('some markdown text.')
app/config/markdown.php
bash
cd LARAVEL_PROJECT_DIR
php artisan vendor:publish