@m2d/react-markdown
Version:
A modern, SSR-friendly React Markdown renderer that preserves the MDAST tree for reuse (e.g., mdast2docx), supports full JSX children, unified plugins, and component overrides.
2 lines (1 loc) • 2.2 kB
JavaScript
;var L=Object.create;var l=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var J=(r,t)=>{for(var e in t)l(r,e,{get:t[e],enumerable:!0})},M=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of O(t))!C.call(r,o)&&o!==e&&l(r,o,{get:()=>t[o],enumerable:!(s=H(t,o))||s.enumerable});return r};var R=(r,t,e)=>(e=r!=null?L(S(r)):{},M(t||!r||!r.__esModule?l(e,"default",{value:r,enumerable:!0}):e,r)),T=r=>M(l({},"__esModule",{value:!0}),r);var X={};J(X,{Mdx:()=>h});module.exports=T(X);var k=R(require("remark-parse")),w=R(require("remark-rehype")),v=require("unified"),A=require("hast-util-to-jsx-runtime"),i=require("react/jsx-runtime"),I=require("unist-util-visit");var E=()=>crypto.randomUUID();var b=({children:r,remarkPlugins:t=[],rehypePlugins:e=[],remarkRehypeOptions:s,astRef:o,components:f,skipHtml:m})=>{let c=(0,v.unified)().use(k.default).use(t).use(w.default,{...s,allowDangerousHtml:!m}).use(e),p=c.parse(r!=null?r:""),a=c.runSync(p);return o&&(o.current||(o.current=[]),o.current.push({mdast:p,hast:a})),(0,I.visit)(a,(u,d,y)=>{var x;u.type==="raw"&&y&&typeof d=="number"&&(m?y.children.splice(d,1):y.children[d]={type:"text",value:u.value}),u.type==="element"&&((x=u.properties).src||(x.src=null))}),(0,A.toJsxRuntime)(a,{Fragment:i.Fragment,components:f,ignoreInvalidStyle:!0,jsx:i.jsx,jsxs:i.jsxs,passKeys:!0,passNode:!0})};var P=require("react"),g=({children:r,markdownProps:t})=>{if(typeof r=="string")return(0,i.jsx)(b,{...t,children:r});if(Array.isArray(r)){let e=E();return r.map((s,o)=>(0,i.jsx)(g,{markdownProps:t,children:s},e+o))}if((0,P.isValidElement)(r)){let e=r.type,s=r.props;return(0,i.jsx)(e,{...s,children:(0,i.jsx)(g,{markdownProps:t,children:s.children})})}return r},h=({children:r,wrapper:t,remarkPlugins:e,rehypePlugins:s,remarkRehypeOptions:o,astRef:f,components:m,skipHtml:c,...p})=>{let a=t!=null?t:Object.keys(p).length?"div":P.Fragment;return(0,i.jsx)(a,{...p,children:(0,i.jsx)(g,{markdownProps:{remarkPlugins:e,rehypePlugins:s,remarkRehypeOptions:o,astRef:f,components:m,skipHtml:c},children:r})})};0&&(module.exports={Mdx});