safe-mdx 1.3.1 → 1.3.3

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.
Files changed (81) hide show
  1. package/README.md +14 -14
  2. package/dist/assets/HtmlToJsxConverter-Ds0bTjpw.js +24 -0
  3. package/dist/assets/_commonjsHelpers-CqkleIqs.js +1 -0
  4. package/dist/assets/index-B5fPOjPt.css +1 -0
  5. package/dist/assets/index-B7ATSoRE.js +9 -0
  6. package/dist/assets/index-BwZ2FTRd.js +146 -0
  7. package/dist/assets/index-R1UqLMGJ.js +1 -0
  8. package/dist/assets/index-c0qeY2gs.js +9 -0
  9. package/dist/assets/jsx-runtime-BhZZLbvw.js +9 -0
  10. package/dist/assets/jsx-runtime-NArryeSM.js +1 -0
  11. package/dist/assets/react-Ca6JzGpx.js +1 -0
  12. package/dist/assets/react-dom-BYRHYqYl.js +1 -0
  13. package/dist/dynamic-esm-component.d.ts.map +1 -1
  14. package/dist/dynamic-esm-component.js +16 -1
  15. package/dist/dynamic-esm-component.js.map +1 -1
  16. package/dist/html/attributes.d.ts +19 -0
  17. package/dist/html/attributes.d.ts.map +1 -0
  18. package/dist/html/attributes.js +289 -0
  19. package/dist/html/attributes.js.map +1 -0
  20. package/dist/html/convert-attributes.d.ts +6 -0
  21. package/dist/html/convert-attributes.d.ts.map +1 -0
  22. package/dist/html/convert-attributes.js +43 -0
  23. package/dist/html/convert-attributes.js.map +1 -0
  24. package/dist/html/domparser-browser.d.ts +4 -0
  25. package/dist/html/domparser-browser.d.ts.map +1 -0
  26. package/dist/html/domparser-browser.js +7 -0
  27. package/dist/html/domparser-browser.js.map +1 -0
  28. package/dist/html/domparser.d.ts +2 -0
  29. package/dist/html/domparser.d.ts.map +1 -0
  30. package/dist/html/domparser.js +5 -0
  31. package/dist/html/domparser.js.map +1 -0
  32. package/dist/html/html-to-mdx-ast.d.ts +23 -0
  33. package/dist/html/html-to-mdx-ast.d.ts.map +1 -0
  34. package/dist/html/html-to-mdx-ast.js +227 -0
  35. package/dist/html/html-to-mdx-ast.js.map +1 -0
  36. package/dist/html/html-to-mdx-ast.test.d.ts +2 -0
  37. package/dist/html/html-to-mdx-ast.test.d.ts.map +1 -0
  38. package/dist/html/html-to-mdx-ast.test.js +324 -0
  39. package/dist/html/html-to-mdx-ast.test.js.map +1 -0
  40. package/dist/html/remark-mdx-jsx-normalize.d.ts +10 -0
  41. package/dist/html/remark-mdx-jsx-normalize.d.ts.map +1 -0
  42. package/dist/html/remark-mdx-jsx-normalize.js +117 -0
  43. package/dist/html/remark-mdx-jsx-normalize.js.map +1 -0
  44. package/dist/html/valid-html-elements.d.ts +10 -0
  45. package/dist/html/valid-html-elements.d.ts.map +1 -0
  46. package/dist/html/valid-html-elements.js +50 -0
  47. package/dist/html/valid-html-elements.js.map +1 -0
  48. package/dist/index.html +19 -0
  49. package/dist/parse.d.ts +2 -0
  50. package/dist/parse.d.ts.map +1 -1
  51. package/dist/parse.js +2 -0
  52. package/dist/parse.js.map +1 -1
  53. package/dist/safe-mdx.d.ts +2 -2
  54. package/dist/safe-mdx.d.ts.map +1 -1
  55. package/dist/safe-mdx.js +39 -77
  56. package/dist/safe-mdx.js.map +1 -1
  57. package/dist/safe-mdx.test.js +161 -8
  58. package/dist/safe-mdx.test.js.map +1 -1
  59. package/package.json +27 -6
  60. package/src/dynamic-esm-component.tsx +40 -10
  61. package/src/html/README +17 -0
  62. package/src/html/attributes.ts +297 -0
  63. package/src/html/convert-attributes.ts +59 -0
  64. package/src/html/domparser-browser.ts +6 -0
  65. package/src/html/domparser.ts +5 -0
  66. package/src/html/html-to-mdx-ast.test.ts +365 -0
  67. package/src/html/html-to-mdx-ast.ts +304 -0
  68. package/src/html/remark-mdx-jsx-normalize.ts +128 -0
  69. package/src/html/valid-html-elements.ts +65 -0
  70. package/src/parse.ts +3 -0
  71. package/src/safe-mdx.test.tsx +178 -12
  72. package/src/safe-mdx.tsx +61 -93
  73. package/dist/HtmlToJsxConverter.d.ts +0 -10
  74. package/dist/HtmlToJsxConverter.d.ts.map +0 -1
  75. package/dist/HtmlToJsxConverter.js +0 -22
  76. package/dist/HtmlToJsxConverter.js.map +0 -1
  77. package/dist/plugins.d.ts +0 -12
  78. package/dist/plugins.d.ts.map +0 -1
  79. package/dist/plugins.js +0 -68
  80. package/dist/plugins.js.map +0 -1
  81. package/src/HtmlToJsxConverter.tsx +0 -37
package/README.md CHANGED
@@ -13,21 +13,21 @@
13
13
  - Render MDX without `eval` on the server, so you can render MDX in Cloudflare Workers and Vercel Edge
14
14
  - Works with React Server Components
