|
8 | 8 |
|
9 | 9 | Listing Table of Contents Extension for [Parsedown](http://parsedown.org/). |
10 | 10 |
|
11 | | -This [simple PHP file](https://github.com/KEINOS/parsedown-extension_table-of-contents/blob/master/Extension.php) extends [Parsedown Vanilla](https://github.com/erusev/parsedown) / [Parsedown Extra](https://github.com/erusev/parsedown-extra) to generate a list of header index (a.k.a. Table of Contents or ToC), from a markdown text given. |
| 11 | +This [simple PHP file](https://github.com/KEINOS/parsedown-extension_table-of-contents/blob/master/Extension.php) extends [Parsedown Vanilla](https://github.com/erusev/parsedown) / [ParsedownExtra](https://github.com/erusev/parsedown-extra) to generate a list of header index (a.k.a. Table of Contents or ToC), from a markdown text given. |
12 | 12 |
|
13 | 13 | - For PHP 8.3+ users: see [supported PHP version](#requirements) for more details. |
14 | 14 |
|
15 | 15 | ## Basic Usage |
16 | 16 |
|
| 17 | +<details><summary>Parsedown Vanilla</summary><br /> |
| 18 | + |
17 | 19 | ```php |
18 | 20 | <?php |
19 | 21 |
|
@@ -71,6 +73,86 @@ $ php ./index.php |
71 | 73 | </ul> |
72 | 74 | ``` |
73 | 75 |
|
| 76 | +</details> |
| 77 | + |
| 78 | +<details><summary>Parsedown Extra</summary><br /> |
| 79 | + |
| 80 | +```php |
| 81 | +<?php |
| 82 | + |
| 83 | +// Include the Parsedown, ParsedownExtra and ToC extension |
| 84 | +require_once('Parsedown.php'); |
| 85 | +require_once('ParsedownExtra.php'); |
| 86 | +require_once('Extension.php'); |
| 87 | + |
| 88 | +// Extended markdown data sample |
| 89 | +$textMarkdown = <<<EOL |
| 90 | +# Head1 {#self-defined-head1} |
| 91 | + |
| 92 | +You can include inline HTML tags<br>in the markdown text. |
| 93 | + |
| 94 | +<div markdown="1"> |
| 95 | +And use the markdown syntax inside HTML Blocks. |
| 96 | +</div> |
| 97 | + |
| 98 | +| Header1 | Header2 | |
| 99 | +| ------- | ------- | |
| 100 | +| Table syntax | as well | |
| 101 | + |
| 102 | +## 見出し2 {#self-defined-head2-1} |
| 103 | + |
| 104 | +You can customize the anchor IDs of non-ASCII characters, such as Japanese characters, to more readable ones. |
| 105 | + |
| 106 | +EOL; |
| 107 | + |
| 108 | +// Instanciate the Parsedown with ToC extension |
| 109 | +$parser = new \ParsedownToc(); |
| 110 | + |
| 111 | +// Get the parsed HTML |
| 112 | +$html = $parser->text($textMarkdown); |
| 113 | + |
| 114 | +// Get the Table of Contents |
| 115 | +$ToC = $parser->contentsList(); |
| 116 | + |
| 117 | +echo $html . PHP_EOL; |
| 118 | +echo "---" . PHP_EOL; |
| 119 | +echo $ToC . PHP_EOL; |
| 120 | +``` |
| 121 | + |
| 122 | +```shellsession |
| 123 | +$ php ./index.php |
| 124 | +<h1 id="self-defined-head1" name="self-defined-head1">Head1</h1> |
| 125 | +<p>You can include inline HTML tags<br>in the markdown text.</p> |
| 126 | +<div> |
| 127 | +<p>And use the markdown syntax inside HTML Blocks.</p> |
| 128 | +</div> |
| 129 | +<table> |
| 130 | +<thead> |
| 131 | +<tr> |
| 132 | +<th>Header1</th> |
| 133 | +<th>Header2</th> |
| 134 | +</tr> |
| 135 | +</thead> |
| 136 | +<tbody> |
| 137 | +<tr> |
| 138 | +<td>Table syntax</td> |
| 139 | +<td>as well</td> |
| 140 | +</tr> |
| 141 | +</tbody> |
| 142 | +</table> |
| 143 | +<h2 id="self-defined-head2-1" name="self-defined-head2-1">見出し2</h2> |
| 144 | +<p>You can customize the anchor IDs of non-ASCII characters, such as Japanese characters, to more readable ones.</p> |
| 145 | +--- |
| 146 | +<ul> |
| 147 | +<li><a href="#self-defined-head1">Head1</a> |
| 148 | +<ul> |
| 149 | +<li><a href="#self-defined-head2-1">見出し2</a></li> |
| 150 | +</ul></li> |
| 151 | +</ul> |
| 152 | +``` |
| 153 | + |
| 154 | +</details> |
| 155 | + |
74 | 156 | - For more examples see the [examples](https://github.com/KEINOS/parsedown-extension_table-of-contents/tree/master/examples) directory. |
75 | 157 |
|
76 | 158 | ## Installation |
@@ -172,23 +254,23 @@ $ php ./parse_sample.php |
172 | 254 |
|
173 | 255 | `PardesownToC` itself supports PHP 5.5 up-to current latest PHP 8.4. |
174 | 256 |
|
175 | | -However, the latest stable release of `Parsedown` 1.7.4 do not fully support PHP 8.4. And `Parsedown Extra` 0.8.1 do not fully support PHP 8.2 or later. Which throws deprecation warnings of PHP. |
| 257 | +However, the latest stable release of `Parsedown` 1.7.4 do not fully support PHP 8.4. And `ParsedownExtra` 0.8.1 do not fully support PHP 8.2 or later. Which throws deprecation warnings of PHP. |
176 | 258 |
|
177 | 259 | ### Stable Combination |
178 | 260 |
|
179 | | -To use the stable released version of `Parsedown` 1.7.4 and `Parsedown Extra` 0.8.1, you need to use between PHP 5.5 and PHP 8.1. |
| 261 | +To use the stable released version of `Parsedown` 1.7.4 and `ParsedownExtra` 0.8.1, you need to use between PHP 5.5 and PHP 8.1. |
180 | 262 |
|
181 | 263 | With later PHP versions you will get several deprecation warnings. |
182 | 264 |
|
183 | 265 | | Script Name | Versions | |
184 | 266 | | :-- | :-- | |
185 | 267 | | PHP | [](https://github.com/KEINOS/parsedown-extension_table-of-contents/blob/master/composer.json#L19 "Supported PHP Version") | |
186 | 268 | | Parsedown.php | [](https://github.com/erusev/parsedown/releases "Supported Parsedown Version") <br />SHA256 Hash: `af4a4b29f38b5a00b003a3b7a752282274c969e42dee88e55a427b2b61a2f38f` | |
187 | | -| ParsedownExtra.php | [](https://github.com/erusev/parsedown-extra/releases "Supported Parsedown Extra Version") <br />SHA256 Hash: `b0c6bd5280fc7dc1caab4f4409efcae9fb493823826f7999c27b859152494be7` | |
| 269 | +| ParsedownExtra.php | [](https://github.com/erusev/parsedown-extra/releases "Supported ParsedownExtra Version") <br />SHA256 Hash: `b0c6bd5280fc7dc1caab4f4409efcae9fb493823826f7999c27b859152494be7` | |
188 | 270 |
|
189 | 271 | ### Last-gasp Effort Combination |
190 | 272 |
|
191 | | -We have patched versions of `Parsedown` 1.7.4 and `Parsedown Extra` 0.8.1 to support PHP 8.4, the current latest PHP version. |
| 273 | +We have patched versions of `Parsedown` 1.7.4 and `ParsedownExtra` 0.8.1 to support PHP 8.4, the current latest PHP version. |
192 | 274 |
|
193 | 275 | These patched versions do not have any new features or refactoring made. Only the deprecation warnings from PHP are removed. |
194 | 276 |
|
|
0 commit comments