PHP code example of cassarco / markdown-tools

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

    

cassarco / markdown-tools example snippets


return [

    /*
    |--------------------------------------------------------------------------
    | Schemes
    |--------------------------------------------------------------------------
    |
    | Configure as many "schemes" as you like. Each scheme should contain a
    | path to a single markdown file or a folder containing markdown files.
    |
    */

    'schemes' => [

        // Give each scheme a name for your own organisation.
        'markdown' => [

            // Give the path to a folder of markdown files or a single markdown file.
            'path' => resource_path('markdown'),

            // Specify the validation rules for front-matter properties.
            'rules' => [
                // 'title' => '            'symbol' => '#',
            'html_class' => '',
            'aria_hidden' => false,
            'id_prefix' => '',
            'fragment_prefix' => '',
        ],

        'table_of_contents' => [
            'html_class' => 'table-of-contents',
            'position' => 'top',
            'style' => 'bullet',
            'min_heading_level' => 1,
            'max_heading_level' => 6,
            'normalize' => 'relative',
            'placeholder' => null,
        ],

        'wikilinks' => [],

        'front-matter' => [
            'yaml-parse-flags' => Yaml::PARSE_DATETIME
        ]
    ],
];

use function Laravel\Prompts\info;

return [
    'schemes' => [
        'markdown' => [
            'path' => resource_path('markdown'),
            'rules' => [
                'title' => '

use function Laravel\Prompts\info;

// Get the markdown for the markdown file.
$file->markdown()

// Get the front matter as a php array
$file->frontMatter()

// Get the html for the markdown file without a table of contents.
$file->html()

// Get the html table of contents.
$file->toc()

// Get the markdown file as html with the table of contents embedded.
$file->htmlWithToc()

// Get the pathname for the markdown file
$file->pathname()

Article::updateOrCreate([
    'slug' => $file->frontMatter()['slug'] ?? Str::slug($file->frontMatter()['title']),
], [
    'title' => $file->frontMatter()['title'],
    'slug' => $file->frontMatter()['slug'] ?? Str::slug($file->frontMatter()['title']),
    'description' => $file->frontMatter()['description'],
    'table_of_contents' => $file->toc(),
    'content' => $file->html(),
    'image' => $file->frontMatter()['image'],
    'tags' => $file->frontMatter()['tags'],
    'published_at' => Carbon::make($file->frontMatter()['published_at']),
    'deleted_at' => Carbon::make($file->frontMatter()['deleted_at']),
    'created_at' => Carbon::make($file->frontMatter()['created_at']),
    'updated_at' => Carbon::make($file->frontMatter()['updated_at']),
]);
bash
php artisan vendor:publish --tag="markdown-tools-config"
bash
php artisan markdown-tools:process