markdown-to-html-cli 2.1.1 → 2.2.2
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-zh.md +10 -6
- package/README.md +10 -6
- package/lib/create.d.ts +1 -1
- package/lib/create.js +24 -13
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/nodes/githubCornersFork.d.ts +6 -0
- package/lib/nodes/githubCornersFork.js +20 -0
- package/lib/nodes/githubCornersFork.js.map +1 -0
- package/lib/styles/github-fork-ribbon.css +91 -0
- package/lib/{github.css → styles/github.css} +0 -0
- package/package.json +6 -6
- package/src/create.ts +24 -14
- package/src/index.ts +8 -5
- package/src/nodes/githubCornersFork.ts +25 -0
- package/src/styles/github-fork-ribbon.css +91 -0
- package/src/{github.css → styles/github.css} +0 -0
- package/test/create.test.ts +8 -0
- package/test/index.test.ts +2 -0
package/README-zh.md
CHANGED
|
@@ -8,7 +8,7 @@ markdown-to-html-cli
|
|
|
8
8
|
[](https://jaywcjlove.github.io/markdown-to-html-cli/lcov-report/)
|
|
9
9
|
[](README.md)
|
|
10
10
|
|
|
11
|
-
将 Markdown 文本转换为 HTML
|
|
11
|
+
将 Markdown 文本转换为 HTML,提供命令行工具和方法。如果您是简单的将少量 markdown 文件(或文本)转换成 HTML 页面,这将对你很有帮助。
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
@@ -95,6 +95,7 @@ Options:
|
|
|
95
95
|
--description Define a description of your web page.
|
|
96
96
|
--favicon Add a Favicon to your Site.
|
|
97
97
|
--github-corners Add a Github corner to your project page.
|
|
98
|
+
--github-corners-fork Github corners style.
|
|
98
99
|
--keywords Define keywords for search engines.
|
|
99
100
|
--markdown Markdown string.
|
|
100
101
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
@@ -110,6 +111,7 @@ Example:
|
|
|
110
111
|
npm markdown-to-html --config="config/conf.json"
|
|
111
112
|
npm markdown-to-html-cli --markdown="Hello World!"
|
|
112
113
|
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
114
|
+
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove --github-corners-fork
|
|
113
115
|
npm markdown-to-html-cli --output coverage/index.html
|
|
114
116
|
npm markdown-to-html-cli --source README.md
|
|
115
117
|
```
|
|
@@ -142,12 +144,14 @@ import { ParsedArgs } from 'minimist';
|
|
|
142
144
|
import { Options } from 'rehype-document';
|
|
143
145
|
export interface CreateOptions extends MDToHTMLOptions { }
|
|
144
146
|
export declare function create(options?: CreateOptions): string;
|
|
145
|
-
export interface RunArgvs extends ParsedArgs {
|
|
147
|
+
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
146
148
|
version?: string;
|
|
147
149
|
source?: string;
|
|
148
150
|
output?: string;
|
|
149
|
-
/** Add a Github corner to your project page */
|
|
151
|
+
/** Add a Github corner to your project page. */
|
|
150
152
|
'github-corners'?: string;
|
|
153
|
+
/** Github corners style. */
|
|
154
|
+
'github-corners-fork'?: boolean;
|
|
151
155
|
/** Markdown string. */
|
|
152
156
|
markdown?: string;
|
|
153
157
|
/** The `<title>` tag is required in HTML documents! */
|
|
@@ -163,10 +167,11 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
163
167
|
/** Define the author of a page */
|
|
164
168
|
author?: string;
|
|
165
169
|
}
|
|
166
|
-
export interface MDToHTMLOptions extends
|
|
167
|
-
'github-corners'?: RunArgvs['github-corners'];
|
|
170
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
168
171
|
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
169
172
|
document?: Options;
|
|
173
|
+
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
|
174
|
+
rewrite?: RehypeRewriteOptions['rewrite'];
|
|
170
175
|
/** rewrite URLs of href and src attributes. */
|
|
171
176
|
reurls?: Record<string, string>;
|
|
172
177
|
/**
|
|
@@ -182,7 +187,6 @@ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
|
|
|
182
187
|
export declare function run(opts?: Omit<RunArgvs, "_">): any;
|
|
183
188
|
export declare const cliHelp: string;
|
|
184
189
|
export declare const exampleHelp: string;
|
|
185
|
-
|
|
186
190
|
```
|
|
187
191
|
|
|
188
192
|
## Development
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ markdown-to-html-cli
|
|
|
8
8
|
[](https://jaywcjlove.github.io/markdown-to-html-cli/lcov-report/)
|
|
9
9
|
[](README-zh.md)
|
|
10
10
|
|
|
11
|
-
Converts markdown text to HTML, Provide command line tools and methods.
|
|
11
|
+
Converts markdown text to HTML, Provide command line tools and methods. If you are simply converting a small number of Markdown files (or text) into HTML pages, this is very helpful for you.
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
@@ -95,6 +95,7 @@ Options:
|
|
|
95
95
|
--description Define a description of your web page.
|
|
96
96
|
--favicon Add a Favicon to your Site.
|
|
97
97
|
--github-corners Add a Github corner to your project page.
|
|
98
|
+
--github-corners-fork Github corners style.
|
|
98
99
|
--keywords Define keywords for search engines.
|
|
99
100
|
--markdown Markdown string.
|
|
100
101
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
@@ -110,6 +111,7 @@ Example:
|
|
|
110
111
|
npm markdown-to-html --config="config/conf.json"
|
|
111
112
|
npm markdown-to-html-cli --markdown="Hello World!"
|
|
112
113
|
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
|
|
114
|
+
npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove --github-corners-fork
|
|
113
115
|
npm markdown-to-html-cli --output coverage/index.html
|
|
114
116
|
npm markdown-to-html-cli --source README.md
|
|
115
117
|
```
|
|
@@ -142,12 +144,14 @@ import { ParsedArgs } from 'minimist';
|
|
|
142
144
|
import { Options } from 'rehype-document';
|
|
143
145
|
export interface CreateOptions extends MDToHTMLOptions { }
|
|
144
146
|
export declare function create(options?: CreateOptions): string;
|
|
145
|
-
export interface RunArgvs extends ParsedArgs {
|
|
147
|
+
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
146
148
|
version?: string;
|
|
147
149
|
source?: string;
|
|
148
150
|
output?: string;
|
|
149
|
-
/** Add a Github corner to your project page */
|
|
151
|
+
/** Add a Github corner to your project page. */
|
|
150
152
|
'github-corners'?: string;
|
|
153
|
+
/** Github corners style. */
|
|
154
|
+
'github-corners-fork'?: boolean;
|
|
151
155
|
/** Markdown string. */
|
|
152
156
|
markdown?: string;
|
|
153
157
|
/** The `<title>` tag is required in HTML documents! */
|
|
@@ -163,10 +167,11 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
163
167
|
/** Define the author of a page */
|
|
164
168
|
author?: string;
|
|
165
169
|
}
|
|
166
|
-
export interface MDToHTMLOptions extends
|
|
167
|
-
'github-corners'?: RunArgvs['github-corners'];
|
|
170
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
168
171
|
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
169
172
|
document?: Options;
|
|
173
|
+
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
|
174
|
+
rewrite?: RehypeRewriteOptions['rewrite'];
|
|
170
175
|
/** rewrite URLs of href and src attributes. */
|
|
171
176
|
reurls?: Record<string, string>;
|
|
172
177
|
/**
|
|
@@ -182,7 +187,6 @@ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
|
|
|
182
187
|
export declare function run(opts?: Omit<RunArgvs, "_">): any;
|
|
183
188
|
export declare const cliHelp: string;
|
|
184
189
|
export declare const exampleHelp: string;
|
|
185
|
-
|
|
186
190
|
```
|
|
187
191
|
|
|
188
192
|
## Development
|
package/lib/create.d.ts
CHANGED
package/lib/create.js
CHANGED
|
@@ -20,11 +20,16 @@ import remarkGemoji from 'remark-gemoji';
|
|
|
20
20
|
import remarkRehype from 'remark-rehype';
|
|
21
21
|
import remarkParse from 'remark-parse';
|
|
22
22
|
import { githubCorners } from './nodes/githubCorners.js';
|
|
23
|
+
import { githubCornersFork } from './nodes/githubCornersFork.js';
|
|
23
24
|
import { octiconLink } from './nodes/octiconLink.js';
|
|
24
25
|
export function create(options = {}) {
|
|
25
26
|
// default github css.
|
|
26
|
-
const cssStr = fs.readFileSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'github.css'));
|
|
27
27
|
const { markdown, document, rewrite, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
28
|
+
let cssStr = fs.readFileSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'styles', 'github.css')).toString();
|
|
29
|
+
if (options['github-corners-fork'] && options['github-corners']) {
|
|
30
|
+
let cssFork = fs.readFileSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'styles', 'github-fork-ribbon.css')).toString();
|
|
31
|
+
cssStr = `${cssStr}${cssFork}`;
|
|
32
|
+
}
|
|
28
33
|
return unified()
|
|
29
34
|
.use(remarkParse)
|
|
30
35
|
.use(remarkGfm)
|
|
@@ -39,13 +44,24 @@ export function create(options = {}) {
|
|
|
39
44
|
.use(rehypeSlug)
|
|
40
45
|
.use(rehypeAutolinkHeadings)
|
|
41
46
|
.use(rehypeWrap, { ...wrap })
|
|
47
|
+
.use(rehypePrism, { ignoreMissing: true })
|
|
48
|
+
.use(rehypeAttrs, { properties: 'attr' })
|
|
49
|
+
.use(rehypeUrls, (url) => {
|
|
50
|
+
if (reurls[url.href]) {
|
|
51
|
+
url.path = reurls[url.href];
|
|
52
|
+
return url.path;
|
|
53
|
+
}
|
|
54
|
+
})
|
|
42
55
|
.use(rehypeRewrite, {
|
|
43
56
|
rewrite: (node, index, parent) => {
|
|
44
|
-
if (rewrite && typeof rewrite === 'function') {
|
|
45
|
-
rewrite(node, index, parent);
|
|
46
|
-
}
|
|
47
57
|
if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
|
|
48
|
-
node.children =
|
|
58
|
+
node.children = Array.isArray(node.children) ? node.children : [];
|
|
59
|
+
if (options['github-corners-fork']) {
|
|
60
|
+
node.children.unshift(githubCornersFork({ href: options['github-corners'] }));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
node.children.unshift(githubCorners({ href: options['github-corners'] }));
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
|
|
51
67
|
const child = node.children[0];
|
|
@@ -54,14 +70,9 @@ export function create(options = {}) {
|
|
|
54
70
|
child.children = [octiconLink()];
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.use(rehypeAttrs, { properties: 'attr' })
|
|
61
|
-
.use(rehypeUrls, (url) => {
|
|
62
|
-
if (reurls[url.href]) {
|
|
63
|
-
url.path = reurls[url.href];
|
|
64
|
-
return url.path;
|
|
73
|
+
if (rewrite && typeof rewrite === 'function') {
|
|
74
|
+
rewrite(node, index, parent);
|
|
75
|
+
}
|
|
65
76
|
}
|
|
66
77
|
})
|
|
67
78
|
.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,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,EAAE;gBAC5C,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aAC9B;QACH,CAAC;KACF,CAAC;SACD,GAAG,CAAC,YAAY,CAAC;SACjB,GAAG,CAAC,SAAS,CAAC;SACd,WAAW,CAAC,QAAQ,CAAC;SACrB,QAAQ,EAAE,CAAC;AAChB,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import { ParsedArgs } from 'minimist';
|
|
|
2
2
|
import { Options } from 'rehype-document';
|
|
3
3
|
import { RehypeRewriteOptions } from 'rehype-rewrite';
|
|
4
4
|
export * from './create';
|
|
5
|
-
export interface RunArgvs extends ParsedArgs {
|
|
5
|
+
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
6
6
|
version?: string;
|
|
7
7
|
source?: string;
|
|
8
8
|
output?: string;
|
|
9
|
-
/** Add a Github corner to your project page */
|
|
9
|
+
/** Add a Github corner to your project page. */
|
|
10
10
|
'github-corners'?: string;
|
|
11
|
+
/** Github corners style. */
|
|
12
|
+
'github-corners-fork'?: boolean;
|
|
11
13
|
/** Markdown string. */
|
|
12
14
|
markdown?: string;
|
|
13
15
|
/** The `<title>` tag is required in HTML documents! */
|
|
@@ -23,8 +25,7 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
23
25
|
/** Define the author of a page */
|
|
24
26
|
author?: string;
|
|
25
27
|
}
|
|
26
|
-
export interface MDToHTMLOptions extends
|
|
27
|
-
'github-corners'?: RunArgvs['github-corners'];
|
|
28
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
28
29
|
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
29
30
|
document?: Options;
|
|
30
31
|
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
package/lib/index.js
CHANGED
|
@@ -89,6 +89,7 @@ export const cliHelp = `\n Usage: markdown-to-html [options] [--help|h]
|
|
|
89
89
|
--description Define a description of your web page.
|
|
90
90
|
--favicon Add a Favicon to your Site.
|
|
91
91
|
--github-corners Add a Github corner to your project page.
|
|
92
|
+
--github-corners-fork Github corners style.
|
|
92
93
|
--keywords Define keywords for search engines.
|
|
93
94
|
--markdown Markdown string.
|
|
94
95
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
@@ -104,6 +105,7 @@ export const exampleHelp = `\n Example:
|
|
|
104
105
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
105
106
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
|
106
107
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli
|
|
108
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove --github-corners-fork
|
|
107
109
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html
|
|
108
110
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--source\x1b[0m README.md
|
|
109
111
|
|
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;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,cAAc,UAAU,CAAC;AAEzB,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,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
|
7
|
+
type: 'element',
|
|
8
|
+
tagName: 'a',
|
|
9
|
+
properties: {
|
|
10
|
+
'aria-label': 'Fork me on Github',
|
|
11
|
+
title: 'Fork me on GitHub',
|
|
12
|
+
target: '__blank',
|
|
13
|
+
className: 'github-fork-ribbon',
|
|
14
|
+
'data-ribbon': 'Fork me on GitHub',
|
|
15
|
+
href,
|
|
16
|
+
},
|
|
17
|
+
children: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=githubCornersFork.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubCornersFork.js","sourceRoot":"","sources":["../../src/nodes/githubCornersFork.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,iBAAiB,CAAC,IAAmB;IACnD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,IAAI,EAAE;QACT,OAAO;KACR;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,GAAG;QACZ,UAAU,EAAE;YACV,YAAY,EAAE,mBAAmB;YACjC,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,oBAAoB;YAC/B,aAAa,EAAE,mBAAmB;YAClC,IAAI;SACL;QACD,QAAQ,EAAE,EAAE;KACb,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.github-fork-ribbon {
|
|
2
|
+
width: 12.1em;
|
|
3
|
+
height: 12.1em;
|
|
4
|
+
position: absolute;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
top: 0;
|
|
7
|
+
right: 0;
|
|
8
|
+
z-index: 9999;
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
font-size: 13px;
|
|
11
|
+
text-decoration: none;
|
|
12
|
+
text-indent: -999999px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.github-fork-ribbon.fixed {
|
|
16
|
+
position: fixed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.github-fork-ribbon:hover, .github-fork-ribbon:active {
|
|
20
|
+
background-color: rgba(0, 0, 0, 0.0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.github-fork-ribbon:before, .github-fork-ribbon:after {
|
|
24
|
+
/* The right and left classes determine the side we attach our banner to */
|
|
25
|
+
position: absolute;
|
|
26
|
+
display: block;
|
|
27
|
+
width: 15.38em;
|
|
28
|
+
height: 1.54em;
|
|
29
|
+
|
|
30
|
+
top: 3.23em;
|
|
31
|
+
right: -3.23em;
|
|
32
|
+
|
|
33
|
+
-webkit-box-sizing: content-box;
|
|
34
|
+
-moz-box-sizing: content-box;
|
|
35
|
+
box-sizing: content-box;
|
|
36
|
+
|
|
37
|
+
-webkit-transform: rotate(45deg);
|
|
38
|
+
-moz-transform: rotate(45deg);
|
|
39
|
+
-ms-transform: rotate(45deg);
|
|
40
|
+
-o-transform: rotate(45deg);
|
|
41
|
+
transform: rotate(45deg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.github-fork-ribbon:before {
|
|
45
|
+
content: "";
|
|
46
|
+
|
|
47
|
+
/* Add a bit of padding to give some substance outside the "stitching" */
|
|
48
|
+
padding: .38em 0;
|
|
49
|
+
|
|
50
|
+
/* Set the base colour */
|
|
51
|
+
background-color: #a00;
|
|
52
|
+
|
|
53
|
+
/* Set a gradient: transparent black at the top to almost-transparent black at the bottom */
|
|
54
|
+
background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0)), to(rgba(0, 0, 0, 0.15)));
|
|
55
|
+
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
56
|
+
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
57
|
+
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
58
|
+
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
59
|
+
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
60
|
+
|
|
61
|
+
/* Add a drop shadow */
|
|
62
|
+
-webkit-box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
63
|
+
-moz-box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
64
|
+
box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
65
|
+
|
|
66
|
+
pointer-events: auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.github-fork-ribbon:after {
|
|
70
|
+
/* Set the text from the data-ribbon attribute */
|
|
71
|
+
content: attr(data-ribbon);
|
|
72
|
+
|
|
73
|
+
/* Set the text properties */
|
|
74
|
+
color: #fff;
|
|
75
|
+
font: 700 1em "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
76
|
+
line-height: 1.54em;
|
|
77
|
+
text-decoration: none;
|
|
78
|
+
text-shadow: 0 -.08em rgba(0, 0, 0, 0.5);
|
|
79
|
+
text-align: center;
|
|
80
|
+
text-indent: 0;
|
|
81
|
+
|
|
82
|
+
/* Set the layout properties */
|
|
83
|
+
padding: .15em 0;
|
|
84
|
+
margin: .15em 0;
|
|
85
|
+
|
|
86
|
+
/* Add "stitching" effect */
|
|
87
|
+
border-width: .08em 0;
|
|
88
|
+
border-style: dotted;
|
|
89
|
+
border-color: #fff;
|
|
90
|
+
border-color: rgba(255, 255, 255, 0.7);
|
|
91
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.2",
|
|
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/",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"exports": "./lib/index.js",
|
|
8
9
|
"bin": {
|
|
9
10
|
"markdown-to-html": "lib/cli.js",
|
|
10
11
|
"markdown-to-html-cli": "lib/cli.js"
|
|
11
12
|
},
|
|
12
|
-
"type": "module",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"start": "node lib/cli.js",
|
|
14
|
+
"start": "node lib/cli.js --github-corners-fork --github-corners 'https://jaywcjlove.github.io'",
|
|
15
15
|
"watch": "tsbb watch --disable-babel -f src/cli.ts",
|
|
16
16
|
"build": "tsbb build --disable-babel -f src/cli.ts && npm run fix",
|
|
17
17
|
"fix": "tsc-esm-fix --target='lib' --ext='.js'",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"@types/minimist": "1.2.2",
|
|
50
50
|
"fs-extra": "10.0.0",
|
|
51
51
|
"minimist": "1.2.5",
|
|
52
|
-
"rehype-attr": "2.0.
|
|
52
|
+
"rehype-attr": "2.0.6",
|
|
53
53
|
"rehype-autolink-headings": "6.1.0",
|
|
54
54
|
"rehype-document": "6.0.0",
|
|
55
55
|
"rehype-format": "4.0.0",
|
|
56
56
|
"rehype-meta": "^3.1.0",
|
|
57
57
|
"rehype-raw": "6.1.0",
|
|
58
|
-
"rehype-rewrite": "3.0.
|
|
58
|
+
"rehype-rewrite": "3.0.4",
|
|
59
59
|
"rehype-slug": "5.0.0",
|
|
60
60
|
"rehype-stringify": "9.0.2",
|
|
61
61
|
"rehype-urls": "1.1.1",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"unified": "10.1.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"tsbb": "3.4.
|
|
71
|
+
"tsbb": "3.4.4"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/create.ts
CHANGED
|
@@ -20,15 +20,20 @@ import remarkGemoji from 'remark-gemoji';
|
|
|
20
20
|
import remarkRehype from 'remark-rehype';
|
|
21
21
|
import remarkParse from 'remark-parse';
|
|
22
22
|
import { githubCorners } from './nodes/githubCorners';
|
|
23
|
+
import { githubCornersFork } from './nodes/githubCornersFork';
|
|
23
24
|
import { octiconLink } from './nodes/octiconLink';
|
|
24
25
|
import { MDToHTMLOptions } from './';
|
|
25
26
|
|
|
26
27
|
export interface CreateOptions extends MDToHTMLOptions { }
|
|
27
28
|
|
|
28
|
-
export function create(options = {} as
|
|
29
|
+
export function create(options = {} as MDToHTMLOptions) {
|
|
29
30
|
// default github css.
|
|
30
|
-
const cssStr = fs.readFileSync(path.resolve(__dirname, 'github.css'));
|
|
31
31
|
const { markdown, document, rewrite, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
|
|
32
|
+
let cssStr = fs.readFileSync(path.resolve(__dirname, 'styles', 'github.css')).toString();
|
|
33
|
+
if (options['github-corners-fork'] && options['github-corners']) {
|
|
34
|
+
let cssFork = fs.readFileSync(path.resolve(__dirname, 'styles', 'github-fork-ribbon.css')).toString();
|
|
35
|
+
cssStr = `${cssStr}${cssFork}`;
|
|
36
|
+
}
|
|
32
37
|
return unified()
|
|
33
38
|
.use(remarkParse)
|
|
34
39
|
.use(remarkGfm)
|
|
@@ -43,13 +48,23 @@ export function create(options = {} as CreateOptions) {
|
|
|
43
48
|
.use(rehypeSlug)
|
|
44
49
|
.use(rehypeAutolinkHeadings)
|
|
45
50
|
.use(rehypeWrap, { ...wrap })
|
|
51
|
+
.use(rehypePrism, { ignoreMissing: true })
|
|
52
|
+
.use(rehypeAttrs, { properties: 'attr' })
|
|
53
|
+
.use(rehypeUrls, (url: any) => {
|
|
54
|
+
if (reurls[url.href]) {
|
|
55
|
+
url.path = reurls[url.href];
|
|
56
|
+
return url.path;
|
|
57
|
+
}
|
|
58
|
+
})
|
|
46
59
|
.use(rehypeRewrite, {
|
|
47
60
|
rewrite: (node, index, parent) => {
|
|
48
|
-
if (rewrite && typeof rewrite === 'function') {
|
|
49
|
-
rewrite(node, index, parent);
|
|
50
|
-
}
|
|
51
61
|
if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
|
|
52
|
-
node.children =
|
|
62
|
+
node.children = Array.isArray(node.children) ? node.children : [];
|
|
63
|
+
if (options['github-corners-fork']) {
|
|
64
|
+
node.children.unshift(githubCornersFork({ href: options['github-corners'] }));
|
|
65
|
+
} else {
|
|
66
|
+
node.children.unshift(githubCorners({ href: options['github-corners'] }));
|
|
67
|
+
}
|
|
53
68
|
}
|
|
54
69
|
if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
|
|
55
70
|
const child = node.children[0];
|
|
@@ -58,14 +73,9 @@ export function create(options = {} as CreateOptions) {
|
|
|
58
73
|
child.children = [octiconLink()];
|
|
59
74
|
}
|
|
60
75
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.use(rehypeAttrs, { properties: 'attr' })
|
|
65
|
-
.use(rehypeUrls, (url: any) => {
|
|
66
|
-
if (reurls[url.href]) {
|
|
67
|
-
url.path = reurls[url.href];
|
|
68
|
-
return url.path;
|
|
76
|
+
if (rewrite && typeof rewrite === 'function') {
|
|
77
|
+
rewrite(node, index, parent);
|
|
78
|
+
}
|
|
69
79
|
}
|
|
70
80
|
})
|
|
71
81
|
.use(rehypeFormat)
|
package/src/index.ts
CHANGED
|
@@ -9,12 +9,14 @@ export * from './create';
|
|
|
9
9
|
|
|
10
10
|
const pkg = fs.readJSONSync(path.resolve(__dirname, '..', 'package.json'));
|
|
11
11
|
|
|
12
|
-
export interface RunArgvs extends ParsedArgs {
|
|
12
|
+
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
13
13
|
version?: string;
|
|
14
14
|
source?: string;
|
|
15
15
|
output?: string;
|
|
16
|
-
/** Add a Github corner to your project page */
|
|
16
|
+
/** Add a Github corner to your project page. */
|
|
17
17
|
'github-corners'?: string;
|
|
18
|
+
/** Github corners style. */
|
|
19
|
+
'github-corners-fork'?: boolean;
|
|
18
20
|
/** Markdown string. */
|
|
19
21
|
markdown?: string;
|
|
20
22
|
/** The `<title>` tag is required in HTML documents! */
|
|
@@ -31,8 +33,7 @@ export interface RunArgvs extends ParsedArgs {
|
|
|
31
33
|
author?: string;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
export interface MDToHTMLOptions extends
|
|
35
|
-
'github-corners'?: RunArgvs['github-corners'];
|
|
36
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
36
37
|
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
37
38
|
document?: Options;
|
|
38
39
|
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
|
@@ -51,7 +52,7 @@ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
54
|
-
const argvs
|
|
55
|
+
const argvs = minimist<RunArgvs>(process.argv.slice(2), {
|
|
55
56
|
alias: {
|
|
56
57
|
help: 'h',
|
|
57
58
|
version: 'v',
|
|
@@ -135,6 +136,7 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
|
135
136
|
--description Define a description of your web page.
|
|
136
137
|
--favicon Add a Favicon to your Site.
|
|
137
138
|
--github-corners Add a Github corner to your project page.
|
|
139
|
+
--github-corners-fork Github corners style.
|
|
138
140
|
--keywords Define keywords for search engines.
|
|
139
141
|
--markdown Markdown string.
|
|
140
142
|
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
@@ -151,6 +153,7 @@ export const exampleHelp: string =`\n Example:
|
|
|
151
153
|
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
152
154
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
|
153
155
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli
|
|
156
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove --github-corners-fork
|
|
154
157
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html
|
|
155
158
|
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--source\x1b[0m README.md
|
|
156
159
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
interface GithubCorners {
|
|
4
|
+
href?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function githubCornersFork(opts: GithubCorners): Element {
|
|
8
|
+
const { href } = opts;
|
|
9
|
+
if (!href) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
type: 'element',
|
|
14
|
+
tagName: 'a',
|
|
15
|
+
properties: {
|
|
16
|
+
'aria-label': 'Fork me on Github',
|
|
17
|
+
title: 'Fork me on GitHub',
|
|
18
|
+
target: '__blank',
|
|
19
|
+
className: 'github-fork-ribbon',
|
|
20
|
+
'data-ribbon': 'Fork me on GitHub',
|
|
21
|
+
href,
|
|
22
|
+
},
|
|
23
|
+
children: []
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.github-fork-ribbon {
|
|
2
|
+
width: 12.1em;
|
|
3
|
+
height: 12.1em;
|
|
4
|
+
position: absolute;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
top: 0;
|
|
7
|
+
right: 0;
|
|
8
|
+
z-index: 9999;
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
font-size: 13px;
|
|
11
|
+
text-decoration: none;
|
|
12
|
+
text-indent: -999999px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.github-fork-ribbon.fixed {
|
|
16
|
+
position: fixed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.github-fork-ribbon:hover, .github-fork-ribbon:active {
|
|
20
|
+
background-color: rgba(0, 0, 0, 0.0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.github-fork-ribbon:before, .github-fork-ribbon:after {
|
|
24
|
+
/* The right and left classes determine the side we attach our banner to */
|
|
25
|
+
position: absolute;
|
|
26
|
+
display: block;
|
|
27
|
+
width: 15.38em;
|
|
28
|
+
height: 1.54em;
|
|
29
|
+
|
|
30
|
+
top: 3.23em;
|
|
31
|
+
right: -3.23em;
|
|
32
|
+
|
|
33
|
+
-webkit-box-sizing: content-box;
|
|
34
|
+
-moz-box-sizing: content-box;
|
|
35
|
+
box-sizing: content-box;
|
|
36
|
+
|
|
37
|
+
-webkit-transform: rotate(45deg);
|
|
38
|
+
-moz-transform: rotate(45deg);
|
|
39
|
+
-ms-transform: rotate(45deg);
|
|
40
|
+
-o-transform: rotate(45deg);
|
|
41
|
+
transform: rotate(45deg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.github-fork-ribbon:before {
|
|
45
|
+
content: "";
|
|
46
|
+
|
|
47
|
+
/* Add a bit of padding to give some substance outside the "stitching" */
|
|
48
|
+
padding: .38em 0;
|
|
49
|
+
|
|
50
|
+
/* Set the base colour */
|
|
51
|
+
background-color: #a00;
|
|
52
|
+
|
|
53
|
+
/* Set a gradient: transparent black at the top to almost-transparent black at the bottom */
|
|
54
|
+
background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0)), to(rgba(0, 0, 0, 0.15)));
|
|
55
|
+
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
56
|
+
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
57
|
+
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
58
|
+
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
59
|
+
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
|
|
60
|
+
|
|
61
|
+
/* Add a drop shadow */
|
|
62
|
+
-webkit-box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
63
|
+
-moz-box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
64
|
+
box-shadow: 0 .15em .23em 0 rgba(0, 0, 0, 0.5);
|
|
65
|
+
|
|
66
|
+
pointer-events: auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.github-fork-ribbon:after {
|
|
70
|
+
/* Set the text from the data-ribbon attribute */
|
|
71
|
+
content: attr(data-ribbon);
|
|
72
|
+
|
|
73
|
+
/* Set the text properties */
|
|
74
|
+
color: #fff;
|
|
75
|
+
font: 700 1em "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
76
|
+
line-height: 1.54em;
|
|
77
|
+
text-decoration: none;
|
|
78
|
+
text-shadow: 0 -.08em rgba(0, 0, 0, 0.5);
|
|
79
|
+
text-align: center;
|
|
80
|
+
text-indent: 0;
|
|
81
|
+
|
|
82
|
+
/* Set the layout properties */
|
|
83
|
+
padding: .15em 0;
|
|
84
|
+
margin: .15em 0;
|
|
85
|
+
|
|
86
|
+
/* Add "stitching" effect */
|
|
87
|
+
border-width: .08em 0;
|
|
88
|
+
border-style: dotted;
|
|
89
|
+
border-color: #fff;
|
|
90
|
+
border-color: rgba(255, 255, 255, 0.7);
|
|
91
|
+
}
|
|
File without changes
|
package/test/create.test.ts
CHANGED
|
@@ -70,6 +70,14 @@ it('github-corners test case', async () => {
|
|
|
70
70
|
});
|
|
71
71
|
expect(html.indexOf('<a aria-label="View source on GitHub" target="__blank" class="github-corner"') === 0).toBeTruthy();
|
|
72
72
|
expect(html.indexOf('https://github.com/jaywcjlove/markdown-to-html-cli') > -1).toBeTruthy();
|
|
73
|
+
|
|
74
|
+
html = create({
|
|
75
|
+
'github-corners-fork': true,
|
|
76
|
+
'github-corners': 'https://github.com/jaywcjlove/markdown-to-html-cli',
|
|
77
|
+
markdown: 'Hello World!',
|
|
78
|
+
document: {},
|
|
79
|
+
});
|
|
80
|
+
expect(html.indexOf('data-ribbon="Fork me on GitHub"') > 0).toBeTruthy();
|
|
73
81
|
});
|
|
74
82
|
|
|
75
83
|
it('rewrite test case', async () => {
|
package/test/index.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import FS from 'fs-extra';
|
|
2
2
|
import { githubCorners } from '../src/nodes/githubCorners';
|
|
3
|
+
import { githubCornersFork } from '../src/nodes/githubCornersFork';
|
|
3
4
|
import { cliHelp, exampleHelp, run } from '../src';
|
|
4
5
|
import pkg from '../package.json';
|
|
5
6
|
|
|
@@ -7,6 +8,7 @@ console.log = jest.fn();
|
|
|
7
8
|
|
|
8
9
|
it('githubCorners test case', async () => {
|
|
9
10
|
expect(githubCorners({ })).toBeUndefined();
|
|
11
|
+
expect(githubCornersFork({ })).toBeUndefined();
|
|
10
12
|
expect(Object.keys(githubCorners({ href: 'https://github.com/jaywcjlove/markdown-to-html-cli' }))).toEqual(expect.arrayContaining(['type', 'tagName', 'properties', 'children']));
|
|
11
13
|
});
|
|
12
14
|
|