markdown-to-html-cli 3.8.0 → 3.10.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 +4 -0
- package/lib/create.js +5 -1
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +7 -3
- package/lib/index.js +30 -3
- package/lib/index.js.map +1 -1
- package/lib/nodes/imgBase64.d.ts +1 -0
- package/lib/nodes/imgBase64.js +16 -0
- package/lib/nodes/imgBase64.js.map +1 -0
- package/lib/utils.d.ts +1 -1
- package/package.json +3 -1
- package/src/create.ts +5 -1
- package/src/index.ts +38 -8
- package/src/nodes/imgBase64.ts +17 -0
- package/src/utils.ts +1 -1
package/README.md
CHANGED
|
@@ -142,9 +142,11 @@ Options:
|
|
|
142
142
|
--keywords Define keywords for search engines.
|
|
143
143
|
--no-dark-mode Disable light and dark theme styles button.
|
|
144
144
|
--markdown Markdown string.
|
|
145
|
+
--img-base64 Convert images in HTML to base64.
|
|
145
146
|
--style Override default styles. css file path or css string.
|
|
146
147
|
--markdown-style-theme Setting markdown-style light/dark theme.
|
|
147
148
|
--markdown-style Markdown wrapper style
|
|
149
|
+
--ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
|
|
148
150
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
149
151
|
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
150
152
|
--title The `<title>` tag is required in HTML documents!
|
|
@@ -156,6 +158,8 @@ Example:
|
|
|
156
158
|
markdown-to-html --title="Hello World!"
|
|
157
159
|
markdown-to-html --config="config/conf.json"
|
|
158
160
|
npx markdown-to-html-cli
|
|
161
|
+
npm markdown-to-html-cli **/*.md
|
|
162
|
+
npm markdown-to-html-cli **/*.md --ignore-file="(test)"
|
|
159
163
|
npx markdown-to-html-cli --markdown="Hello World!"
|
|
160
164
|
npx markdown-to-html-cli --no-dark-mode
|
|
161
165
|
npx markdown-to-html-cli --dark-mode auto
|
package/lib/create.js
CHANGED
|
@@ -10,11 +10,12 @@ import rehypeFormat from 'rehype-format';
|
|
|
10
10
|
import { githubCorners } from './nodes/github-corners.js';
|
|
11
11
|
import { githubCornersFork } from './nodes/github-corners-fork.js';
|
|
12
12
|
import { octiconLink } from './nodes/octiconLink.js';
|
|
13
|
+
import { imgBase64 as toBase64 } from './nodes/imgBase64.js';
|
|
13
14
|
import { markdownStyle } from './nodes/markdown-style.js';
|
|
14
15
|
import { copyElement, copyStyle, copyScript } from './nodes/copy.js';
|
|
15
16
|
import { darkMode } from './nodes/dark-mode.js';
|
|
16
17
|
export function create(options = {}) {
|
|
17
|
-
const { markdown: string, document, corners = true, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true, 'markdown-style': wrapperStyle } = options;
|
|
18
|
+
const { markdown: string, document, 'img-base64': imgBase64 = false, corners = true, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true, 'markdown-style': wrapperStyle } = options;
|
|
18
19
|
const mdOptions = {
|
|
19
20
|
hastNode: false,
|
|
20
21
|
remarkPlugins: [remarkGemoji],
|
|
@@ -53,6 +54,9 @@ export function create(options = {}) {
|
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
if (node.type == 'element' && node.tagName === 'img' && imgBase64) {
|
|
58
|
+
node.properties = { ...node.properties, src: toBase64(node.properties.src) };
|
|
59
|
+
}
|
|
56
60
|
if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
|
|
57
61
|
const child = node.children[0];
|
|
58
62
|
if (child && child.type === 'element' && child.properties) {
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,QAAqB,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CA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,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SAC3F;QAED,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;KACpE;IAED,OAAO,QAAQ,CAAC,MAAM,IAAI,EAAE,EAAE,SAAS,CAAW,CAAC;AACrD,CAAC"}
|
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,10 @@ 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;
|
|
40
|
+
/** Convert images in HTML to base64. @default `false` */
|
|
41
|
+
'img-base64'?: boolean;
|
|
38
42
|
}
|
|
39
43
|
export interface MDToHTMLOptions extends RunArgvs {
|
|
40
44
|
/** [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,8 @@ 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)',
|
|
22
|
+
'img-base64': opts.imgBase64 ?? false,
|
|
20
23
|
source: opts.s || opts.source || 'README.md',
|
|
21
24
|
markdown: opts.markdown || '',
|
|
22
25
|
'markdown-style': 'max-width: 960px;',
|
|
@@ -29,12 +32,20 @@ export function run(opts = {}) {
|
|
|
29
32
|
console.log(`${cliHelp}${exampleHelp}`);
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
35
|
+
const mdFilesPath = globSync([...argvs._], {
|
|
36
|
+
ignore: {
|
|
37
|
+
ignored: p => {
|
|
38
|
+
return (new RegExp(argvs.ignoreFile, 'i')).test(p.fullpath()) || !/\.md$/i.test(p.fullpath());
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
32
42
|
const pkgPath = path.resolve(new URL('../package.json', import.meta.url).pathname);
|
|
33
43
|
if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
|
|
34
44
|
const pkg = fs.readJSONSync(pkgPath);
|
|
35
45
|
console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
|
|
36
46
|
return pkg.version;
|
|
37
47
|
}
|
|
48
|
+
// One File
|
|
38
49
|
if (argvs.source && !argvs.markdown) {
|
|
39
50
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
40
51
|
}
|
|
@@ -52,9 +63,21 @@ export function run(opts = {}) {
|
|
|
52
63
|
options.document.style.push(options.style);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
// One File
|
|
67
|
+
if (mdFilesPath.length === 0) {
|
|
68
|
+
const strMarkdown = create({ ...argvs, ...options });
|
|
69
|
+
fs.writeFileSync(output, strMarkdown);
|
|
70
|
+
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
|
|
71
|
+
}
|
|
72
|
+
if (mdFilesPath.length > 0) {
|
|
73
|
+
mdFilesPath.forEach((mdFile) => {
|
|
74
|
+
options.markdown = fs.readFileSync(path.resolve(mdFile)).toString();
|
|
75
|
+
opts.output = path.resolve(mdFile.replace(/\.md$/i, '.html').replace(/README\.html$/i, 'index.html').replace(/README-(.*)\.html$/i, 'index-$1.html'));
|
|
76
|
+
const strMarkdown = create({ ...argvs, ...options });
|
|
77
|
+
fs.writeFileSync(opts.output, strMarkdown);
|
|
78
|
+
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), opts.output)}\x1b[0m\n`);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
58
81
|
}
|
|
59
82
|
export const cliHelp = `\n Usage: markdown-to-html [options] [--help|h]
|
|
60
83
|
|
|
@@ -69,18 +92,22 @@ export const cliHelp = `\n Usage: markdown-to-html [options] [--help|h]
|
|
|
69
92
|
--keywords Define keywords for search engines.
|
|
70
93
|
--no-dark-mode Disable light and dark theme styles button.
|
|
71
94
|
--markdown Markdown string.
|
|
95
|
+
--img-base64 Convert images in HTML to base64.
|
|
72
96
|
--style Override default styles. css file path or css string.
|
|
73
97
|
--markdown-style-theme Setting markdown-style light/dark theme.
|
|
74
98
|
--markdown-style Markdown wrapper style.
|
|
75
99
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
76
100
|
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
77
101
|
--title The \`<title>\` tag is required in HTML documents!
|
|
102
|
+
--ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
|
|
78
103
|
--version, -v Show version number
|
|
79
104
|
--help, -h Displays help information.
|
|
80
105
|
`;
|
|
81
106
|
export const exampleHelp = `\n Example:
|
|
82
107
|
|
|
83
108
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli
|
|
109
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md
|
|
110
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md --ignore-file="(test)"
|
|
84
111
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
|
|
85
112
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
86
113
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAA6B,MAAM,UAAU,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAiDxB,MAAM,UAAU,GAAG,CAAC,OAAO,EAAyB;IAClD,MAAM,KAAK,GAAG,QAAQ,CAAW,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACtD,KAAK,EAAE;YACL,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;SACZ;QACD,OAAO,EAAE;YACP,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,IAAI,K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AAW;;;;;;;;;;;;;;;;;;;;;;;CAuB9B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAU;;;;;;;;;;;;;;;;;CAiBjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function imgBase64(src?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import image2uri, { validUrl } from "image2uri";
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
export function imgBase64(src) {
|
|
5
|
+
if (src && !validUrl(src) && /(png|apng|gif|jpg|jpeg|bm|bmp|webp|ico|svg)/i.test(src)) {
|
|
6
|
+
const imgPath = path.resolve(src);
|
|
7
|
+
if (fs.existsSync(imgPath)) {
|
|
8
|
+
const base64 = image2uri(imgPath);
|
|
9
|
+
if (base64 && typeof base64 === 'string') {
|
|
10
|
+
return base64;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return src;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=imgBase64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imgBase64.js","sourceRoot":"","sources":["../../src/nodes/imgBase64.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,MAAM,UAAU,CAAA;AAGzB,MAAM,UAAU,SAAS,CAAC,GAAY;IACpC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,8CAA8C,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACrF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAC1B,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;YAClC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBACxC,OAAO,MAAM,CAAC;aACf;SACF;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/lib/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.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,8 @@
|
|
|
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",
|
|
47
|
+
"image2uri": "^2.0.2",
|
|
46
48
|
"minimist": "~1.2.5",
|
|
47
49
|
"rehype-autolink-headings": "~6.1.0",
|
|
48
50
|
"rehype-document": "~6.1.0",
|
package/src/create.ts
CHANGED
|
@@ -10,6 +10,7 @@ import rehypeFormat from 'rehype-format';
|
|
|
10
10
|
import { githubCorners } from './nodes/github-corners';
|
|
11
11
|
import { githubCornersFork } from './nodes/github-corners-fork';
|
|
12
12
|
import { octiconLink } from './nodes/octiconLink';
|
|
13
|
+
import { imgBase64 as toBase64 } from './nodes/imgBase64';
|
|
13
14
|
import { markdownStyle } from './nodes/markdown-style';
|
|
14
15
|
import { copyElement, copyStyle, copyScript } from './nodes/copy';
|
|
15
16
|
import { darkMode } from './nodes/dark-mode';
|
|
@@ -23,7 +24,7 @@ import { MDToHTMLOptions } from './index';
|
|
|
23
24
|
export interface CreateOptions extends MDToHTMLOptions { }
|
|
24
25
|
|
|
25
26
|
export function create(options: MDToHTMLOptions = {}) {
|
|
26
|
-
const { markdown: string, document, corners = true, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true, 'markdown-style': wrapperStyle } = options;
|
|
27
|
+
const { markdown: string, document, 'img-base64': imgBase64 = false, corners = true, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true, 'markdown-style': wrapperStyle } = options;
|
|
27
28
|
const mdOptions: Options = {
|
|
28
29
|
hastNode: false,
|
|
29
30
|
remarkPlugins: [remarkGemoji],
|
|
@@ -61,6 +62,9 @@ export function create(options: MDToHTMLOptions = {}) {
|
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
if (node.type == 'element' && node.tagName === 'img' && imgBase64) {
|
|
66
|
+
node.properties = { ...node.properties, src: toBase64(node.properties.src as string) };
|
|
67
|
+
}
|
|
64
68
|
if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
|
|
65
69
|
const child = node.children[0];
|
|
66
70
|
if (child && child.type === 'element' && child.properties) {
|
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,10 @@ 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;
|
|
47
|
+
/** Convert images in HTML to base64. @default `false` */
|
|
48
|
+
'img-base64'?: boolean;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
export interface MDToHTMLOptions extends RunArgvs {
|
|
@@ -64,6 +69,8 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
|
64
69
|
default: {
|
|
65
70
|
version: opts.v || opts.version || false,
|
|
66
71
|
help: opts.h || opts.help || false,
|
|
72
|
+
ignoreFile: opts.ignoreFile || '(node_modules)',
|
|
73
|
+
'img-base64': opts.imgBase64 ?? false,
|
|
67
74
|
source: opts.s || opts.source || 'README.md',
|
|
68
75
|
markdown: opts.markdown || '',
|
|
69
76
|
'markdown-style': 'max-width: 960px;',
|
|
@@ -77,15 +84,23 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
|
77
84
|
return;
|
|
78
85
|
}
|
|
79
86
|
|
|
87
|
+
const mdFilesPath = globSync([...argvs._], {
|
|
88
|
+
ignore: {
|
|
89
|
+
ignored: p => {
|
|
90
|
+
return (new RegExp(argvs.ignoreFile, 'i')).test(p.fullpath()) || !/\.md$/i.test(p.fullpath())
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
80
94
|
const pkgPath = path.resolve(new URL('../package.json', import.meta.url).pathname);
|
|
81
95
|
if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
|
|
82
96
|
const pkg = fs.readJSONSync(pkgPath);
|
|
83
97
|
console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
|
|
84
98
|
return pkg.version;
|
|
85
99
|
}
|
|
100
|
+
// One File
|
|
86
101
|
if (argvs.source && !argvs.markdown) {
|
|
87
102
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
88
|
-
}
|
|
103
|
+
}
|
|
89
104
|
const options = formatConfig({ ...opts, ...argvs });
|
|
90
105
|
const output = path.resolve(argvs.output);
|
|
91
106
|
|
|
@@ -99,10 +114,21 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
|
99
114
|
options.document.style.push(options.style);
|
|
100
115
|
}
|
|
101
116
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
// One File
|
|
118
|
+
if (mdFilesPath.length === 0) {
|
|
119
|
+
const strMarkdown = create({ ...argvs, ...options });
|
|
120
|
+
fs.writeFileSync(output, strMarkdown);
|
|
121
|
+
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
|
|
122
|
+
}
|
|
123
|
+
if (mdFilesPath.length > 0) {
|
|
124
|
+
mdFilesPath.forEach((mdFile) => {
|
|
125
|
+
options.markdown = fs.readFileSync(path.resolve(mdFile)).toString();
|
|
126
|
+
opts.output = path.resolve(mdFile.replace(/\.md$/i, '.html').replace(/README\.html$/i, 'index.html').replace(/README-(.*)\.html$/i, 'index-$1.html'));
|
|
127
|
+
const strMarkdown = create({ ...argvs, ...options });
|
|
128
|
+
fs.writeFileSync(opts.output, strMarkdown);
|
|
129
|
+
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), opts.output)}\x1b[0m\n`);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
@@ -118,12 +144,14 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
|
118
144
|
--keywords Define keywords for search engines.
|
|
119
145
|
--no-dark-mode Disable light and dark theme styles button.
|
|
120
146
|
--markdown Markdown string.
|
|
147
|
+
--img-base64 Convert images in HTML to base64.
|
|
121
148
|
--style Override default styles. css file path or css string.
|
|
122
149
|
--markdown-style-theme Setting markdown-style light/dark theme.
|
|
123
150
|
--markdown-style Markdown wrapper style.
|
|
124
151
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
125
152
|
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
126
153
|
--title The \`<title>\` tag is required in HTML documents!
|
|
154
|
+
--ignore-file Ignore markdown files under certain paths. Default: "(node_modules)"
|
|
127
155
|
--version, -v Show version number
|
|
128
156
|
--help, -h Displays help information.
|
|
129
157
|
`;
|
|
@@ -131,6 +159,8 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
|
131
159
|
export const exampleHelp: string =`\n Example:
|
|
132
160
|
|
|
133
161
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli
|
|
162
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md
|
|
163
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli **/*.md --ignore-file="(test)"
|
|
134
164
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
|
|
135
165
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
136
166
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import image2uri, { validUrl } from "image2uri";
|
|
3
|
+
import fs from 'fs-extra'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function imgBase64(src?: string): string {
|
|
7
|
+
if (src && !validUrl(src) && /(png|apng|gif|jpg|jpeg|bm|bmp|webp|ico|svg)/i.test(src)) {
|
|
8
|
+
const imgPath = path.resolve(src);
|
|
9
|
+
if (fs.existsSync(imgPath)) {
|
|
10
|
+
const base64 = image2uri(imgPath);
|
|
11
|
+
if (base64 && typeof base64 === 'string') {
|
|
12
|
+
return base64;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return src;
|
|
17
|
+
}
|