flatten-tool 1.6.4 → 1.7.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.
Files changed (3) hide show
  1. package/README.md +4 -1
  2. package/index.ts +5 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/flatten-tool)](https://www.npmjs.com/package/flatten-tool)
4
4
 
5
- A CLI utility to flatten directory structures, with perfect GitHub Flavored Markdown compatibility.
5
+ A CLI utility to flatten directory structures, with perfect GitHub Flavored Markdown compatibility including explicit HTML anchors for maximum portability.
6
6
 
7
7
  [![Video thumbnail](https://i.ytimg.com/vi/LCbSoK0Mkjk/maxresdefault.jpg)](https://youtu.be/LCbSoK0Mkjk)
8
8
  *Watch the YouTube video for an example of why you might need to flatten project files into a single document for AI discussions and code reviews.*
@@ -143,6 +143,9 @@ This project uses Bun for runtime, TypeScript for type safety, and follows the g
143
143
 
144
144
  ## Changelog
145
145
 
146
+ ### v1.7.0
147
+ - Added explicit HTML anchors (`<a id="..."></a>`) before all headings for guaranteed compatibility across platforms that don't auto-generate heading IDs, maximum control over anchor names, and stable links.
148
+
146
149
  ### v1.6.3
147
150
  - Enhanced safety: Automatically exclude common binary file extensions (PNG, JPEG, PDF, archives, executables, etc.) when merging to Markdown to prevent corruption.
148
151
  - Added `--ignore` CLI option: Allow additional glob patterns to ignore (e.g., `*.log`, `temp/**`).
package/index.ts CHANGED
@@ -220,7 +220,7 @@ export async function flattenDirectory(
220
220
  }
221
221
 
222
222
  // Render global tree with correct anchors
223
- let treeMarkdown = "# Project File Tree\n\n";
223
+ let treeMarkdown = `<a id="${anchorMap.get('')!}"></a>\n# Project File Tree\n\n`;
224
224
  treeMarkdown += renderMarkdownTree(treeObj, 0, '', anchorMap, null);
225
225
  treeMarkdown += "\n\n";
226
226
 
@@ -259,7 +259,8 @@ export async function flattenDirectory(
259
259
 
260
260
  // Directory section (only for non-root) — no trailing /
261
261
  if (currentPath) {
262
- writeStream.write(`# ${currentPath}\n\n`);
262
+ const anchor = anchorMap.get(currentPath)!;
263
+ writeStream.write(`<a id="${anchor}"></a>\n# ${currentPath}\n\n`);
263
264
  writeStream.write(`File Tree\n\n`);
264
265
 
265
266
  const parentPath = currentPath.includes('/')
@@ -271,7 +272,8 @@ export async function flattenDirectory(
271
272
  }
272
273
 
273
274
  for (const file of files) {
274
- writeStream.write(`# ${file.relPath}\n\n`);
275
+ const anchor = anchorMap.get(file.relPath)!;
276
+ writeStream.write(`<a id="${anchor}"></a>\n# ${file.relPath}\n\n`);
275
277
 
276
278
  let ext = extname(file.srcPath).slice(1) || 'text';
277
279
  const lang = ext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatten-tool",
3
- "version": "1.6.4",
3
+ "version": "1.7.0",
4
4
  "description": "CLI tool to flatten directory structures: merge files into a single Markdown file (default) or copy/move to a flat directory with escaped filenames. Respects .gitignore, supports move/overwrite, and more.",
5
5
  "module": "index.ts",
6
6
  "type": "module",