markdown-to-html-cli 3.7.0 → 3.9.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 CHANGED
@@ -86,6 +86,7 @@ $ npm i markdown-to-html-cli
86
86
  - `dark-mode` - Disable light and dark theme styles button. (default: `true`)
87
87
  - `markdown-style` - Markdown wrapper style.
88
88
  - `markdown-style-theme` - Setting markdown-style light/dark theme. (`dark | light`)
89
+ - `style` - Override default styles. css file path or css string
89
90
 
90
91
  ### Output Parameters
91
92
 
@@ -144,6 +145,7 @@ Options:
144
145
  --style Override default styles. css file path or css string.
145
146
  --markdown-style-theme Setting markdown-style light/dark theme.
146
147
  --markdown-style Markdown wrapper style
148
+ --ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
147
149
  --output, -o Output static pages to the specified directory. Default: "index.html"
148
150
  --source, -s The path of the target file "README.md". Default: "README.md"
149
151
  --title The `<title>` tag is required in HTML documents!
@@ -155,6 +157,8 @@ Example:
155
157
  markdown-to-html --title="Hello World!"
156
158
  markdown-to-html --config="config/conf.json"
157
159
  npx markdown-to-html-cli
160
+ npm markdown-to-html-cli **/*.md
161
+ npm markdown-to-html-cli **/*.md --ignore-file="(test)"
158
162
  npx markdown-to-html-cli --markdown="Hello World!"
159
163
  npx markdown-to-html-cli --no-dark-mode
160
164
  npx markdown-to-html-cli --dark-mode auto
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { ParsedArgs } from 'minimist';
2
- import { Options } from 'rehype-document';
3
- import { RehypeRewriteOptions } from 'rehype-rewrite';
1
+ import { type ParsedArgs } from 'minimist';
2
+ import { type Options } from 'rehype-document';
3
+ import { type RehypeRewriteOptions } from 'rehype-rewrite';
4
4
  export * from './create.js';
5
5
  export * from './utils.js';
6
6
  export interface RunArgvs extends Omit<ParsedArgs, '_'> {
@@ -35,6 +35,8 @@ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
35
35
  author?: string;
36
36
  /** Override default styles */
37
37
  style?: string;
38
+ /** @example `(node_modules)` */
39
+ ignoreFile?: string;
38
40
  }
39
41
  export interface MDToHTMLOptions extends RunArgvs {
40
42
  /** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import minimist from 'minimist';
4
+ import { globSync } from "glob";
4
5
  import { create } from './create.js';
5
6
  import { formatConfig } from './utils.js';
6
7
  export * from './create.js';
@@ -17,6 +18,7 @@ export function run(opts = {}) {
17
18
  default: {
18
19
  version: opts.v || opts.version || false,
19
20
  help: opts.h || opts.help || false,
21
+ ignoreFile: opts.ignoreFile || '(node_modules)',
20
22
  source: opts.s || opts.source || 'README.md',
21
23
  markdown: opts.markdown || '',
22
24
  'markdown-style': 'max-width: 960px;',
@@ -29,12 +31,20 @@ export function run(opts = {}) {
29
31
  console.log(`${cliHelp}${exampleHelp}`);
30
32
  return;
31
33
  }
34
+ const mdFilesPath = globSync([...argvs._], {
35
+ ignore: {
36
+ ignored: p => {
37
+ return (new RegExp(argvs.ignoreFile, 'i')).test(p.fullpath()) || !/\.md$/i.test(p.fullpath());
38
+ },
39
+ },
40
+ });
32
41
  const pkgPath = path.resolve(new URL('../package.json', import.meta.url).pathname);
33
42
  if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
34
43
  const pkg = fs.readJSONSync(pkgPath);
35
44
  console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
36
45
  return pkg.version;
37
46
  }
47
+ // One File
38
48
  if (argvs.source && !argvs.markdown) {
39
49
  argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
40
50
  }
@@ -52,9 +62,21 @@ export function run(opts = {}) {
52
62
  options.document.style.push(options.style);
53
63
  }
54
64
  }
55
- const strMarkdown = create({ ...argvs, ...options });
56
- fs.writeFileSync(output, strMarkdown);
57
- console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
65
+ // One File
66
+ if (mdFilesPath.length === 0) {
67
+ const strMarkdown = create({ ...argvs, ...options });
68
+ fs.writeFileSync(output, strMarkdown);
69
+ console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
70
+ }
71
+ if (mdFilesPath.length > 0) {
72
+ mdFilesPath.forEach((mdFile) => {
73
+ argvs.markdown = fs.readFileSync(path.resolve(mdFile)).toString();
74
+ opts.output = path.resolve(mdFile.replace(/\.md$/i, '.html').replace(/README\.html$/i, 'index.html').replace(/README-(.*)\.html$/i, 'index-$1.html'));
75
+ const strMarkdown = create({ ...argvs, ...options });
76
+ fs.writeFileSync(opts.output, strMarkdown);
77
+ console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), opts.output)}\x1b[0m\n`);
78
+ });
79
+ }
58
80
  }
59
81
  export const cliHelp = `\n Usage: markdown-to-html [options] [--help|h]
60
82
 
@@ -75,12 +97,15 @@ export const cliHelp = `\n Usage: markdown-to-html [options] [--help|h]
75
97
  --output, -o Output static pages to the specified directory. Default: "index.html"
76
98
  --source, -s The path of the target file "README.md". Default: "README.md"
77
99
  --title The \`<title>\` tag is required in HTML documents!
100
+ --ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
78
101
  --version, -v Show version number
79
102
  --help, -h Displays help information.
80
103
  `;
81
104
  export const exampleHelp = `\n Example:
82
105
 
83
106
  \x1b[35mnpm\x1b[0m markdown-to-html-cli
107
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md
108
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md --ignore-file="(test)"
84
109
  \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
85
110
  \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
86
111
  \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m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3C,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACrG,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAW;;;;;;;;;;;;;;;;;;;;;;CAsB9B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAU;;;;;;;;;;;;;;;;;CAiBjC,CAAC"}
package/lib/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { RunArgvs, MDToHTMLOptions } from './index.js';
1
+ import { type RunArgvs, type MDToHTMLOptions } from './index.js';
2
2
  export type Options = Omit<RunArgvs, '_'>;
3
3
  export declare function formatConfig(opts: Options): MDToHTMLOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-to-html-cli",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "license": "MIT",
5
5
  "description": "Command line tool generates markdown as html.",
6
6
  "homepage": "https://jaywcjlove.github.io/markdown-to-html-cli",
@@ -43,6 +43,7 @@
43
43
  "@wcj/markdown-style": "~1.0.9",
44
44
  "@wcj/markdown-to-html": "~2.2.0",
45
45
  "fs-extra": "~11.1.0",
46
+ "glob": "^10.3.10",
46
47
  "minimist": "~1.2.5",
47
48
  "rehype-autolink-headings": "~6.1.0",
48
49
  "rehype-document": "~6.1.0",
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- import minimist, { ParsedArgs } from 'minimist';
4
- import { Options } from 'rehype-document';
5
- import { RehypeRewriteOptions } from 'rehype-rewrite';
3
+ import minimist, { type ParsedArgs } from 'minimist';
4
+ import { type Options } from 'rehype-document';
5
+ import { type RehypeRewriteOptions } from 'rehype-rewrite';
6
+ import { globSync } from "glob";
6
7
  import { create } from './create';
7
8
  import { formatConfig } from './utils';
8
9
 
@@ -41,6 +42,8 @@ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
41
42
  author?: string;
42
43
  /** Override default styles */
43
44
  style?: string;
45
+ /** @example `(node_modules)` */
46
+ ignoreFile?: string;
44
47
  }
