PHPackages                             matthiasnoback/leanpub-sampler - 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. matthiasnoback/leanpub-sampler

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

matthiasnoback/leanpub-sampler
==============================

A simple script for generating samples for Leanpub books

v0.4.0(9y ago)92.0k3MITPHPPHP ^7.1CI failing

Since Feb 15Pushed 5y ago2 watchersCompare

[ Source](https://github.com/matthiasnoback/leanpub-sampler)[ Packagist](https://packagist.org/packages/matthiasnoback/leanpub-sampler)[ Docs](http://github.com/matthiasnoback/leanpub-sampler)[ RSS](/packages/matthiasnoback-leanpub-sampler/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Leanpub Sampler
===============

[](#leanpub-sampler)

This tool can be used to generate sample text for Leanpub books.

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

[](#installation)

Install with [Composer](https://getcomposer.org/). Add a `composer.json` file to the root of your Leanpub book project (one directory higher than `manuscript/`):

```
{
    "require": {
        "matthiasnoback/leanpub-sampler": "~0.1"
    }
}

```

Then run `composer update`. A `vendor/` directory will be created, containing the Leanpub sampler and its dependencies.

Usage
-----

[](#usage)

First you need to edit your manuscript files and add markers for the sample texts:

```
# A regular chapter

## A regular section

Some text.

%% begin sample

## A sample section

Some sample text.

%% end sample

```

Then run:

```
php vendor/bin/generate-sample.php

```

The sampler will generate sample text based on the `%% begin sample` and `%% end sample` markers. It scans all `.txt` or `.md` files inside the `manuscript/` directory, including its subdirectories.

The result is a new file, `manuscript/sample-text.txt`, that contains all the sample text.

### Add all section titles (parts, chapters, sections)

[](#add-all-section-titles-parts-chapters-sections)

Using the command-line option `--all-sections` or `-s` you can instruct the sampler to automatically add any part, chapter or section title to the sample text:

```
php vendor/bin/generate-sample.php -s

```

This is useful if you want to preserve the original structure of your manuscript in the generated sample file. It is also useful because if all the part, chapter and section titles are present in the sample file, Leanpub will add the full table of contents to the generated preview file.

### Last step: mention `sample-text.txt` in `Sample.txt`

[](#last-step-mention-sample-texttxt-in-sampletxt)

When Leanpub generates a preview file, it looks at the `manuscript/Sample.txt` file. All files mentioned there will be added to the generated preview file. Make sure you add the `sample-text.txt` file to the list too:

The contents of `manuscript/Sample.txt` should be:

```
sample-text.txt

```

#### Suggestions

[](#suggestions)

The Leanpub sampler scans the manuscript files in alphabetical order. So to preserve initial order, it's best to sort your manuscript files alphabetically too, like:

```
00-chapter1.txt
01-chapter2.txt
...

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% 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 ~283 days

Total

5

Last Release

3386d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1193078?v=4)[Matthias Noback](/maintainers/matthiasnoback)[@matthiasnoback](https://github.com/matthiasnoback)

---

Top Contributors

[![matthiasnoback](https://avatars.githubusercontent.com/u/1193078?v=4)](https://github.com/matthiasnoback "matthiasnoback (19 commits)")[![benoitMariaux](https://avatars.githubusercontent.com/u/716856?v=4)](https://github.com/benoitMariaux "benoitMariaux (1 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (1 commits)")

---

Tags

markdownleanpub

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matthiasnoback-leanpub-sampler/health.svg)

```
[![Health](https://phpackages.com/badges/matthiasnoback-leanpub-sampler/health.svg)](https://phpackages.com/packages/matthiasnoback-leanpub-sampler)
```

###  Alternatives

[erusev/parsedown

Parser for Markdown.

15.1k155.2M843](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k437.5M950](/packages/league-commonmark)[michelf/php-markdown

PHP Markdown

3.5k53.8M371](/packages/michelf-php-markdown)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k31.0M276](/packages/league-html-to-markdown)[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k33.5M146](/packages/cebe-markdown)[erusev/parsedown-extra

An extension of Parsedown that adds support for Markdown Extra.

84315.1M208](/packages/erusev-parsedown-extra)

PHPackages © 2026

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