承接 camoo/toc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

camoo/toc

Composer 安装命令:

composer create-project camoo/toc

包简介

Generates table of Contents from Text

README 文档

README

Build Status

Feature

This package parses a Html content with H-tags and generate Table of Contents with anchors in your content.

Installation:

  composer require camoo/toc

Usage

        $toc = new TableOfContents('<h1>Html Content</h1>');
		// get only table of contents part
        $onlyTableOfContents = $toc->getTableOfContents();

		// get full content with table of contents included
        $fullContent = $toc->getContent();

Basic Example:

$htmlContent = <<<END
    <h1>This is a header tag h1</h1>
    <p>Lorum ipsum doler sit amet</p>
    <h2>This is a header tag h2</h2>
    <p>Foo Bar</p>
    <h3>This is a header tag h3</h3>
END;

$toc = new TableOfContents($htmlContent);

$fullHtml  = $toc->getContent();


echo $fullHtml;

This produces the following output:

<h1 id="toc-header">Table of Contents</h1>
<hr />
<div>
    <ul>
        <li>
            <a href="#toc-0">This is a header tag h1</a>
            <ul>
                <li>
                    <a href="#toc-1">This is a header tag h2</a>
                    <ul>
                        <li><a href="#toc-2">This is a header tag h3</a></li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</div>
<hr />
<h1><a href="#" name="toc-0"></a>This is a header tag h1</h1>
<p>Lorum ipsum doler sit amet</p>
<h2><a href="#" name="toc-1"></a>This is a header tag h2</h2>
<p>Foo Bar</p>
<h3><a href="#" name="toc-2"></a>This is a header tag h3</h3>

pecifying Heading Levels to Include

You can choose to include only specific h1...h6 heading levels in your TOC. By default the script is parsing h1-h6. To do this, pass the optional parameter $depth to the constructor

$htmlContent = '<h1>Tester</h1><b>Bold</b><h2>Sub-Test</h2><a href="#">link</a><h3>3rd Level</h3><h4>4rd level</h4>';

// Get TOC using h1-h3
$toc = new TableOfContents($htmlContent,3);

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固