Download the PHP package alirezasedghi/laravel-toc without Composer
On this page you can find all versions of the php package alirezasedghi/laravel-toc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alirezasedghi/laravel-toc
More information about alirezasedghi/laravel-toc
Files in alirezasedghi/laravel-toc
Package laravel-toc
Short Description Table of contents for Laravel
License MIT
Informations about the package laravel-toc
Laravel TOC Generator
A Laravel package to generate a Table of Contents (TOC) from HTML headings (h1, h2, ... h6
). This package allows you to create a dynamic TOC with customizable options, including the list type (ul or ol), HTML classes, and level filtering.
Features
- Automatic TOC generation from HTML headings.
- Configurable heading levels to include (
h1
toh6
). - Customizable list types (ul, ol) and HTML classes for TOC structure.
- Customizable HTML classes for the TOC list and items.
- Adds unique
id
attributes to headings for internal linking.
Installation
Install the package via Composer:
Usage
Basic Usage
Here’s how to use the package to generate a Table of Contents and return both the TOC and the processed HTML content.
In your Blade template (resources/views/page.blade.php
):
Custom Options
You can customize the TOC generation by passing an options array. The following options are available:
list_type
: The type of list to use for the TOC (ul
for unordered,ol
for ordered).toc_class
: The CSS class for the main TOC list (<ul>
or<ol>
).internal_list_class
: The CSS class for internal nested lists.toc_item_class
: The CSS class for each item (<li>
) in the TOC.toc_link_class
: The CSS class for each link (<a>
) in the TOC.heading_class
: A CSS class to add to each heading (h1
,h2
, etc.) in the HTML content.min_level
: The minimum heading level to include in the TOC (e.g.,1
forh1
).max_level
: The maximum heading level to include in the TOC (e.g.,6
forh6
).
Example with Custom Options
Available Options
Option | Type | Default | Description |
---|---|---|---|
list_type |
string | 'ul' |
Type of list for TOC (ul for unordered, ol for ordered) |
toc_class |
string | 'toc' |
CSS class for the main TOC list |
internal_list_class |
string | '' |
CSS class for internal nested lists |
toc_item_class |
string | '' |
CSS class for each <li> inside the TOC |
toc_link_class |
string | '' |
CSS class for each link (<a> ) inside the TOC |
heading_class |
string | '' |
CSS class added to each heading (h1 -h6 ) |
min_level |
int | 1 |
Minimum heading level to include (e.g., 1 for h1 ) |
max_level |
int | 6 |
Maximum heading level to include (e.g., 6 for h6 ) |
Example Blade Template
Here’s how you can render both the TOC and the processed HTML content in a Blade view:
Output Example
Given the HTML:
Generated TOC:
License
This package is open-sourced software licensed under the MIT license.