npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

markdown-doc-tree

v0.2.0

Published

Build interactive documentation trees and printable PDF manuals from numbered Markdown files.

Readme

Markdown Doc Tree

Build interactive documentation trees and printable A4 manuals from the same directory of numbered Markdown files.

Features

  • Numbered Markdown hierarchy
  • Validation with readable diagnostics
  • Missing-parent warnings or strict validation
  • Generated JSON manifest
  • Interactive browser viewer
  • Relative image support
  • Printable A4 PDF generation
  • Framework-independent output
  • Cross-platform CLI for Linux and Windows

Example

docs/
├─ 1_Getting-Started.md
├─ 1.1_Installation.md
├─ 1.2_Configuration.md
├─ 2_Usage.md
├─ 2.1_Embedding.md
└─ images/
   └─ installation.png

These filenames produce:

Getting Started
├─ Installation
└─ Configuration

Usage
└─ Embedding

Installation

Clone the repository and install the dependencies:

npm install
npx playwright install chromium

Quick start

Point the CLI at a directory of numbered Markdown files:

markdown-doc-tree serve ./docs

The command validates the documentation, generates a temporary manifest, starts a local viewer, and opens it in the default browser.

Generate a printable PDF from the same source directory:

markdown-doc-tree pdf ./docs \
  --output ./manual.pdf \
  --title "Documentation Manual"

PDF generation runs locally and requires the installed Playwright Chromium browser. Embedding the viewer in an application does not require Chromium.

Development

Run the test suite:

npm test

Run the tests once:

npm run test:run

Build the TypeScript library:

npm run build

Start the documentation viewer:

npm run viewer:dev

Generate the documentation manifest:

npm run example:manifest

Generate the PDF manual:

npm run example:pdf

CLI

Open a documentation directory in the local viewer:

markdown-doc-tree serve ./docs

Use another port or suppress automatic browser opening:

markdown-doc-tree serve ./docs --port 8080
markdown-doc-tree serve ./docs --no-open

Validate a documentation directory:

markdown-doc-tree validate ./docs

Treat missing parents as errors:

markdown-doc-tree validate ./docs --strict-missing-parents

Generate a manifest:

markdown-doc-tree manifest ./docs

Generate a PDF manual:

markdown-doc-tree pdf ./docs \
  --output ./dist/manual.pdf \
  --title "Customer Manual"

Filename convention

1_Chapter.md
1.1_Section.md
1.1.1_Subsection.md

The numeric prefix defines both ordering and hierarchy.

Markdown documents currently live directly inside the documentation root. Subdirectories are intended for images and other assets.

Missing parents

Missing direct parents are warnings by default.

For example:

2_Usage.md
2.1.1_Advanced.md

The document 2.1.1_Advanced.md is attached to the nearest existing ancestor.

Strict validation rejects this structure:

markdown-doc-tree validate ./docs --strict-missing-parents

Generated manifest

The manifest is a small JSON index used by the browser viewer.

Example:

{
  "version": 1,
  "documents": [
    {
      "id": "1",
      "title": "Getting Started",
      "contentPath": "content/1_Getting-Started.md"
    }
  ],
  "tree": [
    {
      "id": "1",
      "children": []
    }
  ]
}

The generated output keeps the original speaking filenames and preserves the documentation asset structure.

Viewer

The viewer loads the generated manifest, renders the documentation tree, and fetches Markdown documents on demand.

Navigation uses URL hashes:

http://localhost:5173/#1.1

Relative links and images are resolved from the source Markdown file location.

Documentation sources are assumed to be trusted. Raw HTML contained in Markdown is rendered by the viewer.

Embedding the viewer

Install the package and import the viewer entry point once in the consuming application:

import "markdown-doc-tree/viewer";

Then add the Web Component:

<markdown-doc-tree
  manifest-url="/docs/docs-manifest.json"
  navigation-mode="internal"
  initial-document="1"
></markdown-doc-tree>

The viewer supports the following attributes:

| Attribute | Description | | ------------------ | ------------------------------------------------------------------------------------------------------------------------- | | manifest-url | URL of the generated documentation manifest. Defaults to /docs-manifest.json. | | navigation-mode | Navigation behavior. Use internal for embedded viewers or hash for URL-hash navigation. Defaults to internal. | | initial-document | ID of the document selected when the viewer loads. The first manifest document is used when no matching ID is configured. |

