catmdx 0.1.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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # CatMdX CLI
2
+
3
+ Read markdown efficiently.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # read metadata, TOC and the '#Usage' section from target markdown
9
+ npx catmdx README.md --metadata --toc --section 'Usage'
10
+ ```
11
+
12
+ ## Options
13
+
14
+ ```
15
+ catmdx [file] [options]
16
+
17
+ Arguments:
18
+ path Path to the markdown file, optional with --content or --stdin flag
19
+
20
+ Options:
21
+ -c, --content <content> Markdown content provided as a string
22
+ -i, --stdin Read markdown content from stdin
23
+ -m, --metadata Print metadata from markdown content
24
+ -t, --toc Print table of contents from markdown content
25
+ -s, --section <section> Print specific section from markdown content (e.g. "Introduction" or "#2")
26
+ ```
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '../dist/cli.js';
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,37 @@
1
+ import { n as getTOC, r as walkMarkdown, t as getSection } from "./section-Cw5XNpYg.js";
2
+ import { program } from "commander";
3
+ import { readFile } from "node:fs/promises";
4
+ import { resolve } from "node:path";
5
+
6
+ //#region src/reader.ts
7
+ async function getContent(options) {
8
+ if (options.file) return await readFile(resolve(options.file), "utf-8");
9
+ if (options.content) return options.content;
10
+ const chunks = [];
11
+ for await (const chunk of process.stdin) chunks.push(chunk);
12
+ return Buffer.concat(chunks).toString("utf8");
13
+ }
14
+
15
+ //#endregion
16
+ //#region src/cli.ts
17
+ program.description("Parse and display specific contents of a markdown").argument("[path]", "Path to the markdown file, optional with --content or --stdin flag").option("-c, --content <content>", "Markdown content provided as a string").option("-i, --stdin", "Read markdown content from stdin").option("-m, --metadata", "Print metadata from markdown content").option("-t, --toc", "Print table of contents from markdown content").option("-s, --section <section>", "Print specific section from markdown content (e.g. \"Introduction\" or \"#2\")").action(async (file, options) => {
18
+ if (!options.file && !options.content && !options.stdin) program.addHelpText("after", "\nError: Please provide a file path / markdown content / or the stdin flag").help();
19
+ const content = await getContent({
20
+ ...options,
21
+ file
22
+ });
23
+ const tokens = Array.from(walkMarkdown(content));
24
+ if (!tokens.length) return;
25
+ const contents = [];
26
+ if (options.metadata && tokens[0].type === "metadata") contents.push(`---\n${tokens[0].metadata}\n---`);
27
+ if (options.toc) contents.push(`[TOC]\n${getTOC(tokens)}`);
28
+ if (options.section) {
29
+ const section = getSection(tokens, options.section);
30
+ if (section != null) contents.push(section);
31
+ }
32
+ if (contents.length) console.log(contents.join("\n\n"));
33
+ });
34
+ program.parse(process.argv);
35
+
36
+ //#endregion
37
+ export { };
@@ -0,0 +1,193 @@
1
+ //#region node_modules/.pnpm/marked@17.0.3/node_modules/marked/lib/marked.d.ts
2
+ // Generated by dts-bundle-generator v9.5.1
3
+ type MarkedToken = (Tokens.Blockquote | Tokens.Br | Tokens.Checkbox | Tokens.Code | Tokens.Codespan | Tokens.Def | Tokens.Del | Tokens.Em | Tokens.Escape | Tokens.Heading | Tokens.Hr | Tokens.HTML | Tokens.Image | Tokens.Link | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.Space | Tokens.Strong | Tokens.Table | Tokens.Tag | Tokens.Text);
4
+ type Token = (MarkedToken | Tokens.Generic);
5
+ declare namespace Tokens {
6
+ interface Blockquote {
7
+ type: "blockquote";
8
+ raw: string;
9
+ text: string;
10
+ tokens: Token[];
11
+ }
12
+ interface Br {
13
+ type: "br";
14
+ raw: string;
15
+ }
16
+ interface Checkbox {
17
+ type: "checkbox";
18
+ raw: string;
19
+ checked: boolean;
20
+ }
21
+ interface Code {
22
+ type: "code";
23
+ raw: string;
24
+ codeBlockStyle?: "indented";
25
+ lang?: string;
26
+ text: string;
27
+ escaped?: boolean;
28
+ }
29
+ interface Codespan {
30
+ type: "codespan";
31
+ raw: string;
32
+ text: string;
33
+ }
34
+ interface Def {
35
+ type: "def";
36
+ raw: string;
37
+ tag: string;
38
+ href: string;
39
+ title: string;
40
+ }
41
+ interface Del {
42
+ type: "del";
43
+ raw: string;
44
+ text: string;
45
+ tokens: Token[];
46
+ }
47
+ interface Em {
48
+ type: "em";
49
+ raw: string;
50
+ text: string;
51
+ tokens: Token[];
52
+ }
53
+ interface Escape {
54
+ type: "escape";
55
+ raw: string;
56
+ text: string;
57
+ }
58
+ interface Generic {
59
+ [index: string]: any;
60
+ type: string;
61
+ raw: string;
62
+ tokens?: Token[];
63
+ }
64
+ interface Heading {
65
+ type: "heading";
66
+ raw: string;
67
+ depth: number;
68
+ text: string;
69
+ tokens: Token[];
70
+ }
71
+ interface Hr {
72
+ type: "hr";
73
+ raw: string;
74
+ }
75
+ interface HTML {
76
+ type: "html";
77
+ raw: string;
78
+ pre: boolean;
79
+ text: string;
80
+ block: boolean;
81
+ }
82
+ interface Image {
83
+ type: "image";
84
+ raw: string;
85
+ href: string;
86
+ title: string | null;
87
+ text: string;
88
+ tokens: Token[];
89
+ }
90
+ interface Link {
91
+ type: "link";
92
+ raw: string;
93
+ href: string;
94
+ title?: string | null;
95
+ text: string;
96
+ tokens: Token[];
97
+ }
98
+ interface List {
99
+ type: "list";
100
+ raw: string;
101
+ ordered: boolean;
102
+ start: number | "";
103
+ loose: boolean;
104
+ items: ListItem[];
105
+ }
106
+ interface ListItem {
107
+ type: "list_item";
108
+ raw: string;
109
+ task: boolean;
110
+ checked?: boolean;
111
+ loose: boolean;
112
+ text: string;
113
+ tokens: Token[];
114
+ }
115
+ interface Paragraph {
116
+ type: "paragraph";
117
+ raw: string;
118
+ pre?: boolean;
119
+ text: string;
120
+ tokens: Token[];
121
+ }
122
+ interface Space {
123
+ type: "space";
124
+ raw: string;
125
+ }
126
+ interface Strong {
127
+ type: "strong";
128
+ raw: string;
129
+ text: string;
130
+ tokens: Token[];
131
+ }
132
+ interface Table {
133
+ type: "table";
134
+ raw: string;
135
+ align: Array<"center" | "left" | "right" | null>;
136
+ header: TableCell[];
137
+ rows: TableCell[][];
138
+ }
139
+ interface TableCell {
140
+ text: string;
141
+ tokens: Token[];
142
+ header: boolean;
143
+ align: "center" | "left" | "right" | null;
144
+ }
145
+ interface TableRow<P = string> {
146
+ text: P;
147
+ }
148
+ interface Tag {
149
+ type: "html";
150
+ raw: string;
151
+ inLink: boolean;
152
+ inRawBlock: boolean;
153
+ text: string;
154
+ block: boolean;
155
+ }
156
+ interface Text {
157
+ type: "text";
158
+ raw: string;
159
+ text: string;
160
+ tokens?: Token[];
161
+ escaped?: boolean;
162
+ }
163
+ }
164
+ //#endregion
165
+ //#region src/walker.d.ts
166
+ type WalkerToken = MarkdownMetadata | MarkdownSectionStart | MarkdownSectionEnd | MarkdownToken;
167
+ interface MarkdownMetadata {
168
+ type: 'metadata';
169
+ metadata: string;
170
+ }
171
+ interface MarkdownSectionStart {
172
+ type: 'section-start';
173
+ path: Tokens.Heading[];
174
+ levelParts: number[];
175
+ startToken: Tokens.Heading;
176
+ }
177
+ interface MarkdownSectionEnd {
178
+ type: 'section-end';
179
+ startToken: Tokens.Heading;
180
+ }
181
+ interface MarkdownToken {
182
+ type: 'token';
183
+ token: Token;
184
+ }
185
+ declare function walkMarkdown(markdown: string): Generator<WalkerToken>;
186
+ //#endregion
187
+ //#region src/toc.d.ts
188
+ declare function getTOC(tokens: WalkerToken[]): string;
189
+ //#endregion
190
+ //#region src/section.d.ts
191
+ declare function getSection(tokens: WalkerToken[], titleOrNumber: string): string;
192
+ //#endregion
193
+ export { MarkdownMetadata, MarkdownSectionEnd, MarkdownSectionStart, MarkdownToken, WalkerToken, getSection, getTOC, walkMarkdown };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { n as getTOC, r as walkMarkdown, t as getSection } from "./section-Cw5XNpYg.js";
2
+
3
+ export { getSection, getTOC, walkMarkdown };