Download the PHP package baraja-core/table-of-content without Composer

On this page you can find all versions of the php package baraja-core/table-of-content. 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 table-of-content

Table of Content

A lightweight PHP library for automatically generating a Table of Contents from HTML article content. The library parses your HTML, extracts headings, creates anchor links, and provides structured data for building navigation.

🎯 Key Features

🏗️ Architecture Overview

The library consists of two main components working together:

🔧 Components

ContentManager

The main service class responsible for parsing HTML content. It provides a single public method:

Processing steps:

  1. Scans for all <h2> tags in the content
  2. For each heading, generates a URL-friendly ID using Nette\Utils\Strings::webalize()
  3. Injects an anchor <div> element before each heading for smooth scroll navigation
  4. Extracts the page title from the first <h1> tag
  5. Extracts the perex (lead paragraph) from the first <p> tag
  6. Returns all data wrapped in an immutable Response object

Response

An immutable data transfer object implementing Stringable. When cast to string, it returns the processed content with anchors.

Available methods:

Method Return Type Description
getOriginal() string Returns the original unmodified HTML input
getContent() string Returns HTML with injected anchor elements
getPureContent() string Returns content without the <h1> title tag
getTitle() ?string Returns the extracted title or null
getPerex() ?string Returns the extracted perex or null
getItems() array<string, string> Returns anchor ID to heading title mapping

📦 Installation

It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.

To install, simply use the command:

You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.

Requirements

🚀 Basic Usage

Simple Example

Accessing Parsed Data

Rendering the Table of Contents

Using Response as String

The Response object implements Stringable, so you can use it directly where a string is expected:

📸 Visual Examples

Response Entity Structure

The following image shows the structure of the Response object after parsing:

Rendered Table of Contents

Example of how a rendered table of contents looks in a real application:

💡 How Anchor Generation Works

When the parser encounters an <h2> heading like:

It transforms it to:

The anchor ID is generated using Nette\Utils\Strings::webalize() which:

This ensures clean, URL-friendly anchor IDs that work reliably across all browsers.

🔒 Security

The library implements proper XSS protection:

⚙️ Integration with Nette Framework

For Nette Framework users, you can register the service in your configuration:

Then inject it into your presenters or services:

🎨 Styling Recommendations

For smooth scroll behavior to anchors, add this CSS:

👤 Author

Jan Barasek

📄 License

baraja-core/table-of-content is licensed under the MIT license. See the LICENSE file for more details.


All versions of table-of-content with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
nette/utils Version ^3.0
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 baraja-core/table-of-content contains the following files

Loading the files please wait ...