Download the PHP package caseyamcl/toc without Composer

On this page you can find all versions of the php package caseyamcl/toc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package toc

PHP TOC Generator

Generates a Table of Contents from H1...H6 Tags in HTML Content

Latest Version on Packagist Github Build PHPStan Level 8 Total Downloads

NOTE: This library now requires PHP 7.2 or newer; to retain PHP5-7.1 support, use the following composer directive: composer require caseyamcl/toc ~2.0.0

This package provides a simple, framework-agnostic library to build a Table-of-Contents from HTML markup. It does so by evaluating your H1...H6 tags. It can also automatically add appropriate id anchor attributes to header tags so that in-page links work.

Features:

In the spirit of KISS philosophy, this library makes a few assumptions:

  1. The hierarchy of your content is defined solely by the header (H1...H6) tags. All other tags are ignored when generating the TOC.
  2. The link titles in the Table of Contents match either the title attribute of the header tag, or if there is no title, the (slugified) plaintext body of the header tag.

Installation Options

Install via Composer by including the following in your composer.json file:

{
    "require": {
        "caseyamcl/toc": "^3.0",
    }
}

Or, drop the src folder into your application and use a PSR-4 autoloader to include the files.

Usage

This package contains two main classes:

  1. TOC\MarkupFixer: Adds id anchor attributes to any H1...H6 tags that do not already have any (you can specify which header tag levels to use at runtime)
  2. TOC\TocGenerator: Generates a Table of Contents from HTML markup

Basic Example:

This produces the following output:

Twig Integration

This library includes a Twig extension that enables you to load TOC lists and add anchors to markup from your Twig templates.

In order to enable Twig integration, you must register the TocTwigExtension with your Twig environment:

Specifically, the extension adds a Twig function for generating Table of Contents HTML:

It also provides a function and a filter for ensuring that your content includes anchors for all HTML header tags. They both do the same thing, so choose which one suits your needs best:

Your HTML content may be hard-coded in your Twig Template. An easy way to accommodate this is to make sure the content is surrounded by {% block %}...{% endblock %} tags, and then just pass in that block to the toc function.

For example:

Specifying Heading Levels to Include

You can choose to include only specific h1...h6 heading levels in your TOC. To do this, pass two additional arguments to the TocGenerator::getHtmlMenu() method: $topLevel and $depth. For example:

Most other methods in the package handle these arguments as well:

Twig functions and filters accept these arguments as well:

Customizing Menu Output

You can customize the rendering of lists that the TocGenerator class outputs. By default, TocGenerator uses the KnpMenu ListRenderer class to output the HTML.

You can pass your own instance of the ListRenderer class to TocGenerator::getHtmlMenu(). Or, you can pass in your own renderer (implements Knp\Menu\Renderer\RendererInterface).

For example, you may wish to use different CSS classes for your list items:

Customizing with Twig

The KnpMenu library offers more robust integration with the Twig Templating System than is offered by default with this library. You can take advantage of it by using the TwigRenderer that is bundled with KnpMenu:

Ordered vs Unordered Lists

The KnpMenu library produces unordered lists (ul) by default. This library contains a custom renderer for ordered lists, whether you're using Twig or not:

Twig Usage:


All versions of toc with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0
ext-dom Version *
masterminds/html5 Version ^2.1
cocur/slugify Version ^3.0|^4.0
knplabs/knp-menu Version ^3.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package caseyamcl/toc contains the following files

Loading the files please wait ....