The manifest, Markdown files, and referenced assets must be available through HTTP from the consuming application.

Angular integration

Import the viewer once, for example in main.ts:

import "markdown-doc-tree/viewer";

Angular must be configured to accept custom elements.

For a standalone component:

import {
  Component,
  CUSTOM_ELEMENTS_SCHEMA,
} from "@angular/core";

@Component({
  selector: "app-help",
  standalone: true,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  templateUrl: "./help.component.html",
})
export class HelpComponent {
  readonly manifestUrl =
    "/assets/documentation/docs-manifest.json";

  readonly initialDocument = "1";
}

Use attribute bindings in the component template:

<markdown-doc-tree
  [attr.manifest-url]="manifestUrl"
  [attr.initial-document]="initialDocument"
  navigation-mode="internal"
></markdown-doc-tree>

For an NgModule-based application, add CUSTOM_ELEMENTS_SCHEMA to the module instead:

import {
  CUSTOM_ELEMENTS_SCHEMA,
  NgModule,
} from "@angular/core";

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

The generated manifest directory must be copied into Angular's served assets. For example:

src/assets/documentation/
├─ docs-manifest.json
└─ content/
   ├─ 1_Getting-Started.md
   └─ images/
      └─ installation.png

The Web Component does not require Playwright or Chromium. Those dependencies are only used by local PDF generation.

Viewer styling

The viewer uses shadow DOM to isolate its internal styles. Consuming applications can customize the exposed elements through CSS shadow parts.

Example:

markdown-doc-tree {
  min-height: 40rem;
  color: #202124;
  background: #ffffff;
  font-family: Arial, sans-serif;
}

markdown-doc-tree::part(layout) {
  grid-template-columns: 20rem minmax(0, 1fr);
  min-height: 40rem;
}

markdown-doc-tree::part(sidebar) {
  padding: 1.5rem;
  border-right: 1px solid #d0d7de;
  background: #f6f8fa;
}

markdown-doc-tree::part(brand) {
  color: #0b57d0;
  font-size: 1.25rem;
}

markdown-doc-tree::part(navigation-link) {
  border-radius: 0.25rem;
  color: #374151;
}

markdown-doc-tree::part(navigation-link-active) {
  color: #ffffff;
  background: #0b57d0;
  font-weight: 700;
}

markdown-doc-tree::part(document-id) {
  color: inherit;
  opacity: 0.7;
}

markdown-doc-tree::part(content) {
  width: min(75rem, 100%);
  padding: 3rem;
}

The following parts are public:

| Part | Element | | ------------------------ | ---------------------------------------------- | | layout | Root layout container | | sidebar | Navigation sidebar | | brand | Viewer brand heading | | navigation | Navigation element containing the tree | | navigation-list | Each generated navigation list | | navigation-item | Each generated navigation list item | | navigation-link | Every document navigation link | | navigation-link-active | The currently selected document link | | document-id | Numeric document ID displayed before the title | | content | Main Markdown content container |

Multiple matching elements may expose the same part. For example, every nested tree list exposes navigation-list, and every document link exposes navigation-link.

The active link exposes both parts simultaneously:

navigation-link navigation-link-active

This means base link styles can be defined through navigation-link and only the selected state overridden through navigation-link-active.

The host element itself can be styled with the normal markdown-doc-tree selector. This is useful for inherited properties such as fonts and colors, as well as the component's outer height and background.

The content part exposes the Markdown container, but the individual rendered headings, tables, images, code blocks, and other descendants are not separate public parts.

PDF generation

The PDF pipeline is:

validated Markdown
→ combined HTML manual
→ A4 print styling
→ Chromium PDF export

The generated PDF supports:

  • A4 page size
  • title page
  • chapter page breaks
  • Markdown headings
  • lists
  • tables
  • code blocks
  • embedded images

Example scripts

Validate the example documentation:

npm run example:validate

Generate the example manifest:

npm run example:manifest

Generate the example PDF:

npm run example:pdf

Project status

v0.1.0 proves the complete vertical slice:

Markdown + images
→ validation
→ manifest
→ browser viewer
→ printable PDF

See the changelog for released features and the roadmap for planned work.

License

ISC