@qui-cli/markdown 1.1.1 → 1.2.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.2.0](https://github.com/battis/qui-cli/compare/markdown/1.1.2...markdown/1.2.0) (2026-02-22)
6
+
7
+
8
+ ### Features
9
+
10
+ * convert ANSI coloring to markdown ([5828d89](https://github.com/battis/qui-cli/commit/5828d894a37950d89f16003bf2b815543cfa9113))
11
+
12
+ ## [1.1.2](https://github.com/battis/qui-cli/compare/markdown/1.1.1...markdown/1.1.2) (2026-01-18)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * compile against Node.js v24 ([7b06b4f](https://github.com/battis/qui-cli/commit/7b06b4f4ac4f9688719041ab8b1d837b3a0ee214))
18
+
5
19
  ## [1.1.1](https://github.com/battis/qui-cli/compare/markdown/1.1.0...markdown/1.1.1) (2026-01-02)
6
20
 
7
21
 
@@ -1,3 +1,4 @@
1
+ import { Colors } from '@qui-cli/colors';
1
2
  import * as Plugin from '@qui-cli/plugin';
2
3
  export type Configuration = Plugin.Configuration & {
3
4
  /**
@@ -20,7 +21,10 @@ export type Configuration = Plugin.Configuration & {
20
21
  post?: string;
21
22
  /** Whether or not to overwrite an existing file with output. Default: `false` */
22
23
  overwrite?: boolean;
24
+ /** Style configuration options */
25
+ style?: Partial<Record<keyof typeof Colors, [string, string]>>;
23
26
  };
24
27
  export declare const name = "markdown";
25
- export declare function configure(config?: Configuration): void;
28
+ export declare function restyle(text: string): string;
29
+ export declare function configure(proposal?: Configuration): void;
26
30
  export declare function run(): Promise<void>;
package/dist/Markdown.js CHANGED
@@ -1,46 +1,81 @@
1
1
  import { Colors } from '@qui-cli/colors';
2
2
  import { Core } from '@qui-cli/core';
3
- import * as Plugin from '@qui-cli/plugin';
4
3
  import { Root } from '@qui-cli/root';
5
4
  import fs from 'node:fs';
6
5
  import path from 'node:path';
7
6
  import stripAnsi from 'strip-ansi';
8
7
  export const name = 'markdown';
9
- let outputPath = '.';
10
- let fileName = 'usage.md';
11
- let pre = '';
12
- let headingLevelAdjustment = 0;
13
- let post = '';
14
- let overwrite = false;
15
- export function configure(config = {}) {
16
- outputPath = Plugin.hydrate(config.outputPath, outputPath);
17
- fileName = Plugin.hydrate(config.fileName, fileName);
18
- pre = Plugin.hydrate(config.pre, pre);
19
- headingLevelAdjustment = Plugin.hydrate(config.headingLevelAdjustment, headingLevelAdjustment);
20
- post = Plugin.hydrate(config.post, post);
21
- overwrite = Plugin.hydrate(config.overwrite, overwrite);
8
+ const config = {
9
+ outputPath: '.',
10
+ fileName: 'usage.md',
11
+ pre: '',
12
+ headingLevelAdjustment: 0,
13
+ post: '',
14
+ overwrite: false,
15
+ style: {
16
+ value: ['`', '`'],
17
+ keyword: ['*', '*']
18
+ }
19
+ };
20
+ const placeholder = '@';
21
+ export function restyle(text) {
22
+ for (const key of Object.keys(Colors)) {
23
+ const replacement = config.style[key] || config.style.value;
24
+ if (replacement) {
25
+ const [ansiOpen, ansiClose] = Colors[key](placeholder).split(placeholder);
26
+ const [markdownOpen, markdownClose] = replacement;
27
+ let start;
28
+ while ((start = text.indexOf(ansiOpen)) >= 0) {
29
+ const end = text.indexOf(ansiClose, start);
30
+ text =
31
+ text.slice(0, start) +
32
+ markdownOpen +
33
+ text.slice(start + ansiOpen.length, end) +
34
+ markdownClose +
35
+ text.slice(end + ansiClose.length);
36
+ }
37
+ }
38
+ }
39
+ return text;
40
+ }
41
+ export function configure(proposal = {}) {
42
+ for (const key in proposal) {
43
+ if (proposal[key] !== undefined) {
44
+ switch (key) {
45
+ case 'style':
46
+ for (const k of Object.keys(proposal.style || {})) {
47
+ if (proposal.style && proposal.style[k] !== undefined) {
48
+ config.style[k] = proposal.style[k];
49
+ }
50
+ }
51
+ break;
52
+ default:
53
+ config[key] = proposal[key];
54
+ }
55
+ }
56
+ }
22
57
  }
23
58
  export async function run() {
24
- outputPath = path.resolve(Root.path(), outputPath);
25
- if (fs.existsSync(outputPath)) {
26
- if (fs.statSync(outputPath).isFile()) {
27
- if (!overwrite) {
28
- throw new Error(`File ${Colors.url(outputPath)} already exists and will not be overwritten`);
59
+ config.outputPath = path.resolve(Root.path(), config.outputPath);
60
+ if (fs.existsSync(config.outputPath)) {
61
+ if (fs.statSync(config.outputPath).isFile()) {
62
+ if (!config.overwrite) {
63
+ throw new Error(`File ${Colors.path(config.outputPath)} already exists and will not be overwritten`);
29
64
  }
30
65
  }
31
66
  else {
32
- outputPath = path.join(outputPath, fileName);
67
+ config.outputPath = path.join(config.outputPath, config.fileName);
33
68
  }
34
69
  }
35
70
  else {
36
- if (path.extname(outputPath) === '') {
37
- outputPath = path.join(outputPath, fileName);
71
+ if (path.extname(config.outputPath) === '') {
72
+ config.outputPath = path.join(config.outputPath, config.fileName);
38
73
  }
39
- fs.mkdirSync(path.dirname(outputPath), { recursive: true });
74
+ fs.mkdirSync(path.dirname(config.outputPath), { recursive: true });
40
75
  }
41
- fs.writeFileSync(outputPath, `${pre.length ? `${pre}\n` : ''}${adjustHeadingLevel(stripAnsi(Core.usageMarkdown()))
76
+ fs.writeFileSync(config.outputPath, `${config.pre.length ? `${config.pre}\n` : ''}${adjustHeadingLevel(stripAnsi(restyle(Core.usageMarkdown())))
42
77
  .replace('Usage:\n\n```', '## Usage:\n\n```bash')
43
- .replace('#### `-h --help', '## Arguments\n\n#### `-h --help')}${post.length ? `\n${post}` : ''}`);
78
+ .replace('#### `-h --help', '## Arguments\n\n#### `-h --help')}${config.post.length ? `\n${config.post}` : ''}`);
44
79
  }
45
80
  function adjustHeadingLevel(usage) {
46
81
  return usage
@@ -48,7 +83,7 @@ function adjustHeadingLevel(usage) {
48
83
  .map((line) => {
49
84
  const [, heading] = line.match(/^(#+) /) || [];
50
85
  if (heading) {
51
- return line.replace(/^(#+)/, '#'.repeat(heading.length + headingLevelAdjustment));
86
+ return line.replace(/^(#+)/, '#'.repeat(heading.length + config.headingLevelAdjustment));
52
87
  }
53
88
  return line;
54
89
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qui-cli/markdown",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "@qui-cli Plugin: Export usage as markdown",
5
5
  "homepage": "https://github.com/battis/qui-cli/tree/main/packages/markdown#readme",
6
6
  "repository": {
@@ -18,18 +18,18 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "dependencies": {
20
20
  "strip-ansi": "^7.1.2",
21
- "@qui-cli/colors": "3.2.1"
21
+ "@qui-cli/colors": "3.2.3"
22
22
  },
23
23
  "devDependencies": {
24
- "@tsconfig/node20": "^20.1.8",
25
- "@types/node": "^24.10.4",
24
+ "@tsconfig/node24": "^24.0.4",
25
+ "@types/node": "^24.10.13",
26
26
  "commit-and-tag-version": "^12.6.1",
27
- "del-cli": "^6.0.0",
27
+ "del-cli": "^7.0.0",
28
28
  "npm-run-all": "^4.1.5",
29
29
  "typescript": "^5.9.3",
30
- "@qui-cli/root": "3.0.6",
31
- "@qui-cli/plugin": "4.0.0",
32
- "@qui-cli/core": "5.0.2"
30
+ "@qui-cli/core": "6.0.3",
31
+ "@qui-cli/root": "3.1.0",
32
+ "@qui-cli/plugin": "4.1.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@qui-cli/core": ">=4",
@@ -42,6 +42,6 @@
42
42
  "build": "run-s build:*",
43
43
  "build:clean": "run-s clean",
44
44
  "build:compile": "tsc",
45
- "release": "commit-and-tag-version"
45
+ "version": "commit-and-tag-version"
46
46
  }
47
47
  }