markdown-to-html-cli 1.0.4 → 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 +2 -2
- package/README.md +59 -7
- package/lib/create.js +6 -3
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +24 -16
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/create.ts +7 -4
- package/src/index.ts +29 -18
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
|
|
@@ -51,7 +51,7 @@ jobs:
|
|
|
51
51
|
tag: ${{ steps.create_tag.outputs.version }}
|
|
52
52
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
53
53
|
body: |
|
|
54
|
-
[](https://uiwjs.github.io/npm-unpkg/#/pkg/
|
|
54
|
+
[](https://uiwjs.github.io/npm-unpkg/#/pkg/markdown-to-html-cli@${{steps.changelog.outputs.version}}/file/README.md)
|
|
55
55
|
|
|
56
56
|
${{ steps.changelog.outputs.compareurl }}
|
|
57
57
|
|
package/README.md
CHANGED
|
@@ -27,16 +27,25 @@ $ npm i markdown-to-html-cli
|
|
|
27
27
|
```js
|
|
28
28
|
{
|
|
29
29
|
"markdown-to-html": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
"document": {
|
|
31
|
+
"title": "markdown-to-html-cli",
|
|
32
|
+
"description": "Command line tool generates markdown as html.",
|
|
33
|
+
"style": "body { color: red; }",
|
|
34
|
+
"meta": [
|
|
35
|
+
{ "description": "Command line tool generates markdown as html." },
|
|
36
|
+
{ "keywords": "store,localStorage,lightweight,JavaScript" }
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"github-corners": "https://github.com/jaywcjlove/markdown-to-html-cli"
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
```
|
|
39
43
|
|
|
44
|
+
- [`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
|
+
- [`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
|
+
- [`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.
|
|
47
|
+
- [`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.
|
|
48
|
+
|
|
40
49
|
## Command Help
|
|
41
50
|
|
|
42
51
|
```bash
|
|
@@ -50,21 +59,64 @@ Options:
|
|
|
50
59
|
--source, -s The path of the target file "README.md". Default: README.md
|
|
51
60
|
--markdown Markdown string.
|
|
52
61
|
--description Define a description of your web page.
|
|
62
|
+
--favicon Add a Favicon to your Site.
|
|
53
63
|
--keywords Define keywords for search engines.
|
|
54
64
|
--title The `<title>` tag is required in HTML documents!
|
|
55
65
|
--author Define the author of a page.
|
|
56
|
-
--description Describe metadata within an HTML document.
|
|
57
66
|
--github-corners Add a Github corner to your project page.
|
|
58
67
|
|
|
59
68
|
Example:
|
|
60
69
|
|
|
61
70
|
npm markdown-to-html-cli
|
|
71
|
+
npm markdown-to-html --title="Hello World!"
|
|
62
72
|
npm markdown-to-html-cli --markdown="Hello World!"
|
|
63
73
|
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
64
74
|
npm markdown-to-html-cli --output coverage/index.html
|
|
65
75
|
npm markdown-to-html-cli --source README.md
|
|
66
76
|
```
|
|
67
77
|
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { ParsedArgs } from 'minimist';
|
|
82
|
+
import { Options } from 'rehype-document';
|
|
83
|
+
export interface RunArgvs extends ParsedArgs {
|
|
84
|
+
version?: string;
|
|
85
|
+
source?: string;
|
|
86
|
+
output?: string;
|
|
87
|
+
/** Add a Github corner to your project page */
|
|
88
|
+
'github-corners'?: string;
|
|
89
|
+
/** Markdown string. */
|
|
90
|
+
markdown?: string;
|
|
91
|
+
/** The `<title>` tag is required in HTML documents! */
|
|
92
|
+
title?: string;
|
|
93
|
+
/** Define a description of your web page */
|
|
94
|
+
description?: string;
|
|
95
|
+
/** Define keywords for search engines */
|
|
96
|
+
keywords?: string;
|
|
97
|
+
/** Add a Favicon to your Site */
|
|
98
|
+
favicon?: string;
|
|
99
|
+
/** Define the author of a page */
|
|
100
|
+
author?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
103
|
+
'github-corners'?: RunArgvs['github-corners'];
|
|
104
|
+
document?: Options;
|
|
105
|
+
/**
|
|
106
|
+
* rehype-wrap Options
|
|
107
|
+
* Wrap selected elements with a given element
|
|
108
|
+
* https://github.com/mrzmmr/rehype-wrap/tree/2402bcdb8ea25bd0948cda72e96d16e65a18c1e9#options
|
|
109
|
+
*/
|
|
110
|
+
wrap?: {
|
|
111
|
+
selector?: string;
|
|
112
|
+
wrapper?: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export declare function run(opts?: RunArgvs): any;
|
|
116
|
+
export declare function cliHelp(): void;
|
|
117
|
+
export declare function exampleHelp(): void;
|
|
118
|
+
```
|
|
119
|
+
|
|
68
120
|
## Development
|
|
69
121
|
|
|
70
122
|
```bash
|
package/lib/create.js
CHANGED
|
@@ -5,11 +5,12 @@ import rehypeDocument from 'rehype-document';
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import rehypePrism from '@mapbox/rehype-prism/index.js';
|
|
7
7
|
import stringify from 'rehype-stringify';
|
|
8
|
-
import
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
9
|
import rehypeFormat from 'rehype-format';
|
|
10
10
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
import rehypeWrap from 'rehype-wrap';
|
|
13
|
+
import rehypeRaw from 'rehype-raw';
|
|
13
14
|
import rehypeRewrite from 'rehype-rewrite';
|
|
14
15
|
import rehypeAttrs from 'rehype-attr';
|
|
15
16
|
import remarkGfm from 'remark-gfm';
|
|
@@ -25,11 +26,13 @@ export function create(argvs, options = {}) {
|
|
|
25
26
|
return unified()
|
|
26
27
|
.use(remarkParse)
|
|
27
28
|
.use(remarkGfm)
|
|
28
|
-
.use(remarkRehype)
|
|
29
|
-
.use(
|
|
29
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
30
|
+
.use(rehypeRaw)
|
|
31
|
+
.use(rehypeSlug)
|
|
30
32
|
.use(rehypeAutolinkHeadings)
|
|
31
33
|
.use(rehypeDocument, {
|
|
32
34
|
...document,
|
|
35
|
+
link: document.link ? document.link : [],
|
|
33
36
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style])],
|
|
34
37
|
})
|
|
35
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,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,
|
|
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,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,MAAM,UAAU,MAAM,CAAC,KAAe,EAAE,UAAU,EAAqB;IACrE,sBAAsB;IACtB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAA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AAe,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,EAAE;YAC3F,IAAI,CAAC,QAAQ,GAAG,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,GAAI,IAAI,CAAC,QAAuB,CAAC,CAAC;SACtG;QAED,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,gBAAgB,CAAC,IAAI,CAAE,IAAY,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3G,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAChD,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,EAAE;gBAC7B,KAAK,CAAC,UAAU,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;gBAC5D,KAAK,CAAC,QAAQ,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;aAClC;SACF;IACH,CAAC,CAAC;SACD,GAAG,CAAC,WAAW,CAAC;SAChB,GAAG,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;SACxC,GAAG,CAAC,SAAS,CAAC;SACd,WAAW,CAAC,QAAQ,CAAC;SACrB,QAAQ,EAAE,CAAC;AAChB,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -14,10 +14,13 @@ 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 {
|
|
23
|
+
'github-corners'?: RunArgvs['github-corners'];
|
|
21
24
|
document?: Options;
|
|
22
25
|
/**
|
|
23
26
|
* rehype-wrap Options
|
package/lib/index.js
CHANGED
|
@@ -32,45 +32,52 @@ 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) {
|
|
42
41
|
options.document.title = pgkData.name;
|
|
43
42
|
}
|
|
43
|
+
if (pgkData.repository && !argvs['github-corners']) {
|
|
44
|
+
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
45
|
+
}
|
|
44
46
|
if (pgkData['markdown-to-html']) {
|
|
45
|
-
mth = pgkData['markdown-to-html'];
|
|
46
|
-
|
|
47
|
-
|
|
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;
|
|
48
52
|
}
|
|
49
|
-
if (!options.wrap) {
|
|
53
|
+
if (!options.wrap && mth.wrap) {
|
|
50
54
|
options.wrap = mth.wrap;
|
|
51
55
|
}
|
|
56
|
+
if (mth['github-corners']) {
|
|
57
|
+
argvs['github-corners'] = mth['github-corners'];
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
60
|
}
|
|
61
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
62
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
63
|
+
}
|
|
54
64
|
if (Array.isArray(options.document.meta)) {
|
|
55
|
-
if (
|
|
56
|
-
options.document.meta.push({ description:
|
|
65
|
+
if (options.description) {
|
|
66
|
+
options.document.meta.push({ description: options.description });
|
|
57
67
|
}
|
|
58
68
|
else if (pgkData.description) {
|
|
59
69
|
options.document.meta.push({ description: pgkData.description });
|
|
60
70
|
}
|
|
61
|
-
if (
|
|
62
|
-
options.document.meta.push({ keywords:
|
|
71
|
+
if (options.keywords) {
|
|
72
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
63
73
|
}
|
|
64
74
|
else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
65
75
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
66
76
|
}
|
|
67
|
-
if (
|
|
68
|
-
options.document.meta.push({ author:
|
|
77
|
+
if (typeof options.author === 'string') {
|
|
78
|
+
options.document.meta.push({ author: options.author });
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
|
-
if (mth.document && mth.document.meta) {
|
|
72
|
-
options.document.meta = mth.document.meta;
|
|
73
|
-
}
|
|
74
81
|
const output = path.resolve(argvs.output);
|
|
75
82
|
const strMarkdown = create(argvs, options);
|
|
76
83
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -85,15 +92,16 @@ export function cliHelp() {
|
|
|
85
92
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
86
93
|
console.log(' --markdown ', 'Markdown string.');
|
|
87
94
|
console.log(' --description ', 'Define a description of your web page.');
|
|
95
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
88
96
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
89
97
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
90
98
|
console.log(' --author ', 'Define the author of a page.');
|
|
91
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
92
99
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
93
100
|
}
|
|
94
101
|
export function exampleHelp() {
|
|
95
102
|
console.log('\n Example:\n');
|
|
96
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!"');
|
|
97
105
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
98
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');
|
|
99
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"],"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;AAoC3E,M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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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"start": "node lib/cli.js
|
|
13
|
+
"start": "node lib/cli.js",
|
|
14
14
|
"watch": "tsbb watch --disable-babel --file-names src/cli.ts",
|
|
15
15
|
"build": "tsbb build --disable-babel --file-names src/cli.ts && npm run fix",
|
|
16
16
|
"fix": "tsc-esm-fix --target='lib' --ext='.js'",
|
|
@@ -52,12 +52,13 @@
|
|
|
52
52
|
"rehype-format": "4.0.0",
|
|
53
53
|
"rehype-rewrite": "2.1.2",
|
|
54
54
|
"rehype-wrap": "1.0.10",
|
|
55
|
+
"rehype-raw": "6.1.0",
|
|
55
56
|
"remark-gfm": "2.0.0",
|
|
56
57
|
"remark-parse": "10.0.0",
|
|
57
58
|
"remark-rehype": "9.1.0",
|
|
58
59
|
"minimist": "1.2.5"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"tsbb": "3.3.
|
|
62
|
+
"tsbb": "3.3.7"
|
|
62
63
|
}
|
|
63
64
|
}
|
package/src/create.ts
CHANGED
|
@@ -5,11 +5,12 @@ import rehypeDocument from 'rehype-document';
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import rehypePrism from '@mapbox/rehype-prism';
|
|
7
7
|
import stringify from 'rehype-stringify';
|
|
8
|
-
import
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
9
|
import rehypeFormat from 'rehype-format';
|
|
10
10
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
import rehypeWrap from 'rehype-wrap';
|
|
13
|
+
import rehypeRaw from 'rehype-raw';
|
|
13
14
|
import rehypeRewrite from 'rehype-rewrite';
|
|
14
15
|
import rehypeAttrs from 'rehype-attr';
|
|
15
16
|
import remarkGfm from 'remark-gfm';
|
|
@@ -20,7 +21,7 @@ import { octiconLink } from './nodes/octiconLink';
|
|
|
20
21
|
|
|
21
22
|
import { RunArgvs, MDToHTMLOptions } from './';
|
|
22
23
|
|
|
23
|
-
export function create(argvs: RunArgvs, options
|
|
24
|
+
export function create(argvs: RunArgvs, options = {} as MDToHTMLOptions) {
|
|
24
25
|
// default github css.
|
|
25
26
|
const cssStr = fs.readFileSync(path.resolve(__dirname, 'github.css'));
|
|
26
27
|
const { markdown } = argvs || {};
|
|
@@ -28,11 +29,13 @@ export function create(argvs: RunArgvs, options: MDToHTMLOptions = {}) {
|
|
|
28
29
|
return unified()
|
|
29
30
|
.use(remarkParse)
|
|
30
31
|
.use(remarkGfm)
|
|
31
|
-
.use(remarkRehype)
|
|
32
|
-
.use(
|
|
32
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
33
|
+
.use(rehypeRaw)
|
|
34
|
+
.use(rehypeSlug)
|
|
33
35
|
.use(rehypeAutolinkHeadings)
|
|
34
36
|
.use(rehypeDocument, {
|
|
35
37
|
...document,
|
|
38
|
+
link: document.link ? document.link : [],
|
|
36
39
|
style: [cssStr.toString(), ...(Array.isArray(document.style) ? document.style : [document.style]) ],
|
|
37
40
|
})
|
|
38
41
|
.use(rehypeFormat)
|
package/src/index.ts
CHANGED
|
@@ -20,11 +20,14 @@ 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 {
|
|
30
|
+
'github-corners'?: RunArgvs['github-corners'];
|
|
28
31
|
document?: Options
|
|
29
32
|
/**
|
|
30
33
|
* rehype-wrap Options
|
|
@@ -66,45 +69,52 @@ export function run(opts = {} as RunArgvs) {
|
|
|
66
69
|
if (argvs.source && !argvs.markdown) {
|
|
67
70
|
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
68
71
|
}
|
|
69
|
-
|
|
72
|
+
|
|
73
|
+
const options = { ...opts, ...argvs, document: { title: argvs.title, meta: [], link: [] } } as MDToHTMLOptions;
|
|
70
74
|
const projectPkg = path.resolve(process.cwd(), 'package.json');
|
|
71
75
|
|
|
72
76
|
let pgkData: any = {};
|
|
73
|
-
let mth: MDToHTMLOptions = {}
|
|
74
77
|
if (fs.existsSync(projectPkg)) {
|
|
75
78
|
pgkData = fs.readJSONSync(projectPkg);
|
|
76
79
|
if (pgkData.name && !options.document.title) {
|
|
77
80
|
options.document.title = pgkData.name;
|
|
78
81
|
}
|
|
82
|
+
if (pgkData.repository && !argvs['github-corners']) {
|
|
83
|
+
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
84
|
+
}
|
|
79
85
|
if (pgkData['markdown-to-html']) {
|
|
80
|
-
mth = pgkData['markdown-to-html'];
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
|
83
91
|
}
|
|
84
|
-
if (!options.wrap) {
|
|
92
|
+
if (!options.wrap && mth.wrap) {
|
|
85
93
|
options.wrap = mth.wrap;
|
|
86
94
|
}
|
|
95
|
+
if (mth['github-corners']) {
|
|
96
|
+
argvs['github-corners'] = mth['github-corners'];
|
|
97
|
+
}
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
|
-
|
|
100
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
101
|
+
options.document.link.push({ rel: 'icon', href: options.favicon });
|
|
102
|
+
}
|
|
90
103
|
if (Array.isArray(options.document.meta)) {
|
|
91
|
-
if (
|
|
92
|
-
options.document.meta.push({ description:
|
|
104
|
+
if (options.description) {
|
|
105
|
+
options.document.meta.push({ description: options.description });
|
|
93
106
|
} else if (pgkData.description) {
|
|
94
107
|
options.document.meta.push({ description: pgkData.description });
|
|
95
108
|
}
|
|
96
|
-
if (
|
|
97
|
-
options.document.meta.push({ keywords:
|
|
109
|
+
if (options.keywords) {
|
|
110
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
98
111
|
} else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
99
112
|
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
100
113
|
}
|
|
101
|
-
if (
|
|
102
|
-
options.document.meta.push({ author:
|
|
114
|
+
if (typeof options.author === 'string') {
|
|
115
|
+
options.document.meta.push({ author: options.author });
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
|
-
if (mth.document && mth.document.meta) {
|
|
106
|
-
options.document.meta = mth.document.meta;
|
|
107
|
-
}
|
|
108
118
|
const output = path.resolve(argvs.output);
|
|
109
119
|
const strMarkdown = create(argvs, options);
|
|
110
120
|
fs.writeFileSync(output, strMarkdown);
|
|
@@ -120,16 +130,17 @@ export function cliHelp() {
|
|
|
120
130
|
console.log(' --source, -s ', 'The path of the target file "README.md".', 'Default: README.md');
|
|
121
131
|
console.log(' --markdown ', 'Markdown string.');
|
|
122
132
|
console.log(' --description ', 'Define a description of your web page.');
|
|
133
|
+
console.log(' --favicon ', 'Add a Favicon to your Site.');
|
|
123
134
|
console.log(' --keywords ', 'Define keywords for search engines.');
|
|
124
135
|
console.log(' --title ', 'The `<title>` tag is required in HTML documents!');
|
|
125
136
|
console.log(' --author ', 'Define the author of a page.');
|
|
126
|
-
console.log(' --description ', 'Describe metadata within an HTML document.');
|
|
127
137
|
console.log(' --github-corners ', 'Add a Github corner to your project page.');
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
export function exampleHelp() {
|
|
131
141
|
console.log('\n Example:\n');
|
|
132
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!"');
|
|
133
144
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"');
|
|
134
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');
|
|
135
146
|
console.log(' \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html');
|