The TOC is an opinionated table of contents generator.

v1.2.1 2024-05-01 11:23 UTC

This package is auto-updated.

Last update: 2024-05-01 11:24:12 UTC


README

code-style run-tests Packagist Version Packagist Downloads Packagist Dependency Version Packagist Stars Packagist License

The TOC is a library for the project document2.

Features

  • Laravel toc
  • Samsung Tizen toc
  • Naver clova ai toc
  • Rhymix toc

Installation

composer require cable8mm/toc

Usage

namespace Cable8mm\Toc;

$markdown = '
- ## Prologue
    - [Release Notes](/docs/{{version}}/releases)
    - [Upgrade Guide](/docs/{{version}}/upgrade)
    - [Contribution Guide](/docs/{{version}}/contributions)
- ## Getting Started
    - [Installation](/docs/{{version}}/installation)
    - [Configuration](/docs/{{version}}/configuration)
';

$lines = Toc::of($markdown)->getLines();

foreach ($lines as $line) {
    // example "- ## Prologue"
    // example "    - [Release Notes](/docs/{{version}}/releases)"
    print $line->getTitle().PHP_EOL;
    //=> "Prologue"
    //=> "Release Notes"
    print $line->getLink().PHP_EOL;
    //=> null
    //=> "/docs/{{version}}/releases"
    print $line->getType().PHP_EOL;
    //=> ItemEnum::section
    //=> ItemEnum::page
    print $line->getDepth().PHP_EOL;
    //=> 1
    //=> 2
}

Testing

composer test

Formatting

composer lint
# Modify all files to comply with the PSR-12.

composer inspect
# Inspect all files to ensure compliance with PSR-12.

License

The Document2 project is open-sourced software licensed under the MIT license.