@readme/markdown 6.75.0-beta.30 → 6.75.0-beta.31

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.
@@ -0,0 +1,36 @@
1
+ import React, { useEffect } from 'react';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+
4
+ const MATCH_SCRIPT_TAGS = /<script\b[^>]*>([\s\S]*?)<\/script *>\n?/gim;
5
+
6
+ const extractScripts = (html: string = ''): [string, () => void] => {
7
+ const scripts: string[] = [];
8
+ let match: RegExpExecArray | null;
9
+ while ((match = MATCH_SCRIPT_TAGS.exec(html)) !== null) {
10
+ scripts.push(match[1]);
11
+ }
12
+ const cleaned = html.replace(MATCH_SCRIPT_TAGS, '');
13
+ return [cleaned, () => scripts.map(js => window.eval(js))];
14
+ };
15
+
16
+ const HTMLBlock = ({ children = '', runScripts = false, safeMode = false }) => {
17
+ let html = children;
18
+ if (typeof html !== 'string') html = renderToStaticMarkup(html);
19
+ const [cleanedHtml, exec] = extractScripts(html);
20
+
21
+ useEffect(() => {
22
+ if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts) exec();
23
+ }, [runScripts, exec]);
24
+
25
+ if (safeMode) {
26
+ return (
27
+ <pre className="html-unsafe">
28
+ <code>{html}</code>
29
+ </pre>
30
+ );
31
+ }
32
+
33
+ return <div className="rdmd-html" dangerouslySetInnerHTML={{ __html: cleanedHtml }} />;
34
+ };
35
+
36
+ export default HTMLBlock;
@@ -1,34 +1,19 @@
1
1
  import * as React from 'react';
2
2
 
3
- interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLImageElement>> {
4
- align: string;
5
- alt: string;
6
- border: boolean;
7
- caption: string;
8
- className: string;
9
- height: string;
10
- lazy: boolean;
11
- src: string;
12
- title: string;
13
- width: string;
14
- }
15
-
16
- const Image = (props: Props) => {
3
+ const Image = ({
4
+ align = '',
5
+ alt = '',
6
+ border = false,
7
+ caption,
8
+ className = '',
9
+ height = 'auto',
10
+ src = '',
11
+ title = '',
12
+ width = 'auto',
13
+ lazy = false,
14
+ }) => {
17
15
  const [lightbox, setLightbox] = React.useState(false);
18
16
 
19
- const {
20
- align = '',
21
- alt = '',
22
- border = false,
23
- caption,
24
- className = '',
25
- height = 'auto',
26
- lazy,
27
- src = '',
28
- title = '',
29
- width = 'auto',
30
- } = props;
31
-
32
17
  if (className === 'emoji') {
33
18
  return <img src={src} width={width} height={height} title={title} alt={alt} loading={lazy ? 'lazy' : 'eager'} />;
34
19
  }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ declare const HTMLBlock: ({ children, runScripts, safeMode }: {
3
+ children?: string;
4
+ runScripts?: boolean;
5
+ safeMode?: boolean;
6
+ }) => React.JSX.Element;
7
+ export default HTMLBlock;
@@ -1,15 +1,14 @@
1
1
  import * as React from 'react';
2
- interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLImageElement>> {
3
- align: string;
4
- alt: string;
5
- border: boolean;
6
- caption: string;
7
- className: string;
8
- height: string;
9
- lazy: boolean;
10
- src: string;
11
- title: string;
12
- width: string;
13
- }
14
- declare const Image: (props: Props) => React.JSX.Element;
2
+ declare const Image: ({ align, alt, border, caption, className, height, src, title, width, lazy, }: {
3
+ align?: string;
4
+ alt?: string;
5
+ border?: boolean;
6
+ caption: any;
7
+ className?: string;
8
+ height?: string;
9
+ src?: string;
10
+ title?: string;
11
+ width?: string;
12
+ lazy?: boolean;
13
+ }) => React.JSX.Element;
15
14
  export default Image;
package/dist/enums.d.ts CHANGED
@@ -2,5 +2,6 @@ export declare enum NodeTypes {
2
2
  codeTabs = "code-tabs",
3
3
  emoji = "emoji",
4
4
  i = "i",
5
- image = "image"
5
+ image = "image",
6
+ htmlBlock = "html-block"
6
7
  }