markdown-to-html-cli 2.0.1 → 2.1.1

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.
@@ -17,6 +17,7 @@ jobs:
17
17
  - run: npm run build
18
18
  - run: npm run coverage
19
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>'
20
21
 
21
22
  - run: npm i coverage-badges-cli -g
22
23
  - run: coverage-badges
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 小弟调调™
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README-zh.md ADDED
@@ -0,0 +1,198 @@
1
+ markdown-to-html-cli
2
+ ===
3
+ <!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
4
+
5
+ [![Downloads](https://img.shields.io/npm/dm/markdown-to-html-cli.svg?style=flat)](https://www.npmjs.com/package/markdown-to-html-cli)
6
+ [![npm version](https://img.shields.io/npm/v/markdown-to-html-cli.svg)](https://www.npmjs.com/package/markdown-to-html-cli)
7
+ [![Build and Test](https://github.com/jaywcjlove/markdown-to-html-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/markdown-to-html-cli/actions/workflows/ci.yml)
8
+ [![Coverage Status](https://jaywcjlove.github.io/markdown-to-html-cli/badges.svg)](https://jaywcjlove.github.io/markdown-to-html-cli/lcov-report/)
9
+ [![English Document](https://jaywcjlove.github.io/sb/lang/english.svg)](README.md)
10
+
11
+ 将 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
+ --keywords Define keywords for search engines.
99
+ --markdown Markdown string.
100
+ --output, -o Output static pages to the specified directory. Default: "index.html"
101
+ --source, -s The path of the target file "README.md". Default: "README.md"
102
+ --title The `<title>` tag is required in HTML documents!
103
+ --version, -v Show version number
104
+ --help, -h Displays help information.
105
+
106
+ Example:
107
+
108
+ npm markdown-to-html-cli
109
+ npm markdown-to-html --title="Hello World!"
110
+ npm markdown-to-html --config="config/conf.json"
111
+ npm markdown-to-html-cli --markdown="Hello World!"
112
+ npm markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli
113
+ npm markdown-to-html-cli --output coverage/index.html
114
+ npm markdown-to-html-cli --source README.md
115
+ ```
116
+
117
+ ## Markdown Features
118
+
119
+ ### 支持 CSS 样式定义
120
+
121
+ 使用 HTML 注释 [`<!--rehype:xxx-->`](https://github.com/jaywcjlove/rehype-attr)<!--rehype:style=color: red;--> 让 Markdown 支持样式自定义。
122
+
123
+ ```markdown
124
+ ## Title
125
+ <!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
126
+
127
+ Markdown Supports **Style**<!--rehype:style=color: red;-->
128
+ ```
129
+
130
+ ### 支持 [GFM 注脚](https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/)
131
+
132
+ ```markdown
133
+ Here is a simple footnote[^1]. With some additional text after it.
134
+
135
+ [^1]: My reference.
136
+ ```
137
+
138
+ ## API
139
+
140
+ ```ts
141
+ import { ParsedArgs } from 'minimist';
142
+ import { Options } from 'rehype-document';
143
+ export interface CreateOptions extends MDToHTMLOptions { }
144
+ export declare function create(options?: CreateOptions): string;
145
+ export interface RunArgvs extends ParsedArgs {
146
+ version?: string;
147
+ source?: string;
148
+ output?: string;
149
+ /** Add a Github corner to your project page */
150
+ 'github-corners'?: string;
151
+ /** Markdown string. */
152
+ markdown?: string;
153
+ /** The `<title>` tag is required in HTML documents! */
154
+ title?: string;
155
+ /** Specify the configuration file. Default: `<process.cwd()>/package.json` */
156
+ config?: string;
157
+ /** Define a description of your web page */
158
+ description?: string;
159
+ /** Define keywords for search engines */
160
+ keywords?: string;
161
+ /** Add a Favicon to your Site */
162
+ favicon?: string;
163
+ /** Define the author of a page */
164
+ author?: string;
165
+ }
166
+ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
167
+ 'github-corners'?: RunArgvs['github-corners'];
168
+ /** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
169
+ document?: Options;
170
+ /** rewrite URLs of href and src attributes. */
171
+ reurls?: Record<string, string>;
172
+ /**
173
+ * rehype-wrap Options
174
+ * Wrap selected elements with a given element
175
+ * https://github.com/mrzmmr/rehype-wrap/tree/2402bcdb8ea25bd0948cda72e96d16e65a18c1e9#options
176
+ */
177
+ wrap?: {
178
+ selector?: string;
179
+ wrapper?: string;
180
+ };
181
+ }
182
+ export declare function run(opts?: Omit<RunArgvs, "_">): any;
183
+ export declare const cliHelp: string;
184
+ export declare const exampleHelp: string;
185
+
186
+ ```
187
+
188
+ ## Development
189
+
190
+ ```bash
191
+ $ npm i
192
+ $ npm run build
193
+ $ npm run watch
194
+ ```
195
+
196
+ ## License
197
+
198
+ MIT © [Kenny Wong](https://wangchujiang.com/)
package/README.md CHANGED
@@ -6,18 +6,46 @@ markdown-to-html-cli
6
6
  [![npm version](https://img.shields.io/npm/v/markdown-to-html-cli.svg)](https://www.npmjs.com/package/markdown-to-html-cli)
7
7
  [![Build and Test](https://github.com/jaywcjlove/markdown-to-html-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/markdown-to-html-cli/actions/workflows/ci.yml)
8
8
  [![Coverage Status](https://jaywcjlove.github.io/markdown-to-html-cli/badges.svg)](https://jaywcjlove.github.io/markdown-to-html-cli/lcov-report/)
9
+ [![中文文档](https://jaywcjlove.github.io/sb/lang/chinese.svg)](README-zh.md)
9
10
 
10
- Command line tool generates markdown as html.
11
+ Converts markdown text to HTML, Provide command line tools and methods.
11
12
 
12
13
  ## Usage
13
14
 
14
- Used in Github Actions.
15
+ Used in Github [Actions](https://github.com/actions).
15
16
 
16
17
  ```yml
17
18
  - run: npm i markdown-to-html-cli -g
18
19
  - run: markdown-to-html --output coverage/index.html
19
20
  ```
20
21
 
22
+ Using With Command.
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
+ Used in [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
+
21
49
  ## Install
22
50
 
23
51
  ```shell
@@ -26,7 +54,7 @@ $ npm i markdown-to-html-cli
26
54
 
27
55
  ## Configure in package.json
28
56
 
29
- The configuration can be specified through `--config="config/conf.json"`.
57
+ The configuration can be specified through `--config="config/conf.json"`, It can be in `package.json` by default.
30
58
 
31
59
  ```js
32
60
  {
@@ -50,10 +78,10 @@ The configuration can be specified through `--config="config/conf.json"`.
50
78
  }
51
79
  ```
52
80
 
53
- - [`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!
81
+ - [`name`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L2) -> `'markdown-to-html'.title` - Define the content of the `<title>` document title!
54
82
  - [`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.
55
- - [`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.
56
- - [`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.
83
+ - [`repository.url`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L22) -> `'markdown-to-html'.github-corners` - Add a Github corner to your project page.
84
+ - [`keywords`](https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L24-L30) -> `'markdown-to-html'.document.meta` - Define keywords for search engines.
57
85
 
58
86
  ## Command Help
59
87
 
@@ -107,7 +135,7 @@ Here is a simple footnote[^1]. With some additional text after it.
107
135
  [^1]: My reference.
108
136
  ```
109
137
 
110
- ## API
138
+ ## API
111
139
 
112
140
  ```ts
113
141
  import { ParsedArgs } from 'minimist';
package/lib/create.js CHANGED
@@ -24,7 +24,7 @@ import { octiconLink } from './nodes/octiconLink.js';
24
24
  export function create(options = {}) {
25
25
  // default github css.
26
26
  const cssStr = fs.readFileSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'github.css'));
27
- const { markdown, document, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
27
+ const { markdown, document, rewrite, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
28
28
  return unified()
29
29
  .use(remarkParse)
30
30
  .use(remarkGfm)
@@ -41,16 +41,17 @@ export function create(options = {}) {
41
41
  .use(rehypeWrap, { ...wrap })
42
42
  .use(rehypeRewrite, {
43
43
  rewrite: (node, index, parent) => {
44
- if (node.type == 'element') {
45
- if (node.tagName === 'body' && options['github-corners']) {
46
- node.children = [githubCorners({ href: options['github-corners'] }), ...node.children];
47
- }
48
- if (/h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
49
- const child = node.children[0];
50
- if (child && child.type === 'element' && child.properties) {
51
- child.properties = { class: 'anchor', ...child.properties };
52
- child.children = [octiconLink()];
53
- }
44
+ if (rewrite && typeof rewrite === 'function') {
45
+ rewrite(node, index, parent);
46
+ }
47
+ if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
48
+ node.children = [githubCorners({ href: options['github-corners'] }), ...node.children];
49
+ }
50
+ 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
+ const child = node.children[0];
52
+ if (child && child.type === 'element' && child.properties) {
53
+ child.properties = { className: 'anchor', ...child.properties };
54
+ child.children = [octiconLink()];
54
55
  }
55
56
  }
56
57
  }
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,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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D,KAAK,CAAC,UAAU,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;oBAChE,KAAK,CAAC,QAAQ,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;iBAClC;aACF;QACH,CAAC;KACF,CAAC;SACD,GAAG,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SACzC,GAAG,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;SACxC,GAAG,CAAC,UAAU,EAAE,CAAC,GAAQ,EAAE,EAAE;QAC5B,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACpB,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5B,OAAO,GAAG,CAAC,IAAI,CAAC;SACjB;IACH,CAAC,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
@@ -1,5 +1,6 @@
1
1
  import { ParsedArgs } from 'minimist';
2
2
  import { Options } from 'rehype-document';
3
+ import { RehypeRewriteOptions } from 'rehype-rewrite';
3
4
  export * from './create';
4
5
  export interface RunArgvs extends ParsedArgs {
5
6
  version?: string;
@@ -26,6 +27,8 @@ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
26
27
  'github-corners'?: RunArgvs['github-corners'];
27
28
  /** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
28
29
  document?: Options;
30
+ /** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
31
+ rewrite?: RehypeRewriteOptions['rewrite'];
29
32
  /** rewrite URLs of href and src attributes. */
30
33
  reurls?: Record<string, string>;
31
34
  /**
package/lib/index.js.map CHANGED
@@ -1 +1 @@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E;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;SAC5D;aAAM,IAAI,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC9D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACtE;QACD,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE;YACtC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;SACxD;KACF;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACrD,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;AAChG,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAW;;;;;;;;;;;;;;;CAe9B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAU;;;;;;;;;;CAUjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "markdown-to-html-cli",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
+ "license": "MIT",
4
5
  "description": "Command line tool generates markdown as html.",
5
6
  "homepage": "https://jaywcjlove.github.io/markdown-to-html-cli/",
6
7
  "exports": "./lib/index.js",
@@ -28,7 +29,6 @@
28
29
  "html",
29
30
  "cli"
30
31
  ],
31
- "license": "MIT",
32
32
  "engines": {
33
33
  "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
34
34
  },
@@ -38,7 +38,10 @@
38
38
  ]
39
39
  },
40
40
  "markdown-to-html": {
41
- "github-corners": "https://github.com/jaywcjlove/markdown-to-html-cli.git"
41
+ "reurls": {
42
+ "README-zh.md": "index.zh.html",
43
+ "README.md": "index.html"
44
+ }
42
45
  },
43
46
  "dependencies": {
44
47
  "@mapbox/rehype-prism": "0.8.0",
@@ -52,7 +55,7 @@
52
55
  "rehype-format": "4.0.0",
53
56
  "rehype-meta": "^3.1.0",
54
57
  "rehype-raw": "6.1.0",
55
- "rehype-rewrite": "3.0.0",
58
+ "rehype-rewrite": "3.0.2",
56
59
  "rehype-slug": "5.0.0",
57
60
  "rehype-stringify": "9.0.2",
58
61
  "rehype-urls": "1.1.1",
package/src/create.ts CHANGED
@@ -28,7 +28,7 @@ export interface CreateOptions extends MDToHTMLOptions { }
28
28
  export function create(options = {} as CreateOptions) {
29
29
  // default github css.
30
30
  const cssStr = fs.readFileSync(path.resolve(__dirname, 'github.css'));
31
- const { markdown, document, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
31
+ const { markdown, document, rewrite, reurls = {}, wrap = { wrapper: 'div.wmde-markdown' } } = options;
32
32
  return unified()
33
33
  .use(remarkParse)
34
34
  .use(remarkGfm)
@@ -45,16 +45,17 @@ export function create(options = {} as CreateOptions) {
45
45
  .use(rehypeWrap, { ...wrap })
46
46
  .use(rehypeRewrite, {
47
47
  rewrite: (node, index, parent) => {
48
- if (node.type == 'element') {
49
- if(node.tagName === 'body' && options['github-corners']) {
50
- node.children = [githubCorners({ href: options['github-corners'] }), ...node.children];
51
- }
52
- if (/h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
53
- const child = node.children[0];
54
- if (child && child.type === 'element' && child.properties) {
55
- child.properties = { class: 'anchor', ...child.properties };
56
- child.children = [octiconLink()];
57
- }
48
+ if (rewrite && typeof rewrite === 'function') {
49
+ rewrite(node, index, parent);
50
+ }
51
+ if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
52
+ node.children = [githubCorners({ href: options['github-corners'] }), ...node.children];
53
+ }
54
+ 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
+ const child = node.children[0];
56
+ if (child && child.type === 'element' && child.properties) {
57
+ child.properties = { className: 'anchor', ...child.properties };
58
+ child.children = [octiconLink()];
58
59
  }
59
60
  }
60
61
  }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import minimist, { ParsedArgs } from 'minimist';
4
4
  import { Options } from 'rehype-document';
5
+ import { RehypeRewriteOptions } from 'rehype-rewrite';
5
6
  import { create } from './create';
6
7
 
7
8
  export * from './create';
@@ -34,6 +35,8 @@ export interface MDToHTMLOptions extends Omit<RunArgvs, '_'> {
34
35
  'github-corners'?: RunArgvs['github-corners'];
35
36
  /** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
36
37
  document?: Options;
38
+ /** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
39
+ rewrite?: RehypeRewriteOptions['rewrite'];
37
40
  /** rewrite URLs of href and src attributes. */
38
41
  reurls?: Record<string, string>;
39
42
  /**
@@ -54,3 +54,32 @@ it('options.document=undefined test case', async () => {
54
54
  const html = create({ document: undefined });
55
55
  expect(html.indexOf('<!doctype html>') === -1).toBeTruthy();
56
56
  });
57
+
58
+ it('github-corners test case', async () => {
59
+ let html = create({
60
+ markdown: 'Hello World!',
61
+ 'github-corners': 'https://github.com/jaywcjlove/markdown-to-html-cli',
62
+ document: {},
63
+ });
64
+ expect(html.indexOf('<body><a aria-label="View source on GitHub"') > 0).toBeTruthy();
65
+
66
+ html = create({
67
+ markdown: 'Hello World!',
68
+ 'github-corners': 'https://github.com/jaywcjlove/markdown-to-html-cli',
69
+ document: undefined,
70
+ });
71
+ expect(html.indexOf('<a aria-label="View source on GitHub" target="__blank" class="github-corner"') === 0).toBeTruthy();
72
+ expect(html.indexOf('https://github.com/jaywcjlove/markdown-to-html-cli') > -1).toBeTruthy();
73
+ });
74
+
75
+ it('rewrite test case', async () => {
76
+ let html = create({
77
+ markdown: 'Hello World!',
78
+ rewrite: (node) => {
79
+ if (node.type === 'element' && node.tagName === 'p') {
80
+ node.properties.className = 'test';
81
+ }
82
+ }
83
+ });
84
+ expect(html.indexOf('<p class="test">Hello World!</p>') > 0).toBeTruthy();
85
+ });
@@ -69,10 +69,10 @@ it('config test case', async () => {
69
69
  it('keywords test case', async () => {
70
70
  await FS.mkdirs('test/demo');
71
71
  await FS.writeJSON('test/demo/config.json', {
72
- "repository": "https://github.com/jaywcjlove/markdown-to-html-cli.git",
73
72
  "keywords": ["html", "cli"],
74
73
  "markdown-to-html": {
75
74
  "favicon": "data:image/svg+xml",
75
+ 'github-corners': 'https://github.com/jaywcjlove/markdown-to-html-cli.git',
76
76
  "reurls": {
77
77
  "README.md": "index.html"
78
78
  },
@@ -82,5 +82,6 @@ it('keywords test case', async () => {
82
82
  expect(run({ config: 'test/demo/config.json', output: 'test/demo/index.html', keywords: 'html,cli', markdown: 'Hello World! [](README.md)' })).toBeUndefined();
83
83
  const htmlStr = await FS.readFile('test/demo/index.html');
84
84
  expect(htmlStr.toString().indexOf('html,cli') > 0).toBeTruthy();
85
+ expect(htmlStr.toString().indexOf('https://github.com/jaywcjlove/markdown-to-html-cli.git') > 0).toBeTruthy();
85
86
  await FS.remove('test/demo');
86
87
  });