splitdown 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/index.js +109 -0
- package/package.json +52 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-01-23
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release.
|
|
9
|
+
- CLI tool to split markdown files by headings.
|
|
10
|
+
- Configurable output directory and filename prefix.
|
|
11
|
+
- Unit tests with Vitest.
|
|
12
|
+
- Linting and formatting with ESLint and Prettier.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kaf
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Splitdown
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Split large Markdown files into manageable chunks based on headings. Useful for feeding docs into AI assistants with context window limits.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Split by heading level (h1-h6)
|
|
12
|
+
- Auto-numbered files to preserve order
|
|
13
|
+
- Sanitized, human-readable filenames
|
|
14
|
+
- Configurable output directory and filename prefixes
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx splitdown <input-file> [options]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Examples
|
|
30
|
+
|
|
31
|
+
**Split by H2 headings (default):**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx splitdown README.md
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Split by H1 headings to a specific directory:**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx splitdown docs.md --level 1 --output ./chapters
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
| Option | Alias | Default | Description |
|
|
46
|
+
| ---------- | ----- | ---------------- | ------------------------------- |
|
|
47
|
+
| `--output` | `-o` | `./split-output` | Output directory |
|
|
48
|
+
| `--level` | `-l` | `2` | Heading level to split on (1-6) |
|
|
49
|
+
| `--prefix` | `-p` | `section-` | Filename prefix |
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install
|
|
55
|
+
npm run dev # watch mode
|
|
56
|
+
npm run build # production build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_commander = require("commander");
|
|
28
|
+
var fs2 = __toESM(require("fs"));
|
|
29
|
+
|
|
30
|
+
// src/lib.ts
|
|
31
|
+
var fs = __toESM(require("fs"));
|
|
32
|
+
var path = __toESM(require("path"));
|
|
33
|
+
function parseMarkdownSections(content, level = 2) {
|
|
34
|
+
const lines = content.split("\n");
|
|
35
|
+
const sections = [];
|
|
36
|
+
let currentSection = null;
|
|
37
|
+
lines.forEach((line, index) => {
|
|
38
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
39
|
+
if (headingMatch) {
|
|
40
|
+
const headingLevel = headingMatch[1].length;
|
|
41
|
+
const headingTitle = headingMatch[2];
|
|
42
|
+
if (headingLevel <= level) {
|
|
43
|
+
if (currentSection) {
|
|
44
|
+
sections.push(currentSection);
|
|
45
|
+
}
|
|
46
|
+
currentSection = {
|
|
47
|
+
title: headingTitle,
|
|
48
|
+
level: headingLevel,
|
|
49
|
+
content: line + "\n",
|
|
50
|
+
lineStart: index + 1
|
|
51
|
+
};
|
|
52
|
+
} else if (currentSection) {
|
|
53
|
+
currentSection.content += line + "\n";
|
|
54
|
+
}
|
|
55
|
+
} else if (currentSection) {
|
|
56
|
+
currentSection.content += line + "\n";
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (currentSection) {
|
|
60
|
+
sections.push(currentSection);
|
|
61
|
+
}
|
|
62
|
+
return sections;
|
|
63
|
+
}
|
|
64
|
+
function sanitizeFilename(title) {
|
|
65
|
+
return title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").substring(0, 50);
|
|
66
|
+
}
|
|
67
|
+
function splitMarkdown(inputFile, outputDir, level, prefix) {
|
|
68
|
+
const content = fs.readFileSync(inputFile, "utf-8");
|
|
69
|
+
const sections = parseMarkdownSections(content, level);
|
|
70
|
+
console.log(
|
|
71
|
+
`Found ${sections.length} sections at heading level ${level} or above
|
|
72
|
+
`
|
|
73
|
+
);
|
|
74
|
+
if (!fs.existsSync(outputDir)) {
|
|
75
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
sections.forEach((section, index) => {
|
|
78
|
+
const filename = `${prefix}${String(index + 1).padStart(2, "0")}-${sanitizeFilename(section.title)}.md`;
|
|
79
|
+
const filepath = path.join(outputDir, filename);
|
|
80
|
+
fs.writeFileSync(filepath, section.content.trimEnd());
|
|
81
|
+
console.log(`\u2713 ${filename} (${section.content.split("\n").length} lines)`);
|
|
82
|
+
});
|
|
83
|
+
console.log(`
|
|
84
|
+
Split complete. Files saved to: ${outputDir}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/index.ts
|
|
88
|
+
var program = new import_commander.Command();
|
|
89
|
+
program.name("splitdown").description(
|
|
90
|
+
"Split markdown files by headings for easier sharing with AI assistants"
|
|
91
|
+
).version("1.0.0");
|
|
92
|
+
program.argument("<input>", "input markdown file").option("-o, --output <dir>", "output directory", "./split-output").option("-l, --level <number>", "heading level to split on (1-6)", "2").option("-p, --prefix <string>", "prefix for output filenames", "section-").action((input, options) => {
|
|
93
|
+
try {
|
|
94
|
+
const level = parseInt(options.level, 10);
|
|
95
|
+
if (level < 1 || level > 6) {
|
|
96
|
+
console.error("Error: Heading level must be between 1 and 6");
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
if (!fs2.existsSync(input)) {
|
|
100
|
+
console.error(`Error: File not found: ${input}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
splitMarkdown(input, options.output, level, options.prefix);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error("Error:", error instanceof Error ? error.message : error);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "splitdown",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Split markdown files by headings for easier sharing with AI assistants",
|
|
5
|
+
"bin": {
|
|
6
|
+
"splitdown": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup src/index.ts --format cjs --clean",
|
|
10
|
+
"dev": "tsup src/index.ts --format cjs --watch",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"lint": "eslint . --ext .ts",
|
|
13
|
+
"format": "prettier --write .",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"markdown",
|
|
18
|
+
"cli",
|
|
19
|
+
"split",
|
|
20
|
+
"ai",
|
|
21
|
+
"headings"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/iamkaf/splitdown.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/iamkaf/splitdown/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/iamkaf/splitdown#readme",
|
|
31
|
+
"author": "Kaf",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^11.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.10.0",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
39
|
+
"@typescript-eslint/parser": "^8.53.1",
|
|
40
|
+
"eslint": "^8.57.0",
|
|
41
|
+
"eslint-config-prettier": "^10.1.8",
|
|
42
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
43
|
+
"prettier": "^3.8.1",
|
|
44
|
+
"tsup": "^8.0.1",
|
|
45
|
+
"typescript": "^5.3.3",
|
|
46
|
+
"vitest": "^4.0.18"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"CHANGELOG.md"
|
|
51
|
+
]
|
|
52
|
+
}
|