45
48
 
46
49
  export interface MDToHTMLOptions extends RunArgvs {
@@ -64,6 +67,7 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
64
67
  default: {
65
68
  version: opts.v || opts.version || false,
66
69
  help: opts.h || opts.help || false,
70
+ ignoreFile: opts.ignoreFile || '(node_modules)',
67
71
  source: opts.s || opts.source || 'README.md',
68
72
  markdown: opts.markdown || '',
69
73
  'markdown-style': 'max-width: 960px;',
@@ -77,15 +81,23 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
77
81
  return;
78
82
  }
79
83
 
84
+ const mdFilesPath = globSync([...argvs._], {
85
+ ignore: {
86
+ ignored: p => {
87
+ return (new RegExp(argvs.ignoreFile, 'i')).test(p.fullpath()) || !/\.md$/i.test(p.fullpath())
88
+ },
89
+ },
90
+ });
80
91
  const pkgPath = path.resolve(new URL('../package.json', import.meta.url).pathname);
81
92
  if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
82
93
  const pkg = fs.readJSONSync(pkgPath);
83
94
  console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
84
95
  return pkg.version;
85
96
  }
97
+ // One File
86
98
  if (argvs.source && !argvs.markdown) {
87
99
  argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
88
- }
100
+ }
89
101
  const options = formatConfig({ ...opts, ...argvs });
90
102
  const output = path.resolve(argvs.output);
91
103
 
@@ -99,10 +111,21 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
99
111
  options.document.style.push(options.style);
100
112
  }
101
113
  }
102
-
103
- const strMarkdown = create({ ...argvs, ...options });
104
- fs.writeFileSync(output, strMarkdown);
105
- console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
114
+ // One File
115
+ if (mdFilesPath.length === 0) {
116
+ const strMarkdown = create({ ...argvs, ...options });
117
+ fs.writeFileSync(output, strMarkdown);
118
+ console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
119
+ }
120
+ if (mdFilesPath.length > 0) {
121
+ mdFilesPath.forEach((mdFile) => {
122
+ argvs.markdown = fs.readFileSync(path.resolve(mdFile)).toString();
123
+ opts.output = path.resolve(mdFile.replace(/\.md$/i, '.html').replace(/README\.html$/i, 'index.html').replace(/README-(.*)\.html$/i, 'index-$1.html'));
124
+ const strMarkdown = create({ ...argvs, ...options });
125
+ fs.writeFileSync(opts.output, strMarkdown);
126
+ console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), opts.output)}\x1b[0m\n`);
127
+ });
128
+ }
106
129
  }
107
130
 
108
131
  export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
@@ -124,6 +147,7 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
124
147
  --output, -o Output static pages to the specified directory. Default: "index.html"
125
148
  --source, -s The path of the target file "README.md". Default: "README.md"
126
149
  --title The \`<title>\` tag is required in HTML documents!
150
+ --ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
127
151
  --version, -v Show version number
128
152
  --help, -h Displays help information.
129
153
  `;
@@ -131,6 +155,8 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
131
155
  export const exampleHelp: string =`\n Example:
132
156
 
133
157
  \x1b[35mnpm\x1b[0m markdown-to-html-cli
158
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md
159
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md --ignore-file="(test)"
134
160
  \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
135
161
  \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
136
162
  \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- import { RunArgvs, MDToHTMLOptions } from './index';
3
+ import { type RunArgvs, type MDToHTMLOptions } from './index';
4
4
 
5
5
  export type Options = Omit<RunArgvs, '_'>
6
6