PHP code example of keinos / parsedown-toc

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

    

keinos / parsedown-toc example snippets




// Include the Parsedown and the ToC extension
le
$inputMarkdown = <<<EOL
# Head1
Sample text of head 1.
## Head1-1
Sample text of head 1-1.
# Head2
Sample text of head 2.
## 見出し2-1
Sample text of head2-1.
EOL;

// Instanciate the Parsedown with ToC extension
$parser = new \ParsedownToc();

// Get the parsed HTML
$html = $parser->text($inputMarkdown);

// Get the Table of Contents in HTML
$tocHTML = $parser->contentsList('html');

// Print the parsed HTML and ToC
echo $html . PHP_EOL;
echo "---" . PHP_EOL;
echo $tocHTML . PHP_EOL;



// Include the Parsedown, ParsedownExtra and ToC extension
;

// Extended markdown data sample
$textMarkdown = <<<EOL
# Head1 {#self-defined-head1}

You can  {#self-defined-head2-1}

You can customize the anchor IDs of non-ASCII characters, such as Japanese characters, to more readable ones.

EOL;

// Instanciate the Parsedown with ToC extension
$parser = new \ParsedownToc();

// Get the parsed HTML
$html = $parser->text($textMarkdown);

// Get the Table of Contents
$ToC  = $parser->contentsList();

echo $html . PHP_EOL;
echo "---" . PHP_EOL;
echo $ToC . PHP_EOL;

$ cat ./parse_sample.php

]' tag AMPLE.md');

$parser = new \ParsedownToC();

// Parse Markdown and the '[toc]' tag to HTML
$html = $parser->text($text_markdown);

echo $html . PHP_EOL;

bash
https://KEINOS.github.io/parsedown-extension_table-of-contents/Extension.php
bash
# Download via cURL
curl -O https://KEINOS.github.io/parsedown-extension_table-of-contents/Extension.php
bash
# Download via PHP
php -r "copy('https://KEINOS.github.io/parsedown-extension_table-of-contents/Extension.php', './Extension.php');"