
stitchmd is a tool that stitches together several Markdown files into one large Markdown file, making it easier to maintain larger Markdown files.
It lets you define the layout of your final document in a summary file, which it then uses to stitch and interlink other Markdown files with.

See Getting Started for a tutorial, or Usage to start using it.
Example
Input
markdown
[Install](install.md) the program.
See also, [Overview](#overview).
Output
markdown
[Install](#install) the program.
See also, [Overview](#overview).
Example
Input
markdown

Output
markdown

Example
Input
markdown
- [Introduction](intro.md)
- [Installation](install.md)
Output
```markdown # Introduction
## Installation
```
The following is a non-exhaustive list of use cases where stitchmd may come in handy.
...and more. (Feel free to contribute a PR with your use case.)
This is a step-by-step tutorial to introduce stitchmd.
For details on how to use it, see Usage.
bash
go install go.abhg.dev/stitchmd@latest
For other installation methods, see the Installation section.
bash
echo 'Welcome to my program.' > intro.md
echo 'It has many features.' > features.md
echo 'Download it from GitHub.' > install.md
Alternatively, clone this repository and copy the doc folder.
bash
cat > summary.md << EOF
- [Introduction](intro.md)
- [Features](features.md)
- [Installation](install.md)
EOF
bash
stitchmd summary.md
The output should look similar to the following:
```markdown - Introduction - Features - Installation
# Introduction
Welcome to my program.
## Features
It has many features.
# Installation
Download it from GitHub. ```
Each included document got its own heading matching its level in the summary file.
intro.md and add the following to the bottom:markdown
See [installation](install.md) for instructions.
If you run stitchmd now, the output should change slightly.
```markdown - Introduction - Features - Installation
# Introduction
Welcome to my program. See installation for instructions.
## Features
It has many features.
# Installation
Download it from GitHub. ```
stitchmd recognized the link from intro.md to install.md,
and updated it to point to the # Installation header instead.
Next steps: Play around with the document further:
markdown
- Overview
- [Introduction](intro.md)
- [Features](features.md)
markdown
[Build from source](install.md#build-from-source).
summary.md:```markdown # my awesome program
You can install stitchmd from pre-built binaries or from source.
Pre-built binaries of stitchmd are available for different platforms over a few different mediums.
If you use Homebrew on macOS or Linux, run the following command to install stitchmd:
brew install abhinav/tap/stitchmd
If you use ArchLinux, install stitchmd from AUR using the stitchmd-bin package.
git clone https://aur.archlinux.org/stitchmd-bin.git
cd stitchmd-bin
makepkg -si
If you use an AUR helper like yay, run the following command instead:
yay -S stitchmd-bin
For other platforms, download a pre-built binary from the
Releases page
and place it on your $PATH.
To install stitchmd from source, install Go >= 1.20 and run:
go install go.abhg.dev/stitchmd@latest
stitchmd-action is a GitHub Action that will install and run stitchmd for you in CI. With stitchmd-action, you can set up GitHub Workflows to:
yaml
uses: abhinav/stitchmd-action@v1
with:
mode: check
summary: doc/SUMMARY.md
output: README.md
```yaml uses: abhinav/stitchmd-action@v1 with: mode: write summary: doc/SUMMARY.md output: README.md
# Optionally, use https://github.com/stefanzweifel/git-auto-commit-action # to automatically push these changes. ```
yaml
uses: abhinav/stitchmd-action@v1
with:
mode: install
For more information, see stitchmd-action.
stitchmd [OPTIONS] FILE
stitchmd accepts a single Markdown file as input. This file defines the layout you want in your combined document, and is referred to as the summary file.
For example:
# User Guide
- [Getting Started](getting-started.md)
- [Installation](installation.md)
- [Usage](usage.md)
- [API](api.md)
# Appendix
- [How things work](implementation.md)
- [FAQ](faq.md)
The format of the summary file is specified in more detail in Syntax.
Given such a file as input, stitchmd will print a single Markdown file including the contents of all listed files inline.
Example output
The output of the input file above will be roughly in the following shape:
# User Guide
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
## Getting Started
### Installation
## Usage
## API
# Appendix
- [How things work](#how-things-work)
- [FAQ](#faq)
## How things work
## FAQ
stitchmd supports the following options:
Instead of reading from a specific file on-disk, you can pass in '-' as the file name to read the summary from stdin.
cat summary.md | stitchmd -
-preface FILE
If this flag is specified, stitchmd will include the given file at the top of the output verbatim.
You can use this to add comments holding license headers or instructions for contributors.
For example:
cat > generated.txt <<EOF
EOF
stitchmd -preface generated.txt summary.md
-offset N
stitchmd changes heading levels based on a few factors:
The -offset flag allows you to offset all these headings
by a fixed value.
Example
Input
# User Guide
- [Introduction](intro.md)
- [Installation](install.md)
stitchmd -offset 1 summary.md
Output
## User Guide
- [Introduction](#introduction)
- [Installation](#installation)
### Introduction
### Installation
Use a negative value to reduce heading levels.
Example
Input
# User Guide
- [Introduction](intro.md)
- [Installation](install.md)
stitchmd -offset -1 summary.md
Output
# User Guide
- [Introduction](#introduction)
- [Installation](#installation)
# Introduction
## Installation
-no-toc
stitchmd reproduces the original table of contents in the output.
You can change this with the -no-toc flag.
stitchmd -no-toc summary.md
This will omit the item listing under each section.
Example
Input
- [Introduction](intro.md)
- [Installation](install.md)
stitchmd -no-toc summary.md
Output
# Introduction
# Installation
-o FILE
stitchmd writes its output to stdout by default.
Use the -o option to write to a file instead.
stitchmd -o README.md summary.md
-C DIR
Paths in the summary file are considered relative to the summary file.
Use the -C flag to change the directory
that stitchmd considers itself to be in.
stitchmd -C docs summary.md
This is especially useful if your summary file is passed via stdin
... | stitchmd -C docs -
-d
stitchmd normally writes output directly to the file
if you pass in a filename with -o.
Use the -d flag to instead have it report what would change
in the output file without actually changing it.
stitchmd -d -o README.md # ...
This can be useful for lint checks and similar, or to do a dry run and find out what would change without changing it.
Although the summary file is Markdown, stitchmd expects it in a very specific format.
The summary file is comprised of one or more sections. Sections have a section title specified by a Markdown heading.
Example
# Section 1
# Section 2
If there's only one section, the section title may be omitted.
File = Section | (SectionTitle Section)+
Each section contains a Markdown list defining one or more list items. List items are one of the following, and may optionally have another list nested inside them to indicate a hierarchy.
Example
markdown
- [Overview](overview.md)
- [Getting Started](start/install.md)
.
The included file will be read as another summary file,
a$ claude mcp add stitchmd \
-- python -m otcore.mcp_server <graph>