l3aro / html-toc
从HTML生成目录表,适用于PHP
v1.2
2024-09-29 12:58 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- knplabs/knp-menu: ^3.5
- masterminds/html5: ^2.9
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
这是一个PHP包,可以从HTML生成目录表。
安装
您可以通过composer安装此包
composer require l3aro/html-toc
使用方法
使用依赖注入
use l3aro\HtmlToc\HtmlToc; public function show(HtmlToc $toc) { $content = <<<HTML <h2>This is heading H2</h2> <h3>This is heading H3</h3> <h4>This is heading H4</h4> <h2>This is heading H2</h2> HTML; $markup = $toc->from($content); $markupContent = $markup->getMarkup(); $tableOfContent = $markup->getTableOfContent(); $htmlOut = "<div class='content'>" . $markupContent . "</div>"; $htmlOut .= "<div class='toc'>" . $tableOfContent . "</div>"; return $htmlOut; }
使用外观模式
use l3aro\HtmlToc\Facades\HtmlToc; public function show() { $content = <<<HTML <h2>This is heading H2</h2> <h3>This is heading H3</h3> <h4>This is heading H4</h4> <h2>This is heading H2</h2> HTML; $markup = HtmlToc::from($content); $markupContent = $markup->getMarkup(); $tableOfContent = $markup->getTableOfContent(); $htmlOut = "<div class='content'>" . $markupContent . "</div>"; $htmlOut .= "<div class='toc'>" . $tableOfContent . "</div>"; return $htmlOut; }
测试
composer test
变更日志
请参阅 变更日志 了解最近的变化信息。
贡献
请参阅 贡献指南 了解详情。
安全漏洞
请查看 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。请参阅 许可证文件 了解更多信息。