markdown-to-html-cli 1.0.6 → 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/.github/workflows/ci.yml +1 -1
- package/README.md +17 -7
- package/lib/create.js +12 -1
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +22 -19
- package/lib/index.js.map +1 -1
- package/package.json +3 -1
- package/src/create.ts +13 -2
- package/src/index.ts +30 -27
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
|
@@ -30,13 +30,17 @@ $ npm i markdown-to-html-cli
|
|
|
30
30
|
"document": {
|
|
31
31
|
"title": "markdown-to-html-cli",
|
|
32
32
|
"description": "Command line tool generates markdown as html.",
|
|
33
|
-
"style": "body { color: red; }"
|
|
33
|
+
"style": "body { color: red; }",
|
|
34
|
+
"meta": [
|
|
35
|
+
{ "description": "Command line tool generates markdown as html." },
|
|
36
|
+
{ "keywords": "store,localStorage,lightweight,JavaScript" }
|
|
37
|
+
]
|
|
34
38
|
},
|
|
35
39
|
"github-corners": "https://github.com/jaywcjlove/markdown-to-html-cli",
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
"reurls": {
|
|
41
|
+
"README-zh.md": "index.zh.html",
|
|
42
|
+
"README.md": "index.html"
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
```
|
|
@@ -44,6 +48,7 @@ $ npm i markdown-to-html-cli
|
|
|
44
48
|
- [`name`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L2) -> `'markdown-to-html'.title` - The `<title>` tag is required in HTML documents!
|
|
45
49
|
- [`description`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L4) -> `'markdown-to-html'.description` - Define a description of your web page.
|
|
46
50
|
- [`repository.url`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L22) -> `'markdown-to-html'.github-corners` - Define a description of your web page.
|
|
51
|
+
- [`keywords`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L24-L30) -> `'markdown-to-html'.document.meta` - Define a description of your web page.
|
|
47
52
|
|
|
48
53
|
## Command Help
|
|
49
54
|
|
|
@@ -58,15 +63,16 @@ Options:
|
|
|
58
63
|
--source, -s The path of the target file "README.md". Default: README.md
|
|
59
64
|
--markdown Markdown string.
|
|
60
65
|
--description Define a description of your web page.
|
|
66
|
+
--favicon Add a Favicon to your Site.
|
|
61
67
|
--keywords Define keywords for search engines.
|
|
62
68
|
--title The `<title>` tag is required in HTML documents!
|
|
63
69
|
--author Define the author of a page.
|
|
64
|
-
--description Describe metadata within an HTML document.
|
|
65
70
|
--github-corners Add a Github corner to your project page.
|
|
66
71
|
|
|
67
72
|
Example:
|
|
68
73
|
|
|
69
74
|
npm markdown-to-html-cli
|
|
75
|
+
npm markdown-to-html --title="Hello World!"
|
|
70
76
|
npm markdown-to-html-cli --markdown="Hello World!"
|
|
71
77
|
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
72
78
|
npm markdown-to-html-cli --output coverage/index.html
|
|
@@ -92,10 +98,12 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
92
98
|
description?: string;
|
|
93
99
|
/** Define keywords for search engines */
|
|
94
100
|
keywords?: string;
|
|
101
|
+
/** Add a Favicon to your Site */
|
|
102
|
+
favicon?: string;
|
|
95
103
|
/** Define the author of a page */
|
|
96
104
|
author?: string;
|
|
97
105
|
}
|
|
98
|
-
export interface MDToHTMLOptions {
|
|
106
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
99
107
|
'github-corners'?: RunArgvs['github-corners'];
|
|
100
108
|
document?: Options;
|
|
101
109
|
/**
|
|
@@ -109,6 +117,8 @@ export interface MDToHTMLOptions {
|
|
|
109
117
|
};
|
|
110
118
|
}
|
|
111
119
|
export declare function run(opts?: RunArgvs): any;
|
|
120
|
+
export declare function cliHelp(): void;
|
|
121
|
+
export declare function exampleHelp(): void;
|
|
112
122
|
```
|
|
113
123
|
|
|
114
124
|
## Development
|
package/lib/create.js
CHANGED
|
@@ -13,7 +13,10 @@ import rehypeWrap from 'rehype-wrap';
|
|
|
13
13
|
import rehypeRaw from 'rehype-raw';
|
|
14
14
|
import rehypeRewrite from 'rehype-rewrite';
|
|
15
15
|
import rehypeAttrs from 'rehype-attr';
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import rehypeUrls from 'rehype-urls';
|
|
16
18
|
import remarkGfm from 'remark-gfm';
|
|
19
|
+
import remarkGemoji from 'remark-gemoji';
|
|
17
20
|
import remarkRehype from 'remark-rehype';
|
|
18
21
|
import remarkParse from 'remark-parse';
|
|
19
22
|
import { githubCorners } from './nodes/githubCorners.js';
|
|
@@ -22,16 +25,24 @@ export function create(argvs, options = {}) {
|
|
|
22
25
|
// default github css.
|
|
23
26
|
const cssStr = fs.readFileSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'github.css'));
|
|
24
27
|
const { markdown } = argvs || {};
|
|
25
|
-
const { document = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
28
|
+
const { document = {}, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
26
29
|
return unified()
|
|
27
30
|
.use(remarkParse)
|
|
28
31
|
.use(remarkGfm)
|
|
32
|
+
.use(remarkGemoji)
|
|
29
33
|
.use(remarkRehype, { allowDangerousHtml: true })
|
|
30
34
|
.use(rehypeRaw)
|
|
31
35
|
.use(rehypeSlug)
|
|
32
36
|
.use(rehypeAutolinkHeadings)
|
|
37
|
+
.use(rehypeUrls, (url) => {
|
|
38
|
+
if (reurls[url.href]) {
|
|
39
|
+
url.path = reurls[url.href];
|
|
40
|
+
return url.path;
|
|
41
|
+
}
|
|
42
|
+
})
|
|
33
43
|
.use(rehypeDocument, {
|
|
34
44
|
...document,
|
|
45
|
+
link: document.link ? document.link : [],
|
|
35
46
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style])],
|
|
36
47
|
})
|
|
37
48
|
.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,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,aAAa;AACb,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO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"}
|
package/lib/index.d.ts
CHANGED
|
@@ -14,12 +14,16 @@ export interface RunArgvs 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;
|
|
25
|
+
/** rewrite URLs of href and src attributes. */
|
|
26
|
+
reurls?: Record<string, string>;
|
|
23
27
|
/**
|
|
24
28
|
* rehype-wrap Options
|
|
25
29
|
* Wrap selected elements with a given element
|
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,43 @@ 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
|
}
|
|
59
|
+
if (mth.reurls) {
|
|
60
|
+
options.reurls = mth.reurls;
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
64
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
65
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
66
|
+
}
|
|
62
67
|
if (Array.isArray(options.document.meta)) {
|
|
63
|
-
if (
|
|
64
|
-
options.document.meta.push({ description:
|
|
68
|
+
if (options.description) {
|
|
69
|
+
options.document.meta.push({ description: options.description });
|
|
65
70
|
}
|
|
66
71
|
else if (pgkData.description) {
|
|
67
72
|
options.document.meta.push({ description: pgkData.description });
|
|
68
73
|
}
|
|
69
|
-
if (
|
|
70
|
-
options.document.meta.push({ keywords:
|
|
74
|
+
if (options.keywords) {
|
|
75
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
71
76
|
}
|
|
72
77
|
else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
73
78
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
74
79
|
}
|
|
75
|
-
if (
|
|
76
|
-
options.document.meta.push({ author:
|
|
80
|
+
if (typeof options.author === 'string') {
|
|
81
|
+
options.document.meta.push({ author: options.author });
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
|
-
if (mth.document && mth.document.meta) {
|
|
80
|
-
options.document.meta = mth.document.meta;
|
|
81
|
-
}
|
|
82
84
|
const output = path.resolve(argvs.output);
|
|
83
85
|
const strMarkdown = create(argvs, options);
|
|
84
86
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -93,15 +95,16 @@ export function cliHelp() {
|
|
|
93
95
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
94
96
|
console.log(' --markdown ', 'Markdown string.');
|
|
95
97
|
console.log(' --description ', 'Define a description of your web page.');
|
|
98
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
96
99
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
97
100
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
98
101
|
console.log(' --author ', 'Define the author of a page.');
|
|
99
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
100
102
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
101
103
|
}
|
|
102
104
|
export function exampleHelp() {
|
|
103
105
|
console.log('\n Example:\n');
|
|
104
106
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli');
|
|
107
|
+
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"');
|
|
105
108
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
106
109
|
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
110
|
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,QAAw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AO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Command line tool generates markdown as html.",
|
|
5
5
|
"homepage": "https://jaywcjlove.github.io/markdown-to-html-cli/",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -53,6 +53,8 @@
|
|
|
53
53
|
"rehype-rewrite": "2.1.2",
|
|
54
54
|
"rehype-wrap": "1.0.10",
|
|
55
55
|
"rehype-raw": "6.1.0",
|
|
56
|
+
"rehype-urls": "1.1.1",
|
|
57
|
+
"remark-gemoji": "7.0.0",
|
|
56
58
|
"remark-gfm": "2.0.0",
|
|
57
59
|
"remark-parse": "10.0.0",
|
|
58
60
|
"remark-rehype": "9.1.0",
|
package/src/create.ts
CHANGED
|
@@ -13,7 +13,10 @@ import rehypeWrap from 'rehype-wrap';
|
|
|
13
13
|
import rehypeRaw from 'rehype-raw';
|
|
14
14
|
import rehypeRewrite from 'rehype-rewrite';
|
|
15
15
|
import rehypeAttrs from 'rehype-attr';
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import rehypeUrls from 'rehype-urls';
|
|
16
18
|
import remarkGfm from 'remark-gfm';
|
|
19
|
+
import remarkGemoji from 'remark-gemoji';
|
|
17
20
|
import remarkRehype from 'remark-rehype';
|
|
18
21
|
import remarkParse from 'remark-parse';
|
|
19
22
|
import { githubCorners } from './nodes/githubCorners';
|
|
@@ -21,20 +24,28 @@ import { octiconLink } from './nodes/octiconLink';
|
|
|
21
24
|
|
|
22
25
|
import { RunArgvs, MDToHTMLOptions } from './';
|
|
23
26
|
|
|
24
|
-
export function create(argvs: RunArgvs, options
|
|
27
|
+
export function create(argvs: RunArgvs, options = {} as MDToHTMLOptions) {
|
|
25
28
|
// default github css.
|
|
26
29
|
const cssStr = fs.readFileSync(path.resolve(__dirname, 'github.css'));
|
|
27
30
|
const { markdown } = argvs || {};
|
|
28
|
-
const { document = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
31
|
+
const { document = {}, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
29
32
|
return unified()
|
|
30
33
|
.use(remarkParse)
|
|
31
34
|
.use(remarkGfm)
|
|
35
|
+
.use(remarkGemoji)
|
|
32
36
|
.use(remarkRehype, { allowDangerousHtml: true })
|
|
33
37
|
.use(rehypeRaw)
|
|
34
38
|
.use(rehypeSlug)
|
|
35
39
|
.use(rehypeAutolinkHeadings)
|
|
40
|
+
.use(rehypeUrls, (url: any) => {
|
|
41
|
+
if (reurls[url.href]) {
|
|
42
|
+
url.path = reurls[url.href];
|
|
43
|
+
return url.path;
|
|
44
|
+
}
|
|
45
|
+
})
|
|
36
46
|
.use(rehypeDocument, {
|
|
37
47
|
...document,
|
|
48
|
+
link: document.link ? document.link : [],
|
|
38
49
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style]) ],
|
|
39
50
|
})
|
|
40
51
|
.use(rehypeFormat)
|
package/src/index.ts
CHANGED
|
@@ -20,13 +20,17 @@ 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
|
-
document?: Options
|
|
31
|
+
document?: Options;
|
|
32
|
+
/** rewrite URLs of href and src attributes. */
|
|
33
|
+
reurls?: Record<string, string>;
|
|
30
34
|
/**
|
|
31
35
|
* rehype-wrap Options
|
|
32
36
|
* Wrap selected elements with a given element
|
|
@@ -67,57 +71,55 @@ export function run(opts = {} as RunArgvs) {
|
|
|
67
71
|
if (argvs.source && !argvs.markdown) {
|
|
68
72
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
69
73
|
}
|
|
70
|
-
|
|
74
|
+
|
|
75
|
+
const options = { ...opts, ...argvs, document: { title: argvs.title, meta: [], link: [] } } as MDToHTMLOptions;
|
|
71
76
|
const projectPkg = path.resolve(process.cwd(), 'package.json');
|
|
72
77
|
|
|
73
78
|
let pgkData: any = {};
|
|
74
|
-
let mth: MDToHTMLOptions = {}
|
|
75
79
|
if (fs.existsSync(projectPkg)) {
|
|
76
80
|
pgkData = fs.readJSONSync(projectPkg);
|
|
77
81
|
if (pgkData.name && !options.document.title) {
|
|
78
82
|
options.document.title = pgkData.name;
|
|
79
83
|
}
|
|
80
84
|
if (pgkData.repository && !argvs['github-corners']) {
|
|
81
|
-
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url
|
|
85
|
+
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
82
86
|
}
|
|
83
87
|
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;
|
|
88
|
+
const mth = pgkData['markdown-to-html'] as MDToHTMLOptions;
|
|
89
|
+
const { title, meta, link } = options.document;
|
|
90
|
+
options.document = { title, meta, link, ...mth.document };
|
|
91
|
+
if (!options.favicon && mth.favicon) {
|
|
92
|
+
options.favicon = mth.favicon;
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
if (!options.wrap) {
|
|
94
|
+
if (!options.wrap && mth.wrap) {
|
|
94
95
|
options.wrap = mth.wrap;
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
-
if (!argvs['github-corners'] && mth['github-corners']) {
|
|
97
|
+
if (mth['github-corners']) {
|
|
98
98
|
argvs['github-corners'] = mth['github-corners'];
|
|
99
99
|
}
|
|
100
|
+
if (mth.reurls) {
|
|
101
|
+
options.reurls = mth.reurls;
|
|
102
|
+
}
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
106
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
107
|
+
}
|
|
103
108
|
if (Array.isArray(options.document.meta)) {
|
|
104
|
-
if (
|
|
105
|
-
options.document.meta.push({ description:
|
|
109
|
+
if (options.description) {
|
|
110
|
+
options.document.meta.push({ description: options.description });
|
|
106
111
|
} else if (pgkData.description) {
|
|
107
112
|
options.document.meta.push({ description: pgkData.description });
|
|
108
113
|
}
|
|
109
|
-
if (
|
|
110
|
-
options.document.meta.push({ keywords:
|
|
114
|
+
if (options.keywords) {
|
|
115
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
111
116
|
} else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
112
117
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
113
118
|
}
|
|
114
|
-
if (
|
|
115
|
-
options.document.meta.push({ author:
|
|
119
|
+
if (typeof options.author === 'string') {
|
|
120
|
+
options.document.meta.push({ author: options.author });
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
|
-
if (mth.document && mth.document.meta) {
|
|
119
|
-
options.document.meta = mth.document.meta;
|
|
120
|
-
}
|
|
121
123
|
const output = path.resolve(argvs.output);
|
|
122
124
|
const strMarkdown = create(argvs, options);
|
|
123
125
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -133,16 +135,17 @@ export function cliHelp() {
|
|
|
133
135
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
134
136
|
console.log(' --markdown ', 'Markdown string.');
|
|
135
137
|
console.log(' --description ', 'Define a description of your web page.');
|
|
138
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
136
139
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
137
140
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
138
141
|
console.log(' --author ', 'Define the author of a page.');
|
|
139
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
140
142
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
export function exampleHelp() {
|
|
144
146
|
console.log('\n Example:\n');
|
|
145
147
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli');
|
|
148
|
+
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"');
|
|
146
149
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
147
150
|
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
151
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html');
|