@uiw/react-md-editor 3.25.6 → 4.0.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.
package/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
  </p>
7
7
 
8
8
  <p align="center">
9
+ <a href="https://jaywcjlove.github.io/#/sponsor" target="__blank">
10
+ <img alt="Buy me a coffee" src="https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee">
11
+ </a>
9
12
  <a href="https://www.npmjs.com/package/@uiw/react-md-editor" target="__blank">
10
13
  <img alt="Downloads" src="https://img.shields.io/npm/dm/@uiw/react-md-editor.svg?style=flat">
11
14
  </a>
@@ -594,18 +597,14 @@ export default function App() {
594
597
  onChange={(val) => setValue(val)}
595
598
  previewOptions={{
596
599
  components: {
597
- code: ({ inline, children = [], className, ...props }) => {
598
- const txt = children[0] || '';
599
- if (inline) {
600
- if (typeof txt === 'string' && /^\$\$(.*)\$\$/.test(txt)) {
601
- const html = katex.renderToString(txt.replace(/^\$\$(.*)\$\$/, '$1'), {
602
- throwOnError: false,
603
- });
604
- return <code dangerouslySetInnerHTML={{ __html: html }} />;
605
- }
606
- return <code>{txt}</code>;
600
+ code: ({ children = [], className, ...props }) => {
601
+ if (typeof children === 'string' && /^\$\$(.*)\$\$/.test(children)) {
602
+ const html = katex.renderToString(children.replace(/^\$\$(.*)\$\$/, '$1'), {
603
+ throwOnError: false,
604
+ });
605
+ return <code dangerouslySetInnerHTML={{ __html: html }} style={{ background: 'transparent' }} />;
607
606
  }
608
- const code = props.node && props.node.children ? getCodeString(props.node.children) : txt;
607
+ const code = props.node && props.node.children ? getCodeString(props.node.children) : children;
609
608
  if (
610
609
  typeof code === 'string' &&
611
610
  typeof className === 'string' &&
@@ -718,16 +717,25 @@ const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
718
717
  const Code = ({ inline, children = [], className, ...props }) => {
719
718
  const demoid = useRef(`dome${randomid()}`);
720
719
  const [container, setContainer] = useState(null);
721
- const isMermaid = className && /^language-mermaid/.test(className.toLocaleLowerCase());
722
- const code = props.node && props.node.children ? getCodeString(props.node.children) : children[0] || '';
720
+ const isMermaid =
721
+ className && /^language-mermaid/.test(className.toLocaleLowerCase());
722
+ const code = children
723
+ ? getCodeString(props.node.children)
724
+ : children[0] || "";
725
+
723
726
  useEffect(() => {
724
- if (container && isMermaid) {
725
- try {
726
- const str = mermaid.render(demoid.current, code);
727
- container.innerHTML = str;
728
- } catch (error) {
729
- container.innerHTML = error;
730
- }
727
+ if (container && isMermaid && demoid.current && code) {
728
+ mermaid
729
+ .render(demoid.current, code)
730
+ .then(({ svg, bindFunctions }) => {
731
+ container.innerHTML = svg;
732
+ if (bindFunctions) {
733
+ bindFunctions(container);
734
+ }
735
+ })
736
+ .catch((error) => {
737
+ console.log("error:", error);
738
+ });
731
739
  }
732
740
  }, [container, isMermaid, code, demoid]);
733
741
 
@@ -741,11 +749,11 @@ const Code = ({ inline, children = [], className, ...props }) => {
741
749
  return (
742
750
  <Fragment>
743
751
  <code id={demoid.current} style={{ display: "none" }} />
744
- <code ref={refElement} data-name="mermaid" />
752
+ <code className={className} ref={refElement} data-name="mermaid" />
745
753
  </Fragment>
746
754
  );
747
755
  }
748
- return <code>{children}</code>;
756
+ return <code className={className}>{children}</code>;
749
757
  };
750
758
 
751
759
  export default function App() {
@@ -935,8 +943,8 @@ As always, thanks to our amazing contributors!
935
943
  <a href="https://github.com/MercierCorentin" title="Corentin Mercier">
936
944
  <img src="https://avatars.githubusercontent.com/u/46066895?v=4" width="42;" alt="Corentin Mercier"/>
937
945
  </a>
938
- <a href="https://github.com/dmitriyyan" title="Dmitriy Yanushkevich">
939
- <img src="https://avatars.githubusercontent.com/u/89025862?v=4" width="42;" alt="Dmitriy Yanushkevich"/>
946
+ <a href="https://github.com/dmitriyyan" title="Dmitrii Ianushkevich">
947
+ <img src="https://avatars.githubusercontent.com/u/89025862?v=4" width="42;" alt="Dmitrii Ianushkevich"/>
940
948
  </a>
941
949
  <a href="https://github.com/jnishiyama" title="James Finucane">
942
950
  <img src="https://avatars.githubusercontent.com/u/2048195?v=4" width="42;" alt="James Finucane"/>
package/dist/mdeditor.css CHANGED
@@ -1183,7 +1183,7 @@ body[data-color-mode*='light'] {
1183
1183
  .w-md-editor-toolbar {
1184
1184
  border-bottom: 1px solid var(--md-editor-box-shadow-color);
1185
1185
  background-color: var(--md-editor-background-color);
1186
- padding: 5px 5px;
1186
+ padding: 3px;
1187
1187
  display: flex;
1188
1188
  justify-content: space-between;
1189
1189
  align-items: center;