15
15
  - Supports custom MDX components
16
- - custom `createElement`. Pass a no-op function to use safe-mdx as a validation step.
17
- - use `componentPropsSchema` to validate component props against a schema (works with Zod, Valibot, etc).
16
+ - Custom `createElement`. Pass a no-op function to use safe-mdx as a validation step.
17
+ - Use `componentPropsSchema` to validate component props against a schema (works with Zod, Valibot, etc).
18
18
  - ESM `https://` imports support with `allowClientEsmImports` option (disabled by default for security)
19
- - fast. 3ms to render the [full mdx document for Zod v3](https://github.com/colinhacks/zod/blob/0a49fa39348b7c72b19ddedc3b0f879bd395304b/packages/docs/content/packages/v3.mdx) (2500 lines)
19
+ - Fast. 3ms to render the [full mdx document for Zod v3](https://github.com/colinhacks/zod/blob/0a49fa39348b7c72b19ddedc3b0f879bd395304b/packages/docs/content/packages/v3.mdx) (2500 lines)
20
20
 
21
21
  ## Why
22
22
 
23
- The default MDX renderer uses `eval` (or `new Function(code)`) to render MDX components in the server. This is a security risk if the MdX code comes from untrusted sources and it's not allowed in some environments like Cloudflare Workers.
23
+ The default MDX renderer uses `eval` (or `new Function(code)`) to render MDX components in the server. This is a security risk if the MDX code comes from untrusted sources and it's not allowed in some environments like Cloudflare Workers.
24
24
 
25
- For example in an hypothetical platform similar to Notion, where users can write Markdown and publish it as a website, an user could be able to write MDX code that extracts secrets from the server in the SSR pass, using this library that is not possible. This is what happened with Mintlify platform in 2024.
25
+ For example in a hypothetical platform similar to Notion, where users can write Markdown and publish it as a website, a user could be able to write MDX code that extracts secrets from the server in the SSR pass, using this library that is not possible. This is what happened with Mintlify platform in 2024.
26
26
 
27
27
  Some use cases for this package are:
28
28
 
29
29
  - Render MDX in Cloudflare Workers and Vercel Edge
30
- - Safely render dynamically generated MDX code, like inside a ChatGPT like interface
30
+ - Safely render dynamically generated MDX code, like inside a ChatGPT-style interface
31
31
  - Render user generated MDX, like in a multi-tenant SaaS app
32
32
 
33
33
  <br>
@@ -217,7 +217,7 @@ export function Page() {
217
217
 
218
218
  ## Reading the frontmatter
219
219
 
220
- safe-mdx renderer ignores the frontmatter, to get its values you wil have to parse the MDX to mdast and read it there.
220
+ safe-mdx renderer ignores the frontmatter, to get its values you will have to parse the MDX to mdast and read it there.
221
221
 
222
222
  ```tsx
223
223
  import { SafeMdxRenderer } from 'safe-mdx'
@@ -253,9 +253,9 @@ export function Page() {
253
253
 
254
254
  ## Override code block component
255
255
 
256
- It's not pratical to override the code block component using `code` as a component override, because it will also be used for inline code blocks. It also does not have access to meta string and language.
256
+ It's not practical to override the code block component using `code` as a component override, because it will also be used for inline code blocks. It also does not have access to meta string and language.
257
257
 
258
- Instead you can use `renderNode` to return some jsx for a specific mdast node:
258
+ Instead you can use `renderNode` to return some JSX for a specific mdast node:
259
259
 
260
260
  ```tsx
261
261
  <SafeMdxRenderer
@@ -301,15 +301,15 @@ safe-mdx is designed to avoid server-side evaluation of untrusted MDX input.
301
301
 
302
302
  However, it's important to note that safe-mdx does not provide protection against client-side vulnerabilities, such as Cross-Site Scripting (XSS) or script injection attacks. While safe-mdx itself does not perform any evaluation or rendering of user-provided content, the rendering library or components used in conjunction with safe-mdx may introduce security risks if not properly configured or sanitized.
303
303
 
304
- This is ok if you render your MDX in isolation from each tenant, for example on different subdomains, this way an XSS attack cannot affect all tenants. If instead you render the MDX from different tenants on the same domain, one tenant could steal cookies set from other customers.
304
+ This is okay if you render your MDX in isolation from each tenant - for example on different subdomains - because an XSS attack cannot affect all tenants. But if instead you render the MDX from different tenants on the same domain, one tenant could steal cookies set from other customers.
305
305
 
306
306
  ## Limitations
307
307
 
308
308
  These features are not supported yet:
309
309
 
310
- - expressions that use methods or functions, currently expressions are evaluated with [eval-estree-expression](https://github.com/jonschlinkert/eval-estree-expression) with the functions option disabled.
311
- - importing components or data from other files (unless `allowClientEsmImports` is enabled for https:// imports).
312
- - Exporting irresolvable or declaring components inline in the MDX
310
+ - Expressions that use methods or functions, currently expressions are evaluated with [eval-estree-expression](https://github.com/jonschlinkert/eval-estree-expression) with the functions option disabled.
311
+ - Importing components or data from other files (unless `allowClientEsmImports` is enabled for `https://` imports).
312
+ - Exporting unresolved components or declaring components inline in the MDX
313
313
 
314
314
  **Note**: JSX components in attributes are now supported! You can use React components inside attributes like `<Card icon={<Icon />}>` without relying on JavaScript evaluation.
315
315
 
@@ -317,4 +317,4 @@ To overcome the remaining limitations you can define custom logic in your compon
317
317
 
318
318
  ## Future Roadmap
319
319
 
320
- - add support for scope parameter to allow referencing variables in expressions and code
320
+ - Add support for scope parameter to allow referencing variables in expressions and code