@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.
- package/components/HTMLBlock/index.tsx +36 -0
- package/components/Image/index.tsx +12 -27
- package/dist/components/HTMLBlock/index.d.ts +7 -0
- package/dist/components/Image/index.d.ts +12 -13
- package/dist/enums.d.ts +2 -1
- package/dist/main.js +278 -598
- package/dist/main.node.js +300 -306
- package/dist/processor/compile/html-block.d.ts +3 -0
- package/package.json +2 -2
- package/components/HTMLBlock/index.jsx +0 -69
|
@@ -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
|
-
|
|
4
|
-
align
|
|
5
|
-
alt
|
|
6
|
-
border
|
|
7
|
-
caption
|
|
8
|
-
className
|
|
9
|
-
height
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
align
|
|
4
|
-
alt
|
|
5
|
-
border
|
|
6
|
-
caption:
|
|
7
|
-
className
|
|
8
|
-
height
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|