PHP code example of jifish / parsedown-toc-ext

1. Go to this page and download the library: Download jifish/parsedown-toc-ext 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/ */

    

jifish / parsedown-toc-ext example snippets


use jifish\ParsedownTocExt\ParsedownToc;

$parser = new ParsedownToc();

$html = $parser->text($markdown);
$toc = $parser->getToc();
$tocText = $parser->renderToc();

use jifish\ParsedownTocExt\ParsedownExtraToc;
$parser = new ParsedownExtraToc();

$html = $parser->text($markdown);
$html = str_replace("[TOC]", $parser->renderToc(), $html);

use jifish\ParsedownTocExt\ParsedownToc;

class ParsedownTocCustomId extends ParsedownToc
{
    // Generate random ids
    protected function slugify(string $text): string
    {
        return uniqid();
    }
}

$parser = new ParsedownTocCustomId();

[
    'heading-id' => [
        'level' => 2,
        'text'  => 'Heading Text',
    ],
]

renderToc(
    bool $asHtml = false,
    bool $collapseSkippedLevels = false,
    ?int $maxDepth = null,
    bool $numbered = false,
    bool $excludeFirstHeading = false
): string

  echo $parser->renderToc(asHtml: true);
  

$parser = new ParsedownToc();

$parser->addHeader(2, 'Installation');
$parser->addHeader(3, 'Windows');
$parser->addHeader(3, 'Linux');

echo $parser->getTocText();