markdown-to-html-cli 2.2.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/lib/create.js +1 -1
- package/lib/nodes/octiconLink.js +2 -17
- package/lib/nodes/octiconLink.js.map +1 -1
- package/lib/styles/github.css +858 -275
- package/package.json +5 -1
- package/.github/workflows/ci.yml +0 -63
- package/README-zh.md +0 -200
- package/renovate.json +0 -5
- package/src/cli.ts +0 -5
- package/src/create.ts +0 -85
- package/src/index.ts +0 -160
- package/src/nodes/githubCorners.ts +0 -64
- package/src/nodes/githubCornersFork.ts +0 -25
- package/src/nodes/octiconLink.ts +0 -27
- package/src/styles/github-fork-ribbon.css +0 -91
- package/src/styles/github.css +0 -393
- package/test/create.test.ts +0 -93
- package/test/index.test.ts +0 -89
- package/tsconfig.json +0 -21
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Command line tool generates markdown as html.",
|
|
6
6
|
"homepage": "https://jaywcjlove.github.io/markdown-to-html-cli/",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
8
9
|
"exports": "./lib/index.js",
|
|
9
10
|
"bin": {
|
|
10
11
|
"markdown-to-html": "lib/cli.js",
|
|
@@ -43,6 +44,9 @@
|
|
|
43
44
|
"README.md": "index.html"
|
|
44
45
|
}
|
|
45
46
|
},
|
|
47
|
+
"files": [
|
|
48
|
+
"lib"
|
|
49
|
+
],
|
|
46
50
|
"dependencies": {
|
|
47
51
|
"@mapbox/rehype-prism": "0.8.0",
|
|
48
52
|
"@types/fs-extra": "9.0.13",
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
name: Build and Test
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
build:
|
|
9
|
-
runs-on: ubuntu-18.04
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v2
|
|
12
|
-
- uses: actions/setup-node@v2
|
|
13
|
-
with:
|
|
14
|
-
node-version: 14
|
|
15
|
-
|
|
16
|
-
- run: npm install
|
|
17
|
-
- run: npm run build
|
|
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 --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
|
-
- run: node lib/cli.js -s README-zh.md --output coverage/index.zh.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>'
|
|
21
|
-
|
|
22
|
-
- run: npm i coverage-badges-cli -g
|
|
23
|
-
- run: coverage-badges
|
|
24
|
-
|
|
25
|
-
- name: Deploy
|
|
26
|
-
uses: peaceiris/actions-gh-pages@v3
|
|
27
|
-
with:
|
|
28
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
29
|
-
publish_dir: ./coverage
|
|
30
|
-
|
|
31
|
-
- name: Create Tag
|
|
32
|
-
id: create_tag
|
|
33
|
-
uses: jaywcjlove/create-tag-action@v1.2.1
|
|
34
|
-
with:
|
|
35
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
36
|
-
package-path: ./package.json
|
|
37
|
-
|
|
38
|
-
- name: Generate Changelog
|
|
39
|
-
id: changelog
|
|
40
|
-
uses: jaywcjlove/changelog-generator@v1.4.6
|
|
41
|
-
with:
|
|
42
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
43
|
-
head-ref: ${{steps.create_tag.outputs.version}}
|
|
44
|
-
filter-author: (小弟调调™|Renovate Bot)
|
|
45
|
-
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
|
|
46
|
-
|
|
47
|
-
- name: Create Release
|
|
48
|
-
uses: ncipollo/release-action@v1
|
|
49
|
-
if: steps.create_tag.outputs.successful
|
|
50
|
-
with:
|
|
51
|
-
name: ${{ steps.create_tag.outputs.version }}
|
|
52
|
-
tag: ${{ steps.create_tag.outputs.version }}
|
|
53
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
54
|
-
body: |
|
|
55
|
-
[](https://uiwjs.github.io/npm-unpkg/#/pkg/markdown-to-html-cli@${{steps.changelog.outputs.version}}/file/README.md)
|
|
56
|
-
|
|
57
|
-
${{ steps.changelog.outputs.compareurl }}
|
|
58
|
-
|
|
59
|
-
${{ steps.changelog.outputs.changelog }}
|
|
60
|
-
|
|
61
|
-
- run: npm install @jsdevtools/npm-publish -g
|
|
62
|
-
- run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json
|
|
63
|
-
|
package/README-zh.md
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
markdown-to-html-cli
|
|
2
|
-
===
|
|
3
|
-
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/markdown-to-html-cli)
|
|
6
|
-
[](https://www.npmjs.com/package/markdown-to-html-cli)
|
|
7
|
-
[](https://github.com/jaywcjlove/markdown-to-html-cli/actions/workflows/ci.yml)
|
|
8
|
-
[](https://jaywcjlove.github.io/markdown-to-html-cli/lcov-report/)
|
|
9
|
-
[](README.md)
|
|
10
|
-
|
|
11
|
-
将 Markdown 文本转换为 HTML,提供命令行工具和方法。如果您是简单的将少量 markdown 文件(或文本)转换成 HTML 页面,这将对你很有帮助。
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
在 Github [Actions](https://github.com/actions) 中使用。
|
|
16
|
-
|
|
17
|
-
```yml
|
|
18
|
-
- run: npm i markdown-to-html-cli -g
|
|
19
|
-
- run: markdown-to-html --output coverage/index.html
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
使用命令
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
{
|
|
26
|
-
"scripts": {
|
|
27
|
-
"start": "markdown-to-html --output coverage/index.html"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"markdown-to-html-cli": "latest"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
在 [Nodejs](https://nodejs.org) 中使用。
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
import { create } from 'markdown-to-html-cli';
|
|
39
|
-
|
|
40
|
-
const html = create({
|
|
41
|
-
markdown: 'Hello World! **Bold**\n# Title',
|
|
42
|
-
document: {
|
|
43
|
-
style: ['body { background: red; }'],
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
// => HTML String
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## 安装
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
$ npm i markdown-to-html-cli
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## 在 package.json 中配置
|
|
56
|
-
|
|
57
|
-
可以通过 `--config="config/conf.json"` 指定配置,默认可以在 `package.json`。
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
{
|
|
61
|
-
"markdown-to-html": {
|
|
62
|
-
"document": {
|
|
63
|
-
"title": "markdown-to-html-cli",
|
|
64
|
-
"description": "Command line tool generates markdown as html.",
|
|
65
|
-
"style": "body { color: red; }",
|
|
66
|
-
"meta": [
|
|
67
|
-
{ "description": "Command line tool generates markdown as html." },
|
|
68
|
-
{ "keywords": "store,localStorage,lightweight,JavaScript" }
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
"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>",
|
|
72
|
-
"github-corners": "https://github.com/jaywcjlove/markdown-to-html-cli",
|
|
73
|
-
"reurls": {
|
|
74
|
-
"README-zh.md": "index.zh.html",
|
|
75
|
-
"README.md": "index.html"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
- [`name`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L2) -> `'markdown-to-html'.title` - 定义 `<title>` 文档标题内容!
|
|
82
|
-
- [`description`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L4) -> `'markdown-to-html'.description` - 定义您的网页的描述。
|
|
83
|
-
- [`repository.url`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L22) -> `'markdown-to-html'.github-corners` - 在你的项目页面添加一个 Github Corners。
|
|
84
|
-
- [`keywords`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L24-L30) -> `'markdown-to-html'.document.meta` - 定义搜索引擎的关键字。
|
|
85
|
-
|
|
86
|
-
## 命令帮助
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
Usage: markdown-to-html [options] [--help|h]
|
|
90
|
-
|
|
91
|
-
Options:
|
|
92
|
-
|
|
93
|
-
--author Define the author of a page.
|
|
94
|
-
--config, -o Specify the configuration file. Default: "<process.cwd()>/package.json".
|
|
95
|
-
--description Define a description of your web page.
|
|
96
|
-
--favicon Add a Favicon to your Site.
|
|
97
|
-
--github-corners Add a Github corner to your project page.
|
|
98
|
-
--github-corners-fork Github corners style.
|
|
99
|
-
--keywords Define keywords for search engines.
|
|
100
|
-
--markdown Markdown string.
|
|
101
|
-
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
102
|
-
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
103
|
-
--title The `<title>` tag is required in HTML documents!
|
|
104
|
-
--version, -v Show version number
|
|
105
|
-
--help, -h Displays help information.
|
|
106
|
-
|
|
107
|
-
Example:
|
|
108
|
-
|
|
109
|
-
npm markdown-to-html-cli
|
|
110
|
-
npm markdown-to-html --title="Hello World!"
|
|
111
|
-
npm markdown-to-html --config="config/conf.json"
|
|
112
|
-
npm markdown-to-html-cli --markdown="Hello World!"
|
|
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
|
|
115
|
-
npm markdown-to-html-cli --output coverage/index.html
|
|
116
|
-
npm markdown-to-html-cli --source README.md
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Markdown Features
|
|
120
|
-
|
|
121
|
-
### 支持 CSS 样式定义
|
|
122
|
-
|
|
123
|
-
使用 HTML 注释 [`<!--rehype:xxx-->`](https://github.com/jaywcjlove/rehype-attr)<!--rehype:style=color: red;--> 让 Markdown 支持样式自定义。
|
|
124
|
-
|
|
125
|
-
```markdown
|
|
126
|
-
## Title
|
|
127
|
-
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
|
|
128
|
-
|
|
129
|
-
Markdown Supports **Style**<!--rehype:style=color: red;-->
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 支持 [GFM 注脚](https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/)
|
|
133
|
-
|
|
134
|
-
```markdown
|
|
135
|
-
Here is a simple footnote[^1]. With some additional text after it.
|
|
136
|
-
|
|
137
|
-
[^1]: My reference.
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## API
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
import { ParsedArgs } from 'minimist';
|
|
144
|
-
import { Options } from 'rehype-document';
|
|
145
|
-
export interface CreateOptions extends MDToHTMLOptions { }
|
|
146
|
-
export declare function create(options?: CreateOptions): string;
|
|
147
|
-
export interface RunArgvs extends ParsedArgs {
|
|
148
|
-
version?: string;
|
|
149
|
-
source?: string;
|
|
150
|
-
output?: string;
|
|
151
|
-
/** Add a Github corner to your project page */
|
|
152
|
-
'github-corners'?: string;
|
|
153
|
-
/** Markdown string. */
|
|
154
|
-
markdown?: string;
|
|
155
|
-
/** The `<title>` tag is required in HTML documents! */
|
|
156
|
-
title?: string;
|
|
157
|
-
/** Specify the configuration file. Default: `<process.cwd()>/package.json` */
|
|
158
|
-
config?: string;
|
|
159
|
-
/** Define a description of your web page */
|
|
160
|
-
description?: string;
|
|
161
|
-
/** Define keywords for search engines */
|
|
162
|
-
keywords?: string;
|
|
163
|
-
/** Add a Favicon to your Site */
|
|
164
|
-
favicon?: string;
|
|
165
|
-
/** Define the author of a page */
|
|
166
|
-
author?: string;
|
|
167
|
-
}
|
|
168
|
-
export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
|
|
169
|
-
'github-corners'?: RunArgvs['github-corners'];
|
|
170
|
-
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
171
|
-
document?: Options;
|
|
172
|
-
/** rewrite URLs of href and src attributes. */
|
|
173
|
-
reurls?: Record<string, string>;
|
|
174
|
-
/**
|
|
175
|
-
* rehype-wrap Options
|
|
176
|
-
* Wrap selected elements with a given element
|
|
177
|
-
* https://github.com/mrzmmr/rehype-wrap/tree/2402bcdb8ea25bd0948cda72e96d16e65a18c1e9#options
|
|
178
|
-
*/
|
|
179
|
-
wrap?: {
|
|
180
|
-
selector?: string;
|
|
181
|
-
wrapper?: string;
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
export declare function run(opts?: Omit<RunArgvs, "_">): any;
|
|
185
|
-
export declare const cliHelp: string;
|
|
186
|
-
export declare const exampleHelp: string;
|
|
187
|
-
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Development
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
$ npm i
|
|
194
|
-
$ npm run build
|
|
195
|
-
$ npm run watch
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
## License
|
|
199
|
-
|
|
200
|
-
MIT © [Kenny Wong](https://wangchujiang.com/)
|
package/src/cli.ts
DELETED
package/src/create.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { unified } from 'unified';
|
|
4
|
-
import rehypeDocument from 'rehype-document';
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import rehypePrism from '@mapbox/rehype-prism';
|
|
7
|
-
import stringify from 'rehype-stringify';
|
|
8
|
-
import rehypeSlug from 'rehype-slug';
|
|
9
|
-
import rehypeFormat from 'rehype-format';
|
|
10
|
-
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import rehypeUrls from 'rehype-urls';
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
import rehypeWrap from 'rehype-wrap';
|
|
15
|
-
import rehypeRaw from 'rehype-raw';
|
|
16
|
-
import rehypeRewrite from 'rehype-rewrite';
|
|
17
|
-
import rehypeAttrs from 'rehype-attr';
|
|
18
|
-
import remarkGfm from 'remark-gfm';
|
|
19
|
-
import remarkGemoji from 'remark-gemoji';
|
|
20
|
-
import remarkRehype from 'remark-rehype';
|
|
21
|
-
import remarkParse from 'remark-parse';
|
|
22
|
-
import { githubCorners } from './nodes/githubCorners';
|
|
23
|
-
import { githubCornersFork } from './nodes/githubCornersFork';
|
|
24
|
-
import { octiconLink } from './nodes/octiconLink';
|
|
25
|
-
import { MDToHTMLOptions } from './';
|
|
26
|
-
|
|
27
|
-
export interface CreateOptions extends MDToHTMLOptions { }
|
|
28
|
-
|
|
29
|
-
export function create(options = {} as MDToHTMLOptions) {
|
|
30
|
-
// default github css.
|
|
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
|
-
}
|
|
37
|
-
return unified()
|
|
38
|
-
.use(remarkParse)
|
|
39
|
-
.use(remarkGfm)
|
|
40
|
-
.use(remarkGemoji)
|
|
41
|
-
.use(remarkRehype, { allowDangerousHtml: true })
|
|
42
|
-
.use(rehypeRaw)
|
|
43
|
-
.use(document ? rehypeDocument : undefined, {
|
|
44
|
-
...document,
|
|
45
|
-
link: document && document.link ? (Array.isArray(document.link) ? document.link : [document.link]) : [],
|
|
46
|
-
style: [cssStr.toString().replace(/\n/g, ''), ...(document ? (Array.isArray(document.style) ? document.style : [document.style]) : []) ],
|
|
47
|
-
})
|
|
48
|
-
.use(rehypeSlug)
|
|
49
|
-
.use(rehypeAutolinkHeadings)
|
|
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
|
-
})
|
|
59
|
-
.use(rehypeRewrite, {
|
|
60
|
-
rewrite: (node, index, parent) => {
|
|
61
|
-
if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
|
|
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
|
-
}
|
|
68
|
-
}
|
|
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) {
|
|
70
|
-
const child = node.children[0];
|
|
71
|
-
if (child && child.type === 'element' && child.properties) {
|
|
72
|
-
child.properties = { className: 'anchor', ...child.properties };
|
|
73
|
-
child.children = [octiconLink()];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (rewrite && typeof rewrite === 'function') {
|
|
77
|
-
rewrite(node, index, parent);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
.use(rehypeFormat)
|
|
82
|
-
.use(stringify)
|
|
83
|
-
.processSync(markdown)
|
|
84
|
-
.toString();
|
|
85
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import minimist, { ParsedArgs } from 'minimist';
|
|
4
|
-
import { Options } from 'rehype-document';
|
|
5
|
-
import { RehypeRewriteOptions } from 'rehype-rewrite';
|
|
6
|
-
import { create } from './create';
|
|
7
|
-
|
|
8
|
-
export * from './create';
|
|
9
|
-
|
|
10
|
-
const pkg = fs.readJSONSync(path.resolve(__dirname, '..', 'package.json'));
|
|
11
|
-
|
|
12
|
-
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
13
|
-
version?: string;
|
|
14
|
-
source?: string;
|
|
15
|
-
output?: string;
|
|
16
|
-
/** Add a Github corner to your project page. */
|
|
17
|
-
'github-corners'?: string;
|
|
18
|
-
/** Github corners style. */
|
|
19
|
-
'github-corners-fork'?: boolean;
|
|
20
|
-
/** Markdown string. */
|
|
21
|
-
markdown?: string;
|
|
22
|
-
/** The `<title>` tag is required in HTML documents! */
|
|
23
|
-
title?: string;
|
|
24
|
-
/** Specify the configuration file. Default: `<process.cwd()>/package.json` */
|
|
25
|
-
config?: string;
|
|
26
|
-
/** Define a description of your web page */
|
|
27
|
-
description?: string;
|
|
28
|
-
/** Define keywords for search engines */
|
|
29
|
-
keywords?: string;
|
|
30
|
-
/** Add a Favicon to your Site */
|
|
31
|
-
favicon?: string;
|
|
32
|
-
/** Define the author of a page */
|
|
33
|
-
author?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface MDToHTMLOptions extends RunArgvs {
|
|
37
|
-
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
38
|
-
document?: Options;
|
|
39
|
-
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
|
40
|
-
rewrite?: RehypeRewriteOptions['rewrite'];
|
|
41
|
-
/** rewrite URLs of href and src attributes. */
|
|
42
|
-
reurls?: Record<string, string>;
|
|
43
|
-
/**
|
|
44
|
-
* rehype-wrap Options
|
|
45
|
-
* Wrap selected elements with a given element
|
|
46
|
-
* https://github.com/mrzmmr/rehype-wrap/tree/2402bcdb8ea25bd0948cda72e96d16e65a18c1e9#options
|
|
47
|
-
*/
|
|
48
|
-
wrap?: {
|
|
49
|
-
selector?: string;
|
|
50
|
-
wrapper?: string;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
55
|
-
const argvs = minimist<RunArgvs>(process.argv.slice(2), {
|
|
56
|
-
alias: {
|
|
57
|
-
help: 'h',
|
|
58
|
-
version: 'v',
|
|
59
|
-
config: 'c',
|
|
60
|
-
source: 's',
|
|
61
|
-
output: 'o',
|
|
62
|
-
},
|
|
63
|
-
default: {
|
|
64
|
-
version: opts.v || opts.version || false,
|
|
65
|
-
help: opts.h || opts.help || false,
|
|
66
|
-
source: opts.s || opts.source || 'README.md',
|
|
67
|
-
markdown: opts.markdown || '',
|
|
68
|
-
description: opts.description || '',
|
|
69
|
-
output: opts.o || opts.output || 'index.html',
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
if (argvs.h || argvs.help) {
|
|
73
|
-
console.log(`${cliHelp}${exampleHelp}`);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (argvs.v || argvs.version) {
|
|
77
|
-
console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
|
|
78
|
-
return pkg.version;
|
|
79
|
-
}
|
|
80
|
-
if (argvs.source && !argvs.markdown) {
|
|
81
|
-
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let options = { ...opts, ...argvs, document: { title: argvs.title, meta: [], link: [] } } as MDToHTMLOptions;
|
|
85
|
-
const projectPkg = path.resolve(process.cwd(), opts.config || argvs.config || 'package.json');
|
|
86
|
-
let pgkData: any = {};
|
|
87
|
-
if (fs.existsSync(projectPkg)) {
|
|
88
|
-
pgkData = fs.readJSONSync(projectPkg);
|
|
89
|
-
if (pgkData.name && !options.document.title) {
|
|
90
|
-
options.document.title = pgkData.name;
|
|
91
|
-
}
|
|
92
|
-
if (pgkData.repository && !argvs['github-corners']) {
|
|
93
|
-
argvs['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
94
|
-
}
|
|
95
|
-
if (pgkData['markdown-to-html']) {
|
|
96
|
-
const mth = pgkData['markdown-to-html'] as MDToHTMLOptions;
|
|
97
|
-
const { title, meta, link } = options.document;
|
|
98
|
-
options = { ...options, ...mth, document: { title, meta, link, ...mth.document } }
|
|
99
|
-
if (mth['github-corners']) {
|
|
100
|
-
argvs['github-corners'] = mth['github-corners'];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (argvs['github-corners']) {
|
|
105
|
-
argvs['github-corners'] = argvs['github-corners'].replace(/^git[+]/, '')
|
|
106
|
-
}
|
|
107
|
-
if (Array.isArray(options.document.link) && options.favicon) {
|
|
108
|
-
options.document.link.push({ rel: 'icon', href: options.favicon, type: 'image/x-icon' });
|
|
109
|
-
}
|
|
110
|
-
if (Array.isArray(options.document.meta)) {
|
|
111
|
-
if (options.description) {
|
|
112
|
-
options.document.meta.push({ description: options.description });
|
|
113
|
-
} else if (pgkData.description) {
|
|
114
|
-
options.document.meta.push({ description: pgkData.description });
|
|
115
|
-
}
|
|
116
|
-
if (options.keywords) {
|
|
117
|
-
options.document.meta.push({ keywords: options.keywords });
|
|
118
|
-
} else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
119
|
-
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
120
|
-
}
|
|
121
|
-
if (typeof options.author === 'string') {
|
|
122
|
-
options.document.meta.push({ author: options.author });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const output = path.resolve(argvs.output);
|
|
126
|
-
const strMarkdown = create({ ...argvs, ...options });
|
|
127
|
-
fs.writeFileSync(output, strMarkdown);
|
|
128
|
-
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
132
|
-
|
|
133
|
-
Options:\n
|
|
134
|
-
--author Define the author of a page.
|
|
135
|
-
--config, -o Specify the configuration file. Default: "<process.cwd()>/package.json".
|
|
136
|
-
--description Define a description of your web page.
|
|
137
|
-
--favicon Add a Favicon to your Site.
|
|
138
|
-
--github-corners Add a Github corner to your project page.
|
|
139
|
-
--github-corners-fork Github corners style.
|
|
140
|
-
--keywords Define keywords for search engines.
|
|
141
|
-
--markdown Markdown string.
|
|
142
|
-
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
143
|
-
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
144
|
-
--title The \`<title>\` tag is required in HTML documents!
|
|
145
|
-
--version, -v Show version number
|
|
146
|
-
--help, -h Displays help information.
|
|
147
|
-
`;
|
|
148
|
-
|
|
149
|
-
export const exampleHelp: string =`\n Example:
|
|
150
|
-
|
|
151
|
-
\x1b[35mnpm\x1b[0m markdown-to-html-cli
|
|
152
|
-
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
|
|
153
|
-
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
154
|
-
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
|
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
|
|
157
|
-
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html
|
|
158
|
-
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--source\x1b[0m README.md
|
|
159
|
-
|
|
160
|
-
`;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Element } from 'hast';
|
|
2
|
-
|
|
3
|
-
interface GithubCorners {
|
|
4
|
-
href?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function githubCorners(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': 'View source on GitHub',
|
|
17
|
-
target: '__blank',
|
|
18
|
-
className: 'github-corner',
|
|
19
|
-
href,
|
|
20
|
-
},
|
|
21
|
-
children: [
|
|
22
|
-
{
|
|
23
|
-
type: 'element',
|
|
24
|
-
tagName: 'svg',
|
|
25
|
-
properties: {
|
|
26
|
-
width: '54',
|
|
27
|
-
height: '54',
|
|
28
|
-
viewBox: '0 0 250 250',
|
|
29
|
-
'aria-hidden': 'true',
|
|
30
|
-
style: 'fill: rgb(32, 34, 37); color: rgb(255, 255, 255); position: fixed; z-index: 99999; border: 0px; top: 0px; right: 0px;'
|
|
31
|
-
},
|
|
32
|
-
children: [
|
|
33
|
-
{
|
|
34
|
-
type: 'element',
|
|
35
|
-
tagName: 'path',
|
|
36
|
-
properties: {
|
|
37
|
-
d: 'M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z'
|
|
38
|
-
},
|
|
39
|
-
children: [],
|
|
40
|
-
}, {
|
|
41
|
-
type: 'element',
|
|
42
|
-
tagName: 'path',
|
|
43
|
-
children: [],
|
|
44
|
-
properties: {
|
|
45
|
-
style: 'transform-origin: 130px 106px;',
|
|
46
|
-
className: 'octo-arm',
|
|
47
|
-
fill: 'currentColor',
|
|
48
|
-
d: 'M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2'
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
type: 'element',
|
|
52
|
-
tagName: 'path',
|
|
53
|
-
children: [],
|
|
54
|
-
properties: {
|
|
55
|
-
className: 'octo-body',
|
|
56
|
-
fill: 'currentColor',
|
|
57
|
-
d: 'M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
package/src/nodes/octiconLink.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Element } from 'hast';
|
|
2
|
-
|
|
3
|
-
export function octiconLink(): Element {
|
|
4
|
-
return {
|
|
5
|
-
type: 'element',
|
|
6
|
-
tagName: 'svg',
|
|
7
|
-
properties: {
|
|
8
|
-
class: 'octicon octicon-link',
|
|
9
|
-
viewBox: '0 0 16 16',
|
|
10
|
-
version: '1.1',
|
|
11
|
-
width: '16',
|
|
12
|
-
height: '16',
|
|
13
|
-
ariaHidden: 'true',
|
|
14
|
-
},
|
|
15
|
-
children: [
|
|
16
|
-
{
|
|
17
|
-
type: 'element',
|
|
18
|
-
tagName: 'path',
|
|
19
|
-
properties: {
|
|
20
|
-
fillRule: 'evenodd',
|
|
21
|
-
d: 'M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z',
|
|
22
|
-
},
|
|
23
|
-
children: []
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
}
|