l3aro/html-toc

从HTML生成目录表,适用于PHP

v1.2 2024-09-29 12:58 UTC

This package is auto-updated.

Last update: 2024-09-29 13:00:26 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这是一个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)。请参阅 许可证文件 了解更多信息。