markdown-chapter-splitter
Skill2 starsChanged 2 months agoMITView on GitHub
Split large Markdown (.md) files into smaller Markdown files, one per chapter. Use this skill whenever the user wants to split, chunk, divide, or reorganize a Markdown file by chapters or headings, especially for books, manuals, long notes, or documentation. Trigger even when the user says "one file per chapter", "split this markdown", or "separa i capitoli" without explicitly naming a skill. When Markdown H1 chapters are missing or unreliable, use this skill to infer chapter starts from text patterns like `CHAPTER 5`, `Chapter One. Title`, `Chapter 3. Title`, or numbered chapter title pairs instead of degrading to generic H2 splitting.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skill-creatorSkill
- ffpa-analyzerSkill
- llm-wiki-managerSkill
- mineru-pdf-to-mdSkill
- pandoc-convertSkill
- skill-security-auditorSkill
- team-kbSkill
- todo-managerSkill
- wbs-generatorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
22 rules. About 0 are common, 10 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use this skill to turn one large Markdown file into a sibling folder of smaller .md files, with one file per top-level chapter.
- Very specific: line 13
Treat only level-1 headings (# Heading) as chapter boundaries.
- Very specific: line 14
Keep nested sections (##, ###, and deeper) inside the same chapter file.
- Very specific: line 15
Write output in a sibling folder named <input-stem>/ (same name as the file without extension) unless the user explicitly asks for a …
- Very specific: line 17
If the source contains content before the first # chapter (frontmatter, title page, preface, introduction), save it as 00-preface.md.
- Distinctive: line 26
If no reliable H1 chapters are found, or only one H1 chapter is found, try the bundled text-chapter heuristic before giving up on chapter …
- Distinctive: line 38
Ask the user instead of assuming if:
- Very specific: line 51
default: <same-directory>/<input-stem>/ (directory named after the file stem, no -chapters suffix)
- Distinctive: line 53
Run the bundled splitter script in default mode first:
- Very specific: line 59
If the user did not request a custom directory, omit --output-dir.
- Distinctive: line 61
Read the script output carefully:
- Very specific: line 62
If it reports Split mode used: TEXT_CHAPTER, accept that result.
- Very specific: line 65
If it reports Split mode used: H1, accept that result.
- Very specific: line 66
If it reports that no reliable H1 or text-chapter sequence was found, explain that the file does not expose reliable chapter boundaries and …
- Very specific: line 69
If the script found exactly one H1 chapter and the user wants to keep that as a single output file, rerun with --allow-single-section.
- Very specific: line 71
Only use --heading-level 2 when the user explicitly asks for section-based splitting by ## instead of real chapter detection.
- Distinctive: line 74
Read the final script output and report:
- Distinctive: line 120
Prefer the bundled script over manual editing so the split stays deterministic.
- Distinctive: line 121
Prefer inferred numbered chapter starts over generic H2 splitting when the text clearly exposes chapter boundaries.
- Distinctive: line 123
Do not degrade from H1 or inferred text chapters to generic H2 splitting unless the user explicitly asked for section-based splitting.
- Distinctive: line 125
Do not delete the original file.
- Distinctive: line 126
If the output directory already exists, it is acceptable to overwrite files with the same generated names, but do not remove unrelated …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Markdown Chapter Splitter
Use this skill to turn one large Markdown file into a sibling folder of smaller .md
files, with one file per top-level chapter.
Default behavior
- Treat only level-1 headings (
# Heading) as chapter boundaries. - Keep nested sections (
##,###, and deeper) inside the same chapter file. - Write output in a sibling folder named
<input-stem>/(same name as the file without extension) unless the user explicitly asks for a different path. - If the source contains content before the first
#chapter (frontmatter, title page, preface, introduction), save it as00-preface.md. - Generate chapter filenames from the chapter title, sanitized for filesystem safety
and prefixed with chapter order, for example:
01-introduction.md02-system-design.md
- Preserve the original chapter heading as the first heading in each chapter file.
- Ignore
#lines inside fenced code blocks so code samples do not create false chapter splits. - If no reliable H1 chapters are found, or only one H1 chapter is found, try the bundled text-chapter heuristic before giving up on chapter splitting.
- The heuristic should recognize common book-style chapter markers such as:
CHAPTER 5followed by a title on the next lineChapter One. Crunching KnowledgeChapter 3. Mapping to Relational Databases## CHAPTER 1 Layered Architecture## 1followed by## WHAT IS DESIGN AND ARCHITECTURE?
- The heuristic should prefer real chapter starts over table-of-contents entries.
When to ask before running
Ask the user instead of assuming if:
- the input file path is missing or ambiguous
- they want split points based on
##or another heading level - they want a custom output directory or naming scheme
- they want frontmatter copied into every chapter file instead of a separate preface file
- they explicitly do not want automatic text-based chapter inference
Workflow
- Resolve the input
.mdfile path and confirm it exists. - Set the output directory:
- default:
<same-directory>/<input-stem>/(directory named after the file stem, no-chapterssuffix) - custom: only if the user explicitly asked for one
- default:
Run the bundled splitter script in default mode first:
python3 "$HOME/.copilot/skills/markdown-chapter-splitter/scripts/split_markdown_by_chapter.py" "<input_file>" --output-dir "<output_dir>"If the user did not request a custom directory, omit
--output-dir.- Read the script output carefully:
- If it reports
Split mode used: TEXT_CHAPTER, accept that result. The script found a reliable numbered chapter sequence in the text and already split on the inferred chapter boundaries. - If it reports
Split mode used: H1, accept that result. - If it reports that no reliable H1 or text-chapter sequence was found, explain
that the file does not expose reliable chapter boundaries and do not degrade to
generic
##splitting automatically. - If the script found exactly one H1 chapter and the user wants to keep that as a
single output file, rerun with
--allow-single-section. - Only use
--heading-level 2when the user explicitly asks for section-based splitting by##instead of real chapter detection.
- If it reports
- Read the final script output and report:
- output directory path
- split mode used (
H1orTEXT_CHAPTER, plusH2only when the user explicitly requested section-based splitting) - number of section files created
- whether a
00-preface.mdfile was created - how many H1 and H2 headings the script detected
- how many text chapter candidates the script detected
Expected result
The result should be a folder containing:
- zero or one
00-preface.md - one
.mdfile for each chosen split section (#by default, inferred text chapters when reliable,##only when the user explicitly asks for section-based splitting) - numerically ordered filenames to preserve the original chapter order
Examples
Example 1:
Input: "Dividi /tmp/architecture.md in un file per capitolo."
Output: The agent creates /tmp/architecture/, writes 00-preface.md if
needed, then 01-...md, 02-...md, and reports the generated files.
Example 2:
Input: "Split /work/book.md into one Markdown file per chapter."
Output: The agent uses the bundled script, keeps ## sections inside each chapter
file, and reports the destination directory.
Example 3:
Input: "Dividi /tmp/manual.md in un file per capitolo."
Output: If the script finds 0 or 1 H1 chapters and no reliable text-based chapter
sequence, the agent explains that the file does not expose real chapter boundaries
and does not fall back automatically to every ## subsection.
Example 4:
Input: "Split /tmp/oreilly-book.md into one file per chapter."
Output: If the file contains plain text chapter markers like CHAPTER 5 and
Events: A Basis for Collaboration, or lines like Chapter One. Crunching
Knowledge, the script automatically uses TEXT_CHAPTER mode instead of falling back
to every ## subsection.
Notes
- Prefer the bundled script over manual editing so the split stays deterministic.
- Prefer inferred numbered chapter starts over generic H2 splitting when the text clearly exposes chapter boundaries.
- Do not degrade from H1 or inferred text chapters to generic H2 splitting unless the user explicitly asked for section-based splitting.
- Do not delete the original file.
- If the output directory already exists, it is acceptable to overwrite files with the same generated names, but do not remove unrelated files.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

