Package Data | |
---|---|
Maintainer Username: | alutskevich |
Maintainer Contact: | karantin91@gmail.com (Andrii Lutskevich) |
Package Create Date: | 2017-03-26 |
Package Last Update: | 2024-06-05 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:04:25 |
Package Statistics | |
---|---|
Total Downloads: | 27 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 3 |
Total Forks: | 2 |
Total Open Issues: | 5 |
Package for generating table of contents for the text.
For example, you have next text:
<h1>Header first level</h1>
Some text here
<h2>Header second level</h2>
Some text here
<h4>Header fourth level</h4>
Some text here
<h3>Header third level</h3>
Some text here
Table of contents will be:
- Header first level
- Header second level
- Header fourth level
- Header third level
Table of contents support how strict headers nesting and free nesting, i.e. it can be: 1-2-4-3-6-2-4-1-3-7 or 1-2-3-2-4-1-2-3-4-3-5-2-3.
Table of contents work with only <h*>
tags 1-10 levels (h1
- h10
).
PHP 7.1
"lutdev/table-contents": "^2.1"
Or install it by running this command in your project root:
composer require lutdev/table-contents
use Lutdev\TOC\TableContents
or you can download package and include it via require
$tableContents = new TableContents();
//return string table contents
$tableContents->tableContents($text);
Table of contents have next structure:
"0": {
"title": "Title",
"link": "link"
},
"1": {
"title": "Title",
"link": "link"
},
"2": {
"title": "Title",
"link": "link"
"subItems": {
"3": {
"title": "Title",
"link": "link"
"subItems": {
"1": {
"subItems": {
"2": {
"subItems": {
"4": {
"title": "Title",
"link": "link"
},
}
}
}
}
}
}
}
}
<link>-<number>
(for example: link-1, link-2, link-3).//Add ID attribute to the headers. Need for anchors.
$tableContents->headerLinks($text)
Thank you! If you have proposition or find error/bug write me, please.
MIT