PHPackages                             laravelista/sherlock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. laravelista/sherlock

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

laravelista/sherlock
====================

Deduct a markdown document and get a specific chapter and/or a table of content.

0.5.3(9y ago)75142MITPHPPHP &gt;=7.0.0

Since Sep 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/laravelista/sherlock)[ Packagist](https://packagist.org/packages/laravelista/sherlock)[ RSS](/packages/laravelista-sherlock/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (12)Used By (0)

Sherlock
========

[](#sherlock)

[![Latest Stable Version](https://camo.githubusercontent.com/1b85c1808ec30ee2ede57c6a770bd8e094a158cfce90414d042a02975bf3a075/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c697374612f736865726c6f636b2f762f737461626c65)](https://packagist.org/packages/laravelista/sherlock)[![Total Downloads](https://camo.githubusercontent.com/0719a5b6e199d843163c5ed15ec97bd0404dedde108d9d519989181344e41394/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c697374612f736865726c6f636b2f646f776e6c6f616473)](https://packagist.org/packages/laravelista/sherlock)[![License](https://camo.githubusercontent.com/cdbbbff71e90f991fab958565b56728f2d75ba649138f1b831e509e214b2fb2f/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c697374612f736865726c6f636b2f6c6963656e7365)](https://packagist.org/packages/laravelista/sherlock)[![Build Status](https://camo.githubusercontent.com/a14991ffcc3556830f1380f04cfab7773f90940ac6090095f788ee90eca6d7e2/68747470733a2f2f7472617669732d63692e6f72672f6c61726176656c697374612f736865726c6f636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/laravelista/sherlock)

[![forthebadge](https://camo.githubusercontent.com/3f1084b532348df188718ed6a95dbe5bb479d672b97f6ae689a3f485237c12db/687474703a2f2f666f7274686562616467652e636f6d2f696d616765732f6261646765732f6675636b2d69742d736869702d69742e737667)](http://forthebadge.com)[![forthebadge](https://camo.githubusercontent.com/5d1b13674f245aa03b93407808aec25bbe5d2948523d10c57f6bae20e9fe8597/687474703a2f2f666f7274686562616467652e636f6d2f696d616765732f6261646765732f6e6f2d726167726574732e737667)](http://forthebadge.com)

Sherlock is a PHP package that provides unique features for markdown.

It can create a Table of Content or retrieve a specific chapter.

Overview
--------

[](#overview)

I use this package on my website [Laravelista](https://laravelista.com) to create table of content for my lessons, posts and packages. Also, I use it to provide free samples of my lessons.

### Get the Table of Content

[](#get-the-table-of-content)

Given this markdown:

```
# Book Title

## Chapter 1

This is chapter *one*.

## Chapter 2

This is chapter two.
```

You can generate a table of content:

```
use Laravelista\Sherlock\Sherlock;

$sherlock = new Sherlock;

return $sherlock->deduct($markdown)->getToc();
```

**HTML Output:**

```

    Book Title

            Chapter 1
            Chapter 2

```

### Get a specific chapter

[](#get-a-specific-chapter)

Given the same markdown as in the sample above we can fetch a specific chapter from our markdown documents by its name.

```
use Laravelista\Sherlock\Sherlock;

$sherlock = new Sherlock;

return $sherlock->deduct($markdown)->get('Chapter 1');
```

**Markdown output:**

```
This is chapter *one*.
```

### Laravel usage inside views

[](#laravel-usage-inside-views)

If you are using Laravel, there is a convenient way of loading Sherlock in your views. At the top of your view file where you want to display the Table of Content add this code to inject Sherlock and deduct the content:

```
@inject('sherlock', 'Laravelista\Sherlock\Sherlock')
deduct($lesson->content) ?>
```

And then in the place where you want to display the actual Table of Content add this:

```
{!! $sherlock->getToc() !!}
```

or to get a specific chapter use `$sherlock->get()`. Just remember that `get()` returns markdown, so be sure to parse the markdown to HTML.

Installation
------------

[](#installation)

From the command line:

```
composer require laravelista/sherlock

```

API
---

[](#api)

### deduct

[](#deduct)

Reads given markdown string and generates an index of the document (Library).

```
$sherlock->deduct(string $content)
```

You can chain this method with other methods from the API, but this method must always be called first. Library can be retrieved if needed with `getLibrary()`.

### getToc

[](#gettoc)

Returns the Table of Content in HTML format.

```
$sherlock->deduct($markdown)->getToc()

```

**Example:**

Given this markdown:

```
# Book Title

## Chapter 1

This is chapter *one*.

## Chapter 2

This is chapter two.
```

it returns this HTML output:

```

    Book Title

            Chapter 1
            Chapter 2

```

### get

[](#get)

Returns markdown for specific chapter.

```
$sherlock->deduct($markdown)->get('Chapter 1')
```

**Example:**

Given this markdown:

```
# Book Title

## Chapter 1

This is chapter *one*.

## Chapter 2

This is chapter two.
```

it returns this Markdown output:

```
This is chapter *one*.
```

### getLibrary

[](#getlibrary)

It returns the index of the document (Library); which was deducted from the given markdown in `deduct()` method; as an array.

```
$sherlock->deduct($markdown)->getLibrary()
```

**Example:**

This is a sample of the Library you get:

```
[
    [
        'level' => 1,
        'name' => 'This is the document title',
        'starts_at' => 0,
        'ends_at' => 3,
        'slug' => 'this-is-the-document-title'
    ],
    [
        'level' => 2,
        'name' => 'Introduction',
        'starts_at' => 4,
        'ends_at' => 7,
        'slug' => 'introduction'
    ],
    [
        'level' => 3,
        'name' => 'Another introduction',
        'starts_at' => 8,
        'ends_at' => 11,
        'slug' => 'another-introduction'
    ],
    [
        'level' => 4,
        'name' => 'Deep introduction',
        'starts_at' => 12,
        'ends_at' => 19,
        'slug' => 'deep-introduction'
    ],
    [
        'level' => 2,
        'name' => 'Plot',
        'starts_at' => 20,
        'ends_at' => 23,
        'slug' => 'plot'
    ],
    [
        'level' => 2,
        'name' => 'Conclusion',
        'starts_at' => 24,
        'ends_at' => 27,
        'slug' => 'conclusion'
    ],
];
```

With it you can do all sorts of things.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Recently: every ~9 days

Total

11

Last Release

3530d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1839930?v=4)[mabasic](/maintainers/mabasic)[@mabasic](https://github.com/mabasic)

---

Top Contributors

[![mabasic](https://avatars.githubusercontent.com/u/1839930?v=4)](https://github.com/mabasic "mabasic (21 commits)")

---

Tags

laravelmarkdownTOCchapter

### Embed Badge

![Health badge](/badges/laravelista-sherlock/health.svg)

```
[![Health](https://phpackages.com/badges/laravelista-sherlock/health.svg)](https://phpackages.com/packages/laravelista-sherlock)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
