x-star-editor 0.0.7 → 0.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/dist/index.d.ts +10 -0
- package/dist/index.js +2 -1
- package/dist/styles/index.css +1800 -1
- package/dist/utils/handler.d.ts +3 -3
- package/dist/utils/markdown.d.ts +14 -0
- package/dist/utils/markdown.js +28 -0
- package/package.json +5 -2
package/dist/utils/handler.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ type HandlerContext = ReturnType<typeof useHistory>;
|
|
|
7
7
|
/**
|
|
8
8
|
* 处理函数
|
|
9
9
|
*/
|
|
10
|
-
export interface Handler {
|
|
11
|
-
(ctx: HandlerContext):
|
|
10
|
+
export interface Handler<T = void> {
|
|
11
|
+
(ctx: HandlerContext): T;
|
|
12
12
|
}
|
|
13
13
|
export declare const insertHandler: (payload: InsertAction['payload']) => Handler;
|
|
14
14
|
export declare const deleteHandler: (payload: DeleteAction['payload']) => Handler;
|
|
@@ -23,7 +23,7 @@ export declare const selectHandler: (selection: SelectAction['selection']) => Ha
|
|
|
23
23
|
* 接收一个处理函数,获取上下文后执行它
|
|
24
24
|
*/
|
|
25
25
|
export interface Executor {
|
|
26
|
-
(handler: Handler):
|
|
26
|
+
<T>(handler: Handler<T>): T;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* 键盘事件处理函数
|
package/dist/utils/markdown.d.ts
CHANGED
|
@@ -42,4 +42,18 @@ export interface ViewerOptions {
|
|
|
42
42
|
* @returns React 虚拟 DOM 树
|
|
43
43
|
*/
|
|
44
44
|
export declare const viewerRender: (sourceCode: string, options: ViewerOptions) => JSX.Element;
|
|
45
|
+
/**
|
|
46
|
+
* 将 Markdown 文本转成 HTML 文本
|
|
47
|
+
*
|
|
48
|
+
* @param sourceCode Markdown 文本
|
|
49
|
+
* @returns HTML 文本
|
|
50
|
+
*/
|
|
51
|
+
export declare const toHTML: (sourceCode: string) => string;
|
|
52
|
+
/**
|
|
53
|
+
* 将带有 HTML 的 Markdown 文本转成 Markdown 文本
|
|
54
|
+
*
|
|
55
|
+
* @param sourceCode 带有 HTML 的 Markdown 文本
|
|
56
|
+
* @returns Markdown 文本
|
|
57
|
+
*/
|
|
58
|
+
export declare const toMarkdown: (sourceCode: string) => string;
|
|
45
59
|
export {};
|
package/dist/utils/markdown.js
CHANGED
|
@@ -16,12 +16,15 @@ import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
|
16
16
|
import rehypeKatex from 'rehype-katex';
|
|
17
17
|
import rehypePrism from 'rehype-prism-plus';
|
|
18
18
|
import rehypeRaw from 'rehype-raw';
|
|
19
|
+
import rehypeRemark from 'rehype-remark';
|
|
19
20
|
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
|
21
|
+
import rehypeStringify from 'rehype-stringify';
|
|
20
22
|
import remarkBreaks from 'remark-breaks';
|
|
21
23
|
import remarkGfm from 'remark-gfm';
|
|
22
24
|
import remarkMath from 'remark-math';
|
|
23
25
|
import remarkParse from 'remark-parse';
|
|
24
26
|
import remarkRehype from 'remark-rehype';
|
|
27
|
+
import remarkStringify from 'remark-stringify';
|
|
25
28
|
import { unified } from 'unified';
|
|
26
29
|
import { prefix } from "./global";
|
|
27
30
|
export var getDefaultSchema = function getDefaultSchema() {
|
|
@@ -319,4 +322,29 @@ export var viewerRender = function viewerRender(sourceCode, options) {
|
|
|
319
322
|
}
|
|
320
323
|
})
|
|
321
324
|
});
|
|
325
|
+
};
|
|
326
|
+
var toHastProcessor = unified().use(remarkParse).use(remarkBreaks).use(remarkGfm).use(remarkRehype, {
|
|
327
|
+
allowDangerousHtml: true
|
|
328
|
+
}).use(rehypeRaw).freeze();
|
|
329
|
+
var toHTMLProcessor = unified().use(rehypeStringify).freeze();
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 将 Markdown 文本转成 HTML 文本
|
|
333
|
+
*
|
|
334
|
+
* @param sourceCode Markdown 文本
|
|
335
|
+
* @returns HTML 文本
|
|
336
|
+
*/
|
|
337
|
+
export var toHTML = function toHTML(sourceCode) {
|
|
338
|
+
return toHTMLProcessor.stringify(toHastProcessor.runSync(toHastProcessor.parse(sourceCode)));
|
|
339
|
+
};
|
|
340
|
+
var toMarkdownProcessor = unified().use(rehypeRemark).use(remarkGfm).use(remarkBreaks).use(remarkStringify).freeze();
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* 将带有 HTML 的 Markdown 文本转成 Markdown 文本
|
|
344
|
+
*
|
|
345
|
+
* @param sourceCode 带有 HTML 的 Markdown 文本
|
|
346
|
+
* @returns Markdown 文本
|
|
347
|
+
*/
|
|
348
|
+
export var toMarkdown = function toMarkdown(sourceCode) {
|
|
349
|
+
return toMarkdownProcessor.stringify(toMarkdownProcessor.runSync(toHastProcessor.runSync(toHastProcessor.parse(sourceCode))));
|
|
322
350
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x-star-editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "An editor developed by turingstar",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "father build && sass src/styles/index.scss dist/styles/index.css --
|
|
12
|
+
"build": "father build && sass src/styles/index.scss dist/styles/index.css --no-source-map",
|
|
13
13
|
"build:watch": "father dev",
|
|
14
14
|
"dev": "dumi dev",
|
|
15
15
|
"docs:build": "dumi build",
|
|
@@ -49,12 +49,15 @@
|
|
|
49
49
|
"rehype-katex": "^6.0.3",
|
|
50
50
|
"rehype-prism-plus": "^1.6.1",
|
|
51
51
|
"rehype-raw": "^6.1.1",
|
|
52
|
+
"rehype-remark": "^9.1.2",
|
|
52
53
|
"rehype-sanitize": "^5.0.1",
|
|
54
|
+
"rehype-stringify": "^9.0.4",
|
|
53
55
|
"remark-breaks": "^3.0.3",
|
|
54
56
|
"remark-gfm": "^3.0.1",
|
|
55
57
|
"remark-math": "^5.1.1",
|
|
56
58
|
"remark-parse": "^10.0.2",
|
|
57
59
|
"remark-rehype": "^10.1.0",
|
|
60
|
+
"remark-stringify": "^10.0.3",
|
|
58
61
|
"unified": "^10.1.2"
|
|
59
62
|
},
|
|
60
63
|
"devDependencies": {
|