markdown-to-html-cli 1.0.7 → 1.0.8
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/.github/workflows/ci.yml +1 -1
- package/README.md +7 -2
- package/lib/create.js +1 -0
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +19 -19
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/create.ts +2 -1
- package/src/index.ts +24 -26
package/.github/workflows/ci.yml
CHANGED
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
- run: npm install
|
|
17
17
|
- run: npm run build
|
|
18
18
|
- run: npm run coverage
|
|
19
|
-
- run: node lib/cli.js --output coverage/index.html --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
19
|
+
- run: node lib/cli.js --output coverage/index.html --github-corners https://github.com/jaywcjlove/markdown-to-html-cli --favicon 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌐</text></svg>'
|
|
20
20
|
|
|
21
21
|
- run: npm i coverage-badges-cli -g
|
|
22
22
|
- run: coverage-badges
|
package/README.md
CHANGED
|
@@ -59,15 +59,16 @@ Options:
|
|
|
59
59
|
--source, -s The path of the target file "README.md". Default: README.md
|
|
60
60
|
--markdown Markdown string.
|
|
61
61
|
--description Define a description of your web page.
|
|
62
|
+
--favicon Add a Favicon to your Site.
|
|
62
63
|
--keywords Define keywords for search engines.
|
|
63
64
|
--title The `<title>` tag is required in HTML documents!
|
|
64
65
|
--author Define the author of a page.
|
|
65
|
-
--description Describe metadata within an HTML document.
|
|
66
66
|
--github-corners Add a Github corner to your project page.
|
|
67
67
|
|
|
68
68
|
Example:
|
|
69
69
|
|
|
70
70
|
npm markdown-to-html-cli
|
|
71
|
+
npm markdown-to-html --title="Hello World!"
|
|
71
72
|
npm markdown-to-html-cli --markdown="Hello World!"
|
|
72
73
|
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
73
74
|
npm markdown-to-html-cli --output coverage/index.html
|
|
@@ -93,10 +94,12 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
93
94
|
description?: string;
|
|
94
95
|
/** Define keywords for search engines */
|
|
95
96
|
keywords?: string;
|
|
97
|
+
/** Add a Favicon to your Site */
|
|
98
|
+
favicon?: string;
|
|
96
99
|
/** Define the author of a page */
|
|
97
100
|
author?: string;
|
|
98
101
|
}
|
|
99
|
-
export interface MDToHTMLOptions {
|
|
102
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
100
103
|
'github-corners'?: RunArgvs['github-corners'];
|
|
101
104
|
document?: Options;
|
|
102
105
|
/**
|
|
@@ -110,6 +113,8 @@ export interface MDToHTMLOptions {
|
|
|
110
113
|
};
|
|
111
114
|
}
|
|
112
115
|
export declare function run(opts?: RunArgvs): any;
|
|
116
|
+
export declare function cliHelp(): void;
|
|
117
|
+
export declare function exampleHelp(): void;
|
|
113
118
|
```
|
|
114
119
|
|
|
115
120
|
## Development
|
package/lib/create.js
CHANGED
|
@@ -32,6 +32,7 @@ export function create(argvs, options = {}) {
|
|
|
32
32
|
.use(rehypeAutolinkHeadings)
|
|
33
33
|
.use(rehypeDocument, {
|
|
34
34
|
...document,
|
|
35
|
+
link: document.link ? document.link : [],
|
|
35
36
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style])],
|
|
36
37
|
})
|
|
37
38
|
.use(rehypeFormat)
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,aAAa;AACb,OA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extends ParsedArgs {
|
|
|
14
14
|
description?: string;
|
|
15
15
|
/** Define keywords for search engines */
|
|
16
16
|
keywords?: string;
|
|
17
|
+
/** Add a Favicon to your Site */
|
|
18
|
+
favicon?: string;
|
|
17
19
|
/** Define the author of a page */
|
|
18
20
|
author?: string;
|
|
19
21
|
}
|
|
20
|
-
export interface MDToHTMLOptions {
|
|
22
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
21
23
|
'github-corners'?: RunArgvs['github-corners'];
|
|
22
24
|
document?: Options;
|
|
23
25
|
/**
|
package/lib/index.js
CHANGED
|
@@ -32,10 +32,9 @@ export function run(opts = {}) {
|
|
|
32
32
|
if (argvs.source && !argvs.markdown) {
|
|
33
33
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
34
34
|
}
|
|
35
|
-
const options = { document: { title: argvs.title, meta: [] } };
|
|
35
|
+
const options = { ...opts, ...argvs, document: { title: argvs.title, meta: [], link: [] } };
|
|
36
36
|
const projectPkg = path.resolve(process.cwd(), 'package.json');
|
|
37
37
|
let pgkData = {};
|
|
38
|
-
let mth = {};
|
|
39
38
|
if (fs.existsSync(projectPkg)) {
|
|
40
39
|
pgkData = fs.readJSONSync(projectPkg);
|
|
41
40
|
if (pgkData.name && !options.document.title) {
|
|
@@ -45,40 +44,40 @@ export function run(opts = {}) {
|
|
|
45
44
|
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
46
45
|
}
|
|
47
46
|
if (pgkData['markdown-to-html']) {
|
|
48
|
-
mth = pgkData['markdown-to-html'];
|
|
49
|
-
const { title, meta } = options.document;
|
|
50
|
-
options.document = { title, meta, ...mth.document };
|
|
51
|
-
if (mth.
|
|
52
|
-
options.
|
|
47
|
+
const mth = pgkData['markdown-to-html'];
|
|
48
|
+
const { title, meta, link } = options.document;
|
|
49
|
+
options.document = { title, meta, link, ...mth.document };
|
|
50
|
+
if (!options.favicon && mth.favicon) {
|
|
51
|
+
options.favicon = mth.favicon;
|
|
53
52
|
}
|
|
54
|
-
if (!options.wrap) {
|
|
53
|
+
if (!options.wrap && mth.wrap) {
|
|
55
54
|
options.wrap = mth.wrap;
|
|
56
55
|
}
|
|
57
|
-
if (
|
|
56
|
+
if (mth['github-corners']) {
|
|
58
57
|
argvs['github-corners'] = mth['github-corners'];
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
}
|
|
61
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
62
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
63
|
+
}
|
|
62
64
|
if (Array.isArray(options.document.meta)) {
|
|
63
|
-
if (
|
|
64
|
-
options.document.meta.push({ description:
|
|
65
|
+
if (options.description) {
|
|
66
|
+
options.document.meta.push({ description: options.description });
|
|
65
67
|
}
|
|
66
68
|
else if (pgkData.description) {
|
|
67
69
|
options.document.meta.push({ description: pgkData.description });
|
|
68
70
|
}
|
|
69
|
-
if (
|
|
70
|
-
options.document.meta.push({ keywords:
|
|
71
|
+
if (options.keywords) {
|
|
72
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
71
73
|
}
|
|
72
74
|
else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
73
75
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
74
76
|
}
|
|
75
|
-
if (
|
|
76
|
-
options.document.meta.push({ author:
|
|
77
|
+
if (typeof options.author === 'string') {
|
|
78
|
+
options.document.meta.push({ author: options.author });
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
if (mth.document && mth.document.meta) {
|
|
80
|
-
options.document.meta = mth.document.meta;
|
|
81
|
-
}
|
|
82
81
|
const output = path.resolve(argvs.output);
|
|
83
82
|
const strMarkdown = create(argvs, options);
|
|
84
83
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -93,15 +92,16 @@ export function cliHelp() {
|
|
|
93
92
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
94
93
|
console.log(' --markdown ', 'Markdown string.');
|
|
95
94
|
console.log(' --description ', 'Define a description of your web page.');
|
|
95
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
96
96
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
97
97
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
98
98
|
console.log(' --author ', 'Define the author of a page.');
|
|
99
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
100
99
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
101
100
|
}
|
|
102
101
|
export function exampleHelp() {
|
|
103
102
|
console.log('\n Example:\n');
|
|
104
103
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli');
|
|
104
|
+
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"');
|
|
105
105
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
106
106
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli');
|
|
107
107
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html');
|
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,QAAwB,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],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C,EAAE,oBAAoB,CAAC,CAAC;IACxG,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,wCAAwC,CAAC,CAAC;IAChF,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,6BAA6B,CAAC,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,qCAAqC,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,kDAAkD,CAAC,CAAC;IAC1F,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,8BAA8B,CAAC,CAAC;IACtE,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,2CAA2C,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,mFAAmF,CAAC,CAAC;IACjG,OAAO,CAAC,GAAG,CAAC,sFAAsF,CAAC,CAAC;IACpG,OAAO,CAAC,GAAG,CAAC,gIAAgI,CAAC,CAAC;IAC9I,OAAO,CAAC,GAAG,CAAC,yFAAyF,CAAC,CAAC;IACvG,OAAO,CAAC,GAAG,CAAC,+EAA+E,CAAC,CAAC;IAC7F,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
package/src/create.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { octiconLink } from './nodes/octiconLink';
|
|
|
21
21
|
|
|
22
22
|
import { RunArgvs, MDToHTMLOptions } from './';
|
|
23
23
|
|
|
24
|
-
export function create(argvs: RunArgvs, options
|
|
24
|
+
export function create(argvs: RunArgvs, options = {} as MDToHTMLOptions) {
|
|
25
25
|
// default github css.
|
|
26
26
|
const cssStr = fs.readFileSync(path.resolve(__dirname, 'github.css'));
|
|
27
27
|
const { markdown } = argvs || {};
|
|
@@ -35,6 +35,7 @@ export function create(argvs: RunArgvs, options: MDToHTMLOptions = {}) {
|
|
|
35
35
|
.use(rehypeAutolinkHeadings)
|
|
36
36
|
.use(rehypeDocument, {
|
|
37
37
|
...document,
|
|
38
|
+
link: document.link ? document.link : [],
|
|
38
39
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style]) ],
|
|
39
40
|
})
|
|
40
41
|
.use(rehypeFormat)
|
package/src/index.ts
CHANGED
|
@@ -20,11 +20,13 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
20
20
|
description?: string;
|
|
21
21
|
/** Define keywords for search engines */
|
|
22
22
|
keywords?: string;
|
|
23
|
+
/** Add a Favicon to your Site */
|
|
24
|
+
favicon?: string;
|
|
23
25
|
/** Define the author of a page */
|
|
24
26
|
author?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
export interface MDToHTMLOptions {
|
|
29
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
28
30
|
'github-corners'?: RunArgvs['github-corners'];
|
|
29
31
|
document?: Options
|
|
30
32
|
/**
|
|
@@ -67,57 +69,52 @@ export function run(opts = {} as RunArgvs) {
|
|
|
67
69
|
if (argvs.source && !argvs.markdown) {
|
|
68
70
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
|
|
73
|
+
const options = { ...opts, ...argvs, document: { title: argvs.title, meta: [], link: [] } } as MDToHTMLOptions;
|
|
71
74
|
const projectPkg = path.resolve(process.cwd(), 'package.json');
|
|
72
75
|
|
|
73
76
|
let pgkData: any = {};
|
|
74
|
-
let mth: MDToHTMLOptions = {}
|
|
75
77
|
if (fs.existsSync(projectPkg)) {
|
|
76
78
|
pgkData = fs.readJSONSync(projectPkg);
|
|
77
79
|
if (pgkData.name && !options.document.title) {
|
|
78
80
|
options.document.title = pgkData.name;
|
|
79
81
|
}
|
|
80
82
|
if (pgkData.repository && !argvs['github-corners']) {
|
|
81
|
-
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url
|
|
83
|
+
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
82
84
|
}
|
|
83
85
|
if (pgkData['markdown-to-html']) {
|
|
84
|
-
mth = pgkData['markdown-to-html'];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
options.
|
|
88
|
-
|
|
89
|
-
if (mth.document.title) {
|
|
90
|
-
options.document.title = mth.document.title;
|
|
86
|
+
const mth = pgkData['markdown-to-html'] as MDToHTMLOptions;
|
|
87
|
+
const { title, meta, link } = options.document;
|
|
88
|
+
options.document = { title, meta, link, ...mth.document };
|
|
89
|
+
if (!options.favicon && mth.favicon) {
|
|
90
|
+
options.favicon = mth.favicon;
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
if (!options.wrap) {
|
|
92
|
+
if (!options.wrap && mth.wrap) {
|
|
94
93
|
options.wrap = mth.wrap;
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
if (!argvs['github-corners'] && mth['github-corners']) {
|
|
95
|
+
if (mth['github-corners']) {
|
|
98
96
|
argvs['github-corners'] = mth['github-corners'];
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
|
-
|
|
100
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
101
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
102
|
+
}
|
|
103
103
|
if (Array.isArray(options.document.meta)) {
|
|
104
|
-
if (
|
|
105
|
-
options.document.meta.push({ description:
|
|
104
|
+
if (options.description) {
|
|
105
|
+
options.document.meta.push({ description: options.description });
|
|
106
106
|
} else if (pgkData.description) {
|
|
107
107
|
options.document.meta.push({ description: pgkData.description });
|
|
108
108
|
}
|
|
109
|
-
if (
|
|
110
|
-
options.document.meta.push({ keywords:
|
|
109
|
+
if (options.keywords) {
|
|
110
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
111
111
|
} else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
112
112
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
113
113
|
}
|
|
114
|
-
if (
|
|
115
|
-
options.document.meta.push({ author:
|
|
114
|
+
if (typeof options.author === 'string') {
|
|
115
|
+
options.document.meta.push({ author: options.author });
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
if (mth.document && mth.document.meta) {
|
|
119
|
-
options.document.meta = mth.document.meta;
|
|
120
|
-
}
|
|
121
118
|
const output = path.resolve(argvs.output);
|
|
122
119
|
const strMarkdown = create(argvs, options);
|
|
123
120
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -133,16 +130,17 @@ export function cliHelp() {
|
|
|
133
130
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
134
131
|
console.log(' --markdown ', 'Markdown string.');
|
|
135
132
|
console.log(' --description ', 'Define a description of your web page.');
|
|
133
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
136
134
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
137
135
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
138
136
|
console.log(' --author ', 'Define the author of a page.');
|
|
139
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
140
137
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
export function exampleHelp() {
|
|
144
141
|
console.log('\n Example:\n');
|
|
145
142
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli');
|
|
143
|
+
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"');
|
|
146
144
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
147
145
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli');
|
|
148
146
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html');
|