PHP code example of mistralys / markdown-viewer

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

    

mistralys / markdown-viewer example snippets




declare(strict_types=1);

use Mistralys\MarkdownViewer\DocsManager;
use Mistralys\MarkdownViewer\DocsViewer;

if(!file_exists(__DIR__.'/vendor/autoload.php')) {
    die('Please run <code>composer install</code> first.');
}

URL to the vendor/ folder, relative
// to the script. This is needed to load the clientside dependencies,
// like jQuery and Bootstrap.
(new DocsViewer($manager, '/url/to/vendor'))
    ->setTitle('Documentation')
    ->display();

use Mistralys\MarkdownViewer\DocsManager;

$manager = new DocsManager();

// Add a single folder, non-recursive.
$manager->addFile('Name of the file', '/path/to/file.md');

use Mistralys\MarkdownViewer\DocsManager;

$manager = new DocsManager();

// Add a single folder, non-recursive.
$manager->addFolder('/path/to/files');

// Add a folder and all its subfolders
$manager->addFolder('/path/to/files', true);

use Mistralys\MarkdownViewer\DocsManager;

$manager = new DocsManager();

// Add all TXT files from a single folder, non-recursive.
$manager->addFolder('/path/to/files', false, 'txt');

use Mistralys\MarkdownViewer\DocsManager;

$manager = new DocsManager();

$manager->addFile(
    'Name of the file', 
    '/path/to/file.md',
    '(Unique file ID)'
);

use Mistralys\MarkdownViewer\DocsViewer;
use Mistralys\MarkdownViewer\DocsManager;

$manager = new DocsManager();

// Configure the files

(new DocsViewer($manager, '/url/to/vendor'))
    ->setTitle('Documentation')
    ->makeDarkMode()
    ->display();

use Mistralys\MarkdownViewer\DocsManager;
use Mistralys\MarkdownViewer\DocsConfig;

$config = (new DocsConfig())
    ->addIncludePath(__DIR__.'/documentation/

{

use Mistralys\MarkdownViewer\DocsConfig;

$config = (new DocsConfig())
    ->addIncludePath('/documentation/

use Mistralys\MarkdownViewer\DocsConfig;

$config = (new DocsConfig())
    ->addIncludeExtension('php');

use Mistralys\MarkdownViewer\DocsConfig;

$extensions = array(
    'php',
    'js',
    'css'
);

$config = (new DocsConfig())
    ->addIncludeExtensions($extensions);

use Mistralys\MarkdownViewer\DocsConfig;

// Allow files up to 12Kb (12.000 bytes)
$config = (new DocsConfig())
    ->setMaxIncludeSize(12000);



declare(strict_types=1);

use AppUtils\FileHelper\FileInfo;
use Mistralys\MarkdownViewer\DocFile;
use Mistralys\MarkdownViewer\DocsConfig;
use Mistralys\MarkdownViewer\Parser\BaseIncludeFilter;

class ExampleIncludeFilter extends BaseIncludeFilter
{
    public function getExtensions(): array
    {
        return array('example');
    }
    
    public function isValidFor(DocFile $sourceFile, DocsConfig $config, FileInfo $


use Mistralys\MarkdownViewer\DocsConfig;

$config = (new DocsConfig())
    ->addIncludeFilter(new ExampleIncludeFilter());



declare(strict_types=1);

use AppUtils\FileHelper\FileInfo;
use Mistralys\MarkdownViewer\DocFile;
use Mistralys\MarkdownViewer\DocsConfig;
use Mistralys\MarkdownViewer\Parser\BaseIncludeFilter;

class ExampleIncludeFilter extends BaseIncludeFilter
{
    public function isValidFor(DocFile $sourceFile, DocsConfig $config, FileInfo $

\{