@uiw/react-md-editor 3.19.5 → 3.19.6
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/mdeditor.js +84 -650
- package/dist/mdeditor.min.js +1 -1
- package/esm/commands/preview.js +3 -0
- package/esm/commands/preview.js.map +4 -2
- package/esm/components/TextArea/Markdown.js +26 -25
- package/esm/components/TextArea/Markdown.js.map +6 -3
- package/lib/commands/preview.js +3 -0
- package/lib/commands/preview.js.map +4 -2
- package/lib/components/TextArea/Markdown.js +25 -24
- package/lib/components/TextArea/Markdown.js.map +6 -3
- package/package.json +1 -1
- package/src/commands/preview.tsx +3 -0
- package/src/components/TextArea/Markdown.tsx +21 -22
package/esm/commands/preview.js
CHANGED
|
@@ -23,6 +23,7 @@ export var codePreview = {
|
|
|
23
23
|
})]
|
|
24
24
|
}),
|
|
25
25
|
execute: (state, api, dispatch, executeCommandState, shortcuts) => {
|
|
26
|
+
api.textArea.focus();
|
|
26
27
|
if (shortcuts && dispatch && executeCommandState) {
|
|
27
28
|
dispatch({
|
|
28
29
|
preview: 'preview'
|
|
@@ -52,6 +53,7 @@ export var codeEdit = {
|
|
|
52
53
|
})]
|
|
53
54
|
}),
|
|
54
55
|
execute: (state, api, dispatch, executeCommandState, shortcuts) => {
|
|
56
|
+
api.textArea.focus();
|
|
55
57
|
if (shortcuts && dispatch && executeCommandState) {
|
|
56
58
|
dispatch({
|
|
57
59
|
preview: 'edit'
|
|
@@ -81,6 +83,7 @@ export var codeLive = {
|
|
|
81
83
|
})]
|
|
82
84
|
}),
|
|
83
85
|
execute: (state, api, dispatch, executeCommandState, shortcuts) => {
|
|
86
|
+
api.textArea.focus();
|
|
84
87
|
if (shortcuts && dispatch && executeCommandState) {
|
|
85
88
|
dispatch({
|
|
86
89
|
preview: 'live'
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"api",
|
|
16
16
|
"dispatch",
|
|
17
17
|
"executeCommandState",
|
|
18
|
+
"textArea",
|
|
19
|
+
"focus",
|
|
18
20
|
"preview",
|
|
19
21
|
"codeEdit",
|
|
20
22
|
"codeLive"
|
|
@@ -23,7 +25,7 @@
|
|
|
23
25
|
"../../src/commands/preview.tsx"
|
|
24
26
|
],
|
|
25
27
|
"sourcesContent": [
|
|
26
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
|
|
28
|
+
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
|
|
27
29
|
],
|
|
28
|
-
"mappings": "AAAA,OAAO,KAAKA,KAAK,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c;MACnB,MAAM,EAAC;IAA+E,EACtF;EAAA,EAEL;EACDC,OAAO,EAAE,CACPC,KAAgB,EAChBC,GAAoB,EACpBC,QAAuC,EACvCC,mBAAyC,EACzCR,SAAoB,KACjB;IACHM,GAAG,CAACG,QAAQ,CAACC,KAAK,EAAE;IACpB,IAAIV,SAAS,IAAIO,QAAQ,IAAIC,mBAAmB,EAAE;MAChDD,QAAQ,CAAC;QAAEI,OAAO,EAAE;MAAO,CAAC,CAAC;IAC/B;EACF;AACF,CAAC"
|
|
29
31
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";
|
|
2
|
+
var _templateObject;
|
|
3
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
4
|
import { rehype } from 'rehype';
|
|
3
5
|
import rehypePrism from 'rehype-prism-plus';
|
|
4
6
|
import { EditorContext } from '../../Context';
|
|
5
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
8
|
function html2Escape(sHtml) {
|
|
7
|
-
return sHtml.replace(/```(
|
|
9
|
+
return sHtml.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, str => {
|
|
8
10
|
return str.replace(/[<&"]/g, c => ({
|
|
9
11
|
'<': '<',
|
|
10
12
|
'>': '>',
|
|
@@ -36,29 +38,28 @@ export default function Markdown(props) {
|
|
|
36
38
|
}
|
|
37
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
40
|
}, []);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
className: prefixCls + "-text-pre wmde-markdown-color"
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
var mdStr = "<pre class=\"language-markdown " + prefixCls + "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">" + html2Escape(markdown) + "\n</code></pre>";
|
|
47
|
-
if (highlightEnable) {
|
|
48
|
-
try {
|
|
49
|
-
mdStr = rehype().data('settings', {
|
|
50
|
-
fragment: true
|
|
51
|
-
}).use(rehypePrism, {
|
|
52
|
-
ignoreMissing: true
|
|
53
|
-
}).processSync(mdStr).toString();
|
|
54
|
-
} catch (error) {}
|
|
55
|
-
}
|
|
56
|
-
return /*#__PURE__*/React.createElement('div', {
|
|
57
|
-
className: 'wmde-markdown-color',
|
|
58
|
-
dangerouslySetInnerHTML: {
|
|
59
|
-
__html: mdStr || ''
|
|
60
|
-
}
|
|
41
|
+
if (!markdown) {
|
|
42
|
+
return /*#__PURE__*/_jsx("pre", {
|
|
43
|
+
ref: preRef,
|
|
44
|
+
className: prefixCls + "-text-pre wmde-markdown-color"
|
|
61
45
|
});
|
|
62
|
-
}
|
|
46
|
+
}
|
|
47
|
+
var mdStr = "<pre class=\"language-markdown " + prefixCls + "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">" + html2Escape(String.raw(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["", ""])), markdown)) + "\n</code></pre>";
|
|
48
|
+
console.log('markdown::', markdown);
|
|
49
|
+
if (highlightEnable) {
|
|
50
|
+
try {
|
|
51
|
+
mdStr = rehype().data('settings', {
|
|
52
|
+
fragment: true
|
|
53
|
+
}).use(rehypePrism, {
|
|
54
|
+
ignoreMissing: true
|
|
55
|
+
}).processSync(mdStr).toString();
|
|
56
|
+
} catch (error) {}
|
|
57
|
+
}
|
|
58
|
+
return /*#__PURE__*/React.createElement('div', {
|
|
59
|
+
className: 'wmde-markdown-color',
|
|
60
|
+
dangerouslySetInnerHTML: {
|
|
61
|
+
__html: mdStr || ''
|
|
62
|
+
}
|
|
63
|
+
});
|
|
63
64
|
}
|
|
64
65
|
//# sourceMappingURL=Markdown.js.map
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"React",
|
|
5
5
|
"useContext",
|
|
6
6
|
"useEffect",
|
|
7
|
-
"useMemo",
|
|
8
7
|
"rehype",
|
|
9
8
|
"rehypePrism",
|
|
10
9
|
"EditorContext",
|
|
@@ -24,6 +23,10 @@
|
|
|
24
23
|
"current",
|
|
25
24
|
"textareaPre",
|
|
26
25
|
"mdStr",
|
|
26
|
+
"String",
|
|
27
|
+
"raw",
|
|
28
|
+
"console",
|
|
29
|
+
"log",
|
|
27
30
|
"data",
|
|
28
31
|
"fragment",
|
|
29
32
|
"use",
|
|
@@ -40,7 +43,7 @@
|
|
|
40
43
|
"../../../src/components/TextArea/Markdown.tsx"
|
|
41
44
|
],
|
|
42
45
|
"sourcesContent": [
|
|
43
|
-
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(
|
|
46
|
+
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n console.log('markdown::', markdown);\n\n if (highlightEnable) {\n try {\n mdStr = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(mdStr)\n .toString();\n } catch (error) {}\n }\n\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: mdStr || '' },\n });\n}\n"
|
|
44
47
|
],
|
|
45
|
-
"mappings": "AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,
|
|
48
|
+
"mappings": ";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,QAAiB,OAAO;AAC7D,SAASC,MAAM,QAAQ,QAAQ;AAC/B,OAAOC,WAAW,MAAM,mBAAmB;AAE3C,SAASC,aAAa,QAAQ,eAAe;AAAC;AAE9C,SAASC,WAAW,CAACC,KAAa,EAAE;EAClC,OAAOA,KAAK,CACTC,OAAO,CAAC,gCAAgC,EAAGC,GAAW,IAAK;IAC1D,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACPE,CAAS,IAAM,CAAC;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,MAAM;MAAE,GAAG,EAAE,OAAO;MAAE,GAAG,EAAE;IAAS,CAAC,EAA4BA,CAAC,CAAE,CAC1G;EACH,CAAC,CAAC,CACDF,OAAO,CACN,QAAQ,EACPE,CAAS,IAAM,CAAC;IAAE,GAAG,EAAE,MAAM;IAAE,GAAG,EAAE,MAAM;IAAE,GAAG,EAAE,OAAO;IAAE,GAAG,EAAE;EAAS,CAAC,EAA4BA,CAAC,CAAE,CAC1G;AACL;AAIA,eAAe,SAASC,QAAQ,CAACC,KAAoB,EAAE;EACrD,IAAM;IAAEC;EAAU,CAAC,GAAGD,KAAK;EAC3B,IAAM;IAAEE,QAAQ,GAAG,EAAE;IAAEC,eAAe;IAAEC;EAAS,CAAC,GAAGf,UAAU,CAACI,aAAa,CAAC;EAC9E,IAAMY,MAAM,gBAAGjB,KAAK,CAACkB,SAAS,EAAkB;EAChDhB,SAAS,CAAC,MAAM;IACd,IAAIe,MAAM,CAACE,OAAO,IAAIH,QAAQ,EAAE;MAC9BA,QAAQ,CAAC;QAAEI,WAAW,EAAEH,MAAM,CAACE;MAAQ,CAAC,CAAC;IAC3C;IACA;EACF,CAAC,EAAE,EAAE,CAAC;EACN,IAAI,CAACL,QAAQ,EAAE;IACb,oBAAO;MAAK,GAAG,EAAEG,MAAO;MAAC,SAAS,EAAKJ,SAAS;IAAgC,EAAG;EACrF;EACA,IAAIQ,KAAK,uCAAoCR,SAAS,0EAAkEP,WAAW,CACjIgB,MAAM,CAACC,GAAG,+EAAGT,QAAQ,EACtB,oBAAiB;EAElBU,OAAO,CAACC,GAAG,CAAC,YAAY,EAAEX,QAAQ,CAAC;EAEnC,IAAIC,eAAe,EAAE;IACnB,IAAI;MACFM,KAAK,GAAGlB,MAAM,EAAE,CACbuB,IAAI,CAAC,UAAU,EAAE;QAAEC,QAAQ,EAAE;MAAK,CAAC,CAAC,CACpCC,GAAG,CAACxB,WAAW,EAAE;QAAEyB,aAAa,EAAE;MAAK,CAAC,CAAC,CACzCC,WAAW,CAACT,KAAK,CAAC,CAClBU,QAAQ,EAAE;IACf,CAAC,CAAC,OAAOC,KAAK,EAAE,CAAC;EACnB;EAEA,oBAAOhC,KAAK,CAACiC,aAAa,CAAC,KAAK,EAAE;IAChCC,SAAS,EAAE,qBAAqB;IAChCC,uBAAuB,EAAE;MAAEC,MAAM,EAAEf,KAAK,IAAI;IAAG;EACjD,CAAC,CAAC;AACJ"
|
|
46
49
|
}
|
package/lib/commands/preview.js
CHANGED
|
@@ -29,6 +29,7 @@ var codePreview = {
|
|
|
29
29
|
})]
|
|
30
30
|
}),
|
|
31
31
|
execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
|
|
32
|
+
api.textArea.focus();
|
|
32
33
|
if (shortcuts && dispatch && executeCommandState) {
|
|
33
34
|
dispatch({
|
|
34
35
|
preview: 'preview'
|
|
@@ -59,6 +60,7 @@ var codeEdit = {
|
|
|
59
60
|
})]
|
|
60
61
|
}),
|
|
61
62
|
execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
|
|
63
|
+
api.textArea.focus();
|
|
62
64
|
if (shortcuts && dispatch && executeCommandState) {
|
|
63
65
|
dispatch({
|
|
64
66
|
preview: 'edit'
|
|
@@ -89,6 +91,7 @@ var codeLive = {
|
|
|
89
91
|
})]
|
|
90
92
|
}),
|
|
91
93
|
execute: function execute(state, api, dispatch, executeCommandState, shortcuts) {
|
|
94
|
+
api.textArea.focus();
|
|
92
95
|
if (shortcuts && dispatch && executeCommandState) {
|
|
93
96
|
dispatch({
|
|
94
97
|
preview: 'live'
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"api",
|
|
15
15
|
"dispatch",
|
|
16
16
|
"executeCommandState",
|
|
17
|
+
"textArea",
|
|
18
|
+
"focus",
|
|
17
19
|
"preview",
|
|
18
20
|
"codeEdit",
|
|
19
21
|
"codeLive"
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
"../../src/commands/preview.tsx"
|
|
23
25
|
],
|
|
24
26
|
"sourcesContent": [
|
|
25
|
-
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
|
|
27
|
+
"import * as React from 'react';\nimport { ICommand, TextState, TextAreaTextApi } from './';\nimport { ContextStore, ExecuteCommandState } from '../Context';\n\nexport const codePreview: ICommand = {\n name: 'preview',\n keyCommand: 'preview',\n value: 'preview',\n shortcuts: 'ctrlcmd+9',\n buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon\n fill=\"currentColor\"\n points=\"0 71.293 0 122 38.023 123 38.023 398 0 397 0 449.707 91.023 450.413 91.023 72.293\"\n />\n <polygon\n fill=\"currentColor\"\n points=\"148.023 72.293 520 71.293 520 122 200.023 124 200.023 397 520 396 520 449.707 148.023 450.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'preview' });\n }\n },\n};\n\nexport const codeEdit: ICommand = {\n name: 'edit',\n keyCommand: 'preview',\n value: 'edit',\n shortcuts: 'ctrlcmd+7',\n buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 319 122 319 397 0 397 0 449.707 372 449.413 372 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"429 71.293 520 71.293 520 122 481 123 481 396 520 396 520 449.707 429 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'edit' });\n }\n },\n};\n\nexport const codeLive: ICommand = {\n name: 'live',\n keyCommand: 'preview',\n value: 'live',\n shortcuts: 'ctrlcmd+8',\n buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },\n icon: (\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 520 520\">\n <polygon fill=\"currentColor\" points=\"0 71.293 0 122 179 122 179 397 0 397 0 449.707 232 449.413 232 71.293\" />\n <polygon\n fill=\"currentColor\"\n points=\"289 71.293 520 71.293 520 122 341 123 341 396 520 396 520 449.707 289 449.413\"\n />\n </svg>\n ),\n execute: (\n state: TextState,\n api: TextAreaTextApi,\n dispatch?: React.Dispatch<ContextStore>,\n executeCommandState?: ExecuteCommandState,\n shortcuts?: string[],\n ) => {\n api.textArea.focus();\n if (shortcuts && dispatch && executeCommandState) {\n dispatch({ preview: 'live' });\n }\n },\n};\n"
|
|
26
28
|
],
|
|
27
|
-
"mappings": ";;;;;;;AAAA;AAA+B;AAIxB,IAAMA,WAAqB,GAAG;EACnCC,IAAI,EAAE,SAAS;EACfC,UAAU,EAAE,SAAS;EACrBC,KAAK,EAAE,SAAS;EAChBC,SAAS,EAAE,WAAW;EACtBC,WAAW,EAAE;IAAE,YAAY,EAAE,yBAAyB;IAAEC,KAAK,EAAE;EAA0B,CAAC;EAC1FC,IAAI,eACF;IAAK,KAAK,EAAC,IAAI;IAAC,MAAM,EAAC,IAAI;IAAC,OAAO,EAAC,aAAa;IAAA,wBAC/C;MACE,IAAI,EAAC,cAAc;MACnB,MAAM,EAAC;IAAmF,EAC1F,eACF;MACE,IAAI,EAAC,cAAc;MACnB,MAAM,EAAC;IAA+F,EACtG;EAAA,EAEL;EACDC,OAAO,EAAE,iBACPC,KAAgB,EAChBC,GAAoB,EACpBC,QAAuC,EACvCC,mBAAyC,EACzCR,SAAoB,EACjB;
|
|
29
|
+
"mappings": ";;;;;;;AAAA;AAA+B;AAIxB,IAAMA,WAAqB,GAAG;EACnCC,IAAI,E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AQ,CAACC,KAAK,EAAE;IACpB,IAAIV,SAAS,IAAIO,QAAQ,IAAIC,mBAAmB,EAAE;MAChDD,QAAQ,CAAC;QAAEI,OAAO,EAAE;MAAO,CAAC,CAAC;IAC/B;EACF;AACF,CAAC;AAAC;AAEK,IAAME,QAAkB,GAAG;EAChChB,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,SAAS;EACrBC,KAAK,EAAE,MAAM;EACbC,SAAS,EAAE,WAAW;EACtBC,WAAW,EAAE;IAAE,YAAY,EAAE,sBAAsB;IAAEC,KAAK,EAAE;EAAuB,CAAC;EACpFC,IAAI,eACF;IAAK,KAAK,EAAC,IAAI;IAAC,MAAM,EAAC,IAAI;IAAC,OAAO,EAAC,aAAa;IAAA,wBAC/C;MAAS,IAAI,EAAC,cAAc;MAAC,MAAM,EAAC;IAAuE,EAAG,eAC9G;MACE,IAAI,EAAC,cAAc;MACnB,MAAM,EAAC;IAA+E,EACtF;EAAA,EAEL;EACDC,OAAO,EAAE,iBACPC,KAAgB,EAChBC,GAAoB,EACpBC,QAAuC,EACvCC,mBAAyC,EACzCR,SAAoB,EACjB;IACHM,GAAG,CAACG,QAAQ,CAACC,KAAK,EAAE;IACpB,IAAIV,SAAS,IAAIO,QAAQ,IAAIC,mBAAmB,EAAE;MAChDD,QAAQ,CAAC;QAAEI,OAAO,EAAE;MAAO,CAAC,CAAC;IAC/B;EACF;AACF,CAAC;AAAC"
|
|
28
30
|
}
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = Markdown;
|
|
9
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
11
|
var _rehype = require("rehype");
|
|
11
12
|
var _rehypePrismPlus = _interopRequireDefault(require("rehype-prism-plus"));
|
|
12
13
|
var _Context = require("../../Context");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
var _templateObject;
|
|
14
16
|
function html2Escape(sHtml) {
|
|
15
|
-
return sHtml.replace(/```(
|
|
17
|
+
return sHtml.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, function (str) {
|
|
16
18
|
return str.replace(/[<&"]/g, function (c) {
|
|
17
19
|
return {
|
|
18
20
|
'<': '<',
|
|
@@ -46,30 +48,29 @@ function Markdown(props) {
|
|
|
46
48
|
}
|
|
47
49
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
50
|
}, []);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
className: "".concat(prefixCls, "-text-pre wmde-markdown-color")
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
var mdStr = "<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(markdown), "\n</code></pre>");
|
|
57
|
-
if (highlightEnable) {
|
|
58
|
-
try {
|
|
59
|
-
mdStr = (0, _rehype.rehype)().data('settings', {
|
|
60
|
-
fragment: true
|
|
61
|
-
}).use(_rehypePrismPlus["default"], {
|
|
62
|
-
ignoreMissing: true
|
|
63
|
-
}).processSync(mdStr).toString();
|
|
64
|
-
} catch (error) {}
|
|
65
|
-
}
|
|
66
|
-
return /*#__PURE__*/_react["default"].createElement('div', {
|
|
67
|
-
className: 'wmde-markdown-color',
|
|
68
|
-
dangerouslySetInnerHTML: {
|
|
69
|
-
__html: mdStr || ''
|
|
70
|
-
}
|
|
51
|
+
if (!markdown) {
|
|
52
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("pre", {
|
|
53
|
+
ref: preRef,
|
|
54
|
+
className: "".concat(prefixCls, "-text-pre wmde-markdown-color")
|
|
71
55
|
});
|
|
72
|
-
}
|
|
56
|
+
}
|
|
57
|
+
var mdStr = "<pre class=\"language-markdown ".concat(prefixCls, "-text-pre wmde-markdown-color\"><code class=\"language-markdown\">").concat(html2Escape(String.raw(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["", ""])), markdown)), "\n</code></pre>");
|
|
58
|
+
console.log('markdown::', markdown);
|
|
59
|
+
if (highlightEnable) {
|
|
60
|
+
try {
|
|
61
|
+
mdStr = (0, _rehype.rehype)().data('settings', {
|
|
62
|
+
fragment: true
|
|
63
|
+
}).use(_rehypePrismPlus["default"], {
|
|
64
|
+
ignoreMissing: true
|
|
65
|
+
}).processSync(mdStr).toString();
|
|
66
|
+
} catch (error) {}
|
|
67
|
+
}
|
|
68
|
+
return /*#__PURE__*/_react["default"].createElement('div', {
|
|
69
|
+
className: 'wmde-markdown-color',
|
|
70
|
+
dangerouslySetInnerHTML: {
|
|
71
|
+
__html: mdStr || ''
|
|
72
|
+
}
|
|
73
|
+
});
|
|
73
74
|
}
|
|
74
75
|
module.exports = exports.default;
|
|
75
76
|
//# sourceMappingURL=Markdown.js.map
|
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
"useEffect",
|
|
21
21
|
"current",
|
|
22
22
|
"textareaPre",
|
|
23
|
-
"useMemo",
|
|
24
23
|
"mdStr",
|
|
24
|
+
"String",
|
|
25
|
+
"raw",
|
|
26
|
+
"console",
|
|
27
|
+
"log",
|
|
25
28
|
"rehype",
|
|
26
29
|
"data",
|
|
27
30
|
"fragment",
|
|
@@ -40,7 +43,7 @@
|
|
|
40
43
|
"../../../src/components/TextArea/Markdown.tsx"
|
|
41
44
|
],
|
|
42
45
|
"sourcesContent": [
|
|
43
|
-
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(
|
|
46
|
+
"import React, { useContext, useEffect, useMemo } from 'react';\nimport { rehype } from 'rehype';\nimport rehypePrism from 'rehype-prism-plus';\nimport { IProps } from '../../Editor';\nimport { EditorContext } from '../../Context';\n\nfunction html2Escape(sHtml: string) {\n return sHtml\n .replace(/```(\\w+)?([\\s\\S]*?)(\\s.+)?```/g, (str: string) => {\n return str.replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n })\n .replace(\n /[<&\"]/g,\n (c: string) => (({ '<': '<', '>': '>', '&': '&', '\"': '"' } as Record<string, string>)[c]),\n );\n}\n\nexport interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreElement> {}\n\nexport default function Markdown(props: MarkdownProps) {\n const { prefixCls } = props;\n const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);\n const preRef = React.createRef<HTMLPreElement>();\n useEffect(() => {\n if (preRef.current && dispatch) {\n dispatch({ textareaPre: preRef.current });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n if (!markdown) {\n return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;\n }\n let mdStr = `<pre class=\"language-markdown ${prefixCls}-text-pre wmde-markdown-color\"><code class=\"language-markdown\">${html2Escape(\n String.raw`${markdown}`,\n )}\\n</code></pre>`;\n\n console.log('markdown::', markdown);\n\n if (highlightEnable) {\n try {\n mdStr = rehype()\n .data('settings', { fragment: true })\n .use(rehypePrism, { ignoreMissing: true })\n .processSync(mdStr)\n .toString();\n } catch (error) {}\n }\n\n return React.createElement('div', {\n className: 'wmde-markdown-color',\n dangerouslySetInnerHTML: { __html: mdStr || '' },\n });\n}\n"
|
|
44
47
|
],
|
|
45
|
-
"mappings": "
|
|
48
|
+
"mappings": ";;;;;;;;;AAAA;AACA;AACA;AAEA;AAA8C;AAAA;AAE9C,SAASA,WAAW,CAACC,KAAa,EAAE;EAClC,OAAOA,KAAK,CACTC,OAAO,CAAC,gCAAgC,EAAE,UAACC,GAAW,EAAK;IAC1D,OAAOA,GAAG,CAACD,OAAO,CAChB,QAAQ,EACR,UAACE,CAAS;MAAA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EAAE;QAAEC,QAAQ,EAAE;MAAK,CAAC,CAAC,CACpCC,GAAG,CAACC,2BAAW,EAAE;QAAEC,aAAa,EAAE;MAAK,CAAC,CAAC,CACzCC,WAAW,CAACX,KAAK,CAAC,CAClBY,QAAQ,EAAE;IACf,CAAC,CAAC,OAAOC,KAAK,EAAE,CAAC;EACnB;EAEA,oBAAOlB,iBAAK,CAACmB,aAAa,CAAC,KAAK,EAAE;IAChCC,SAAS,EAAE,qBAAqB;IAChCC,uBAAuB,EAAE;MAAEC,MAAM,EAAEjB,KAAK,IAAI;IAAG;EACjD,CAAC,CAAC;AACJ;AAAC"
|
|
46
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-md-editor",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.6",
|
|
4
4
|
"description": "A markdown editor with preview, implemented with React.js and TypeScript.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-md-editor/",
|
|
6
6
|
"author": "kenny wang <wowohoo@qq.com>",
|
package/src/commands/preview.tsx
CHANGED
|
@@ -27,6 +27,7 @@ export const codePreview: ICommand = {
|
|
|
27
27
|
executeCommandState?: ExecuteCommandState,
|
|
28
28
|
shortcuts?: string[],
|
|
29
29
|
) => {
|
|
30
|
+
api.textArea.focus();
|
|
30
31
|
if (shortcuts && dispatch && executeCommandState) {
|
|
31
32
|
dispatch({ preview: 'preview' });
|
|
32
33
|
}
|
|
@@ -55,6 +56,7 @@ export const codeEdit: ICommand = {
|
|
|
55
56
|
executeCommandState?: ExecuteCommandState,
|
|
56
57
|
shortcuts?: string[],
|
|
57
58
|
) => {
|
|
59
|
+
api.textArea.focus();
|
|
58
60
|
if (shortcuts && dispatch && executeCommandState) {
|
|
59
61
|
dispatch({ preview: 'edit' });
|
|
60
62
|
}
|
|
@@ -83,6 +85,7 @@ export const codeLive: ICommand = {
|
|
|
83
85
|
executeCommandState?: ExecuteCommandState,
|
|
84
86
|
shortcuts?: string[],
|
|
85
87
|
) => {
|
|
88
|
+
api.textArea.focus();
|
|
86
89
|
if (shortcuts && dispatch && executeCommandState) {
|
|
87
90
|
dispatch({ preview: 'live' });
|
|
88
91
|
}
|
|
@@ -6,7 +6,7 @@ import { EditorContext } from '../../Context';
|
|
|
6
6
|
|
|
7
7
|
function html2Escape(sHtml: string) {
|
|
8
8
|
return sHtml
|
|
9
|
-
.replace(/```(
|
|
9
|
+
.replace(/```(\w+)?([\s\S]*?)(\s.+)?```/g, (str: string) => {
|
|
10
10
|
return str.replace(
|
|
11
11
|
/[<&"]/g,
|
|
12
12
|
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record<string, string>)[c]),
|
|
@@ -30,28 +30,27 @@ export default function Markdown(props: MarkdownProps) {
|
|
|
30
30
|
}
|
|
31
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
32
|
}, []);
|
|
33
|
+
if (!markdown) {
|
|
34
|
+
return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
|
|
35
|
+
}
|
|
36
|
+
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
|
|
37
|
+
String.raw`${markdown}`,
|
|
38
|
+
)}\n</code></pre>`;
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
if (!markdown) {
|
|
36
|
-
return <pre ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
|
|
37
|
-
}
|
|
38
|
-
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
|
|
39
|
-
markdown,
|
|
40
|
-
)}\n</code></pre>`;
|
|
40
|
+
console.log('markdown::', markdown);
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
if (highlightEnable) {
|
|
43
|
+
try {
|
|
44
|
+
mdStr = rehype()
|
|
45
|
+
.data('settings', { fragment: true })
|
|
46
|
+
.use(rehypePrism, { ignoreMissing: true })
|
|
47
|
+
.processSync(mdStr)
|
|
48
|
+
.toString();
|
|
49
|
+
} catch (error) {}
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}, [markdown, preRef, prefixCls]);
|
|
52
|
+
return React.createElement('div', {
|
|
53
|
+
className: 'wmde-markdown-color',
|
|
54
|
+
dangerouslySetInnerHTML: { __html: mdStr || '' },
|
|
55
|
+
});
|
|
57
56
|
}
|