@readme/markdown 14.11.5 → 14.12.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.
@@ -21,16 +21,12 @@ interface Props {
21
21
  }
22
22
 
23
23
  const HTMLBlock = ({ children = '', html: htmlProp, runScripts, safeMode: safeModeRaw = false }: Props) => {
24
- // Determine HTML source: MDXish uses html prop (from HAST), MDX uses children
25
- let html: string = '';
26
- if (htmlProp !== undefined) {
27
- html = htmlProp;
28
- } else {
29
- if (typeof children !== 'string') {
30
- throw new TypeError('HTMLBlock: children must be a string');
31
- }
32
- html = children;
33
- }
24
+ // Determine HTML source: MDXish uses html prop (from HAST), MDX uses children.
25
+ // A non-string child (no html prop) can't be injected as raw HTML — see the
26
+ // fail-soft fallback below.
27
+ const htmlSource = htmlProp !== undefined ? htmlProp : children;
28
+ const nonStringChildren = typeof htmlSource !== 'string';
29
+ const html: string = nonStringChildren ? '' : htmlSource;
34
30
 
35
31
  // eslint-disable-next-line no-param-reassign
36
32
  runScripts = typeof runScripts !== 'boolean' ? runScripts === 'true' : runScripts;
@@ -45,6 +41,12 @@ const HTMLBlock = ({ children = '', html: htmlProp, runScripts, safeMode: safeMo
45
41
  if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts) exec();
46
42
  }, [runScripts, exec]);
47
43
 
44
+ if (nonStringChildren) {
45
+ // Fail soft: a non-string child (e.g. JSX that wasn't serialized back to a
46
+ // raw string) should never throw, so render the child nodes directly
47
+ return <div className="rdmd-html">{children}</div>;
48
+ }
49
+
48
50
  if (safeMode) {
49
51
  return (
50
52
  <pre className="html-unsafe">