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

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.
@@ -3,12 +3,29 @@ import * as React from 'react';
3
3
  interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
4
4
  attributes: {};
5
5
  icon: string;
6
- theme: string;
6
+ theme?: string;
7
7
  heading?: React.ReactElement;
8
8
  }
9
9
 
10
+ const themes: Record<string, string> = {
11
+ '\uD83D\uDCD8': 'info',
12
+ '\uD83D\uDEA7': 'warn',
13
+ '\u26A0\uFE0F': 'warn',
14
+ '\uD83D\uDC4D': 'okay',
15
+ '\u2705': 'okay',
16
+ '\u2757\uFE0F': 'error',
17
+ '\u2757': 'error',
18
+ '\uD83D\uDED1': 'error',
19
+ '\u2049\uFE0F': 'error',
20
+ '\u203C\uFE0F': 'error',
21
+ '\u2139\uFE0F': 'info',
22
+ '\u26A0': 'warn',
23
+ };
24
+
10
25
  const Callout = (props: Props) => {
11
- const { attributes, children, theme, icon, heading } = props;
26
+ const { attributes, children, icon, heading } = props;
27
+
28
+ let theme = props.theme || themes[icon] || 'default';
12
29
 
13
30
  return (
14
31
  // @ts-ignore
@@ -6,13 +6,16 @@ import React, { createRef } from 'react';
6
6
  // https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
7
7
  let syntaxHighlighter;
8
8
  let canonicalLanguage = _ => '';
9
+
9
10
  if (typeof window !== 'undefined') {
10
- // eslint-disable-next-line global-require
11
- syntaxHighlighter = require('@readme/syntax-highlighter').default;
12
- // eslint-disable-next-line global-require
13
- ({ canonical: canonicalLanguage } = require('@readme/syntax-highlighter'));
11
+ const module = await import('@readme/syntax-highlighter');
12
+
13
+ syntaxHighlighter = module.default;
14
+ canonicalLanguage = module.canonical;
14
15
  }
15
16
 
17
+ console.log(syntaxHighlighter);
18
+
16
19
  function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
17
20
  const copyClass = `${rootClass}_copied`;
18
21
  const button = createRef<HTMLButtonElement>();
@@ -52,7 +55,7 @@ const Code = (props: Props) => {
52
55
  dark: theme === 'dark',
53
56
  };
54
57
 
55
- const code = value ?? children?.[0] ?? children ?? '';
58
+ const code = value ?? (Array.isArray(children) ? children[0] : children) ?? '';
56
59
  const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts) : code;
57
60
 
58
61
  return (
@@ -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
  }
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
3
3
  attributes: {};
4
4
  icon: string;
5
- theme: string;
5
+ theme?: string;
6
6
  heading?: React.ReactElement;
7
7
  }
8
8
  declare const Callout: (props: Props) => React.JSX.Element;
@@ -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
@@ -1,6 +1,8 @@
1
1
  export declare enum NodeTypes {
2
+ callout = "callout",
2
3
  codeTabs = "code-tabs",
3
4
  emoji = "emoji",
4
5
  i = "i",
5
- image = "image"
6
+ image = "image",
7
+ htmlBlock = "html-block"
6
8
  }
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
+ import './demo.scss';
2
3
  declare const App: () => React.JSX.Element;
3
4
  export default App;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { RunOptions } from '@mdx-js/mdx';
3
3
  import * as Components from './components';
4
+ type ComponentOpts = Record<string, (props: any) => React.ReactNode>;
4
5
  type RunOpts = Omit<RunOptions, 'Fragment'> & {
5
- components?: Record<string, () => React.ReactNode>;
6
+ components?: ComponentOpts;
6
7
  imports?: Record<string, unknown>;
7
8
  };
8
9
  export { Components };