@uiw/react-md-editor 3.9.7 → 3.10.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 +49 -23
- package/dist/mdeditor.css +0 -2
- package/dist/mdeditor.js +477 -232
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/esm/Editor.d.ts +4 -0
- package/esm/Editor.js +4 -2
- package/esm/Editor.js.map +3 -2
- package/esm/components/Toolbar/index.d.ts +1 -0
- package/esm/components/Toolbar/index.js +7 -4
- package/esm/components/Toolbar/index.js.map +4 -3
- package/lib/Editor.d.ts +4 -0
- package/lib/Editor.js +5 -2
- package/lib/Editor.js.map +3 -2
- package/lib/components/Toolbar/index.d.ts +1 -0
- package/lib/components/Toolbar/index.js +7 -4
- package/lib/components/Toolbar/index.js.map +4 -3
- package/package.json +5 -4
- package/src/Editor.tsx +6 -1
- package/src/components/Toolbar/index.tsx +7 -4
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/uiwjs/react-md-editor/actions" target="__blank">
|
|
9
|
-
<img alt="Build & Deploy" src="https://github.com/uiwjs/react-md-editor/workflows/
|
|
9
|
+
<img alt="Build & Deploy" src="https://github.com/uiwjs/react-md-editor/actions/workflows/ci.yml/badge.svg">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@uiw/react-md-editor" target="__blank">
|
|
12
12
|
<img alt="Downloads" src="https://img.shields.io/npm/dm/@uiw/react-md-editor.svg?style=flat">
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<img src="https://img.shields.io/badge/Open%20in-unpkg-blue" alt="Open in unpkg">
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://gitee.com/uiw/react-md-editor" target="__blank">
|
|
18
|
-
<img alt="
|
|
18
|
+
<img alt="Gitee" src="https://jaywcjlove.github.io/sb/ico/gitee.svg">
|
|
19
19
|
</a>
|
|
20
20
|
<a href="https://www.npmjs.com/package/@uiw/react-md-editor" target="__blank">
|
|
21
21
|
<img alt="npm version" src="https://img.shields.io/npm/v/@uiw/react-md-editor.svg">
|
|
@@ -72,6 +72,7 @@ export default function App() {
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
### Security
|
|
75
|
+
|
|
75
76
|
Please note markdown needs to be sanitized if you do not **completely trust** your authors.
|
|
76
77
|
Otherwise, your app is vulnerable to XSS. This can be achieved by adding [rehype-sanitize](https://github.com/rehypejs/rehype-sanitize) as a plugin.
|
|
77
78
|
|
|
@@ -309,14 +310,14 @@ export default function App() {
|
|
|
309
310
|
|
|
310
311
|
Using [mermaid](https://github.com/mermaid-js/mermaid) to generation of diagram and flowchart from text in a similar manner as markdown
|
|
311
312
|
|
|
312
|
-
[](https://codesandbox.io/embed/
|
|
313
|
+
[](https://codesandbox.io/embed/recursing-water-08i59s?fontsize=14&hidenavigation=1&theme=dark)
|
|
313
314
|
|
|
314
315
|
```bash
|
|
315
316
|
npm install mermaid
|
|
316
317
|
```
|
|
317
318
|
|
|
318
319
|
```jsx
|
|
319
|
-
import React from "react";
|
|
320
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
320
321
|
import ReactDOM from "react-dom";
|
|
321
322
|
import MDEditor from "@uiw/react-md-editor";
|
|
322
323
|
import mermaid from "mermaid";
|
|
@@ -344,37 +345,61 @@ Bob-->>John: Jolly good!
|
|
|
344
345
|
\`\`\`
|
|
345
346
|
`;
|
|
346
347
|
|
|
347
|
-
const
|
|
348
|
-
|
|
348
|
+
const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
|
|
349
|
+
const Code = ({ inline, children = [], className, ...props }: any) => {
|
|
350
|
+
const demoid = useRef(`dome${randomid()}`);
|
|
351
|
+
const code = getCode(children);
|
|
352
|
+
const demo = useRef(null);
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
if (demo.current) {
|
|
355
|
+
try {
|
|
356
|
+
const str = mermaid.render(demoid.current, code, () => null, demo.current);
|
|
357
|
+
// @ts-ignore
|
|
358
|
+
demo.current.innerHTML = str;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
demo.current.innerHTML = error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}, [code, demo]);
|
|
365
|
+
|
|
366
|
+
if (
|
|
367
|
+
typeof code === "string" && typeof className === "string" &&
|
|
368
|
+
/^language-mermaid/.test(className.toLocaleLowerCase())
|
|
369
|
+
) {
|
|
370
|
+
return (
|
|
371
|
+
<code ref={demo}>
|
|
372
|
+
<code id={demoid.current} style={{ display: "none" }} />
|
|
373
|
+
</code>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return <code className={String(className)}>{children}</code>;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const getCode = (arr = []) => arr.map((dt) => {
|
|
380
|
+
if (typeof dt === "string") {
|
|
349
381
|
return dt;
|
|
350
382
|
}
|
|
351
383
|
if (dt.props && dt.props.children) {
|
|
352
384
|
return getCode(dt.props.children);
|
|
353
385
|
}
|
|
354
|
-
|
|
386
|
+
return false;
|
|
387
|
+
}).filter(Boolean).join("");
|
|
355
388
|
|
|
356
389
|
export default function App() {
|
|
390
|
+
const [value, setValue] = useState(mdMermaid);
|
|
357
391
|
return (
|
|
358
392
|
<MDEditor
|
|
393
|
+
onChange={(newValue = "") => setValue(newValue)}
|
|
394
|
+
textareaProps={{
|
|
395
|
+
placeholder: "Please enter Markdown text"
|
|
396
|
+
}}
|
|
359
397
|
height={500}
|
|
360
|
-
value={
|
|
398
|
+
value={value}
|
|
361
399
|
previewOptions={{
|
|
362
400
|
components: {
|
|
363
|
-
code:
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
typeof code === 'string' &&
|
|
367
|
-
typeof className === 'string' &&
|
|
368
|
-
/^language-mermaid/.test(className.toLocaleLowerCase())
|
|
369
|
-
) {
|
|
370
|
-
const Elm = document.createElement("div");
|
|
371
|
-
Elm.id = "demo";
|
|
372
|
-
const svg = mermaid.render("demo", code);
|
|
373
|
-
return <code dangerouslySetInnerHTML={{ __html: svg }} />
|
|
374
|
-
}
|
|
375
|
-
return <code className={String(className)}>{children}</code>;
|
|
376
|
-
},
|
|
377
|
-
},
|
|
401
|
+
code: Code
|
|
402
|
+
}
|
|
378
403
|
}}
|
|
379
404
|
/>
|
|
380
405
|
);
|
|
@@ -438,6 +463,7 @@ export default HomePage;
|
|
|
438
463
|
- `visiableDragbar?: boolean=true`: Show drag and drop tool. Set the height of the editor.
|
|
439
464
|
- `highlightEnable?: boolean=true`: Disable editing area code highlighting. The value is `false`, which increases the editing speed.
|
|
440
465
|
- `fullscreen?: boolean=false`: Show markdown preview.
|
|
466
|
+
- `overflow?: boolean=true`: Disable `fullscreen` setting body styles
|
|
441
467
|
- `preview?: 'live' | 'edit' | 'preview'`: Default value `live`, Show markdown preview.
|
|
442
468
|
- `maxHeight?: number=1200`: Maximum drag height. The `visiableDragbar=true` value is valid.
|
|
443
469
|
- `minHeights?: number=100`: Minimum drag height. The `visiableDragbar=true` value is valid.
|