"use strict";const q=require("../../../../hast-util-from-html-isomorphic@2.0.0/node_modules/hast-util-from-html-isomorphic/lib/browser.cjs.js"),h=require("../../../../katex@0.16.28/node_modules/katex/dist/katex.cjs.js"),m=require("../../../../unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/index.cjs.js"),C=require("../../../../hast-util-to-text@4.0.2/node_modules/hast-util-to-text/lib/index.cjs.js"),I={},O=[];function S(g){const o=g||I;return function(y,f){m.visitParents(y,"element",function(r,s){const n=Array.isArray(r.properties.className)?r.properties.className:O,u=n.includes("language-math"),p=n.includes("math-display"),x=n.includes("math-inline");let i=p;if(!u&&!p&&!x)return;let e=s[s.length-1],c=r;if(r.tagName==="code"&&u&&e&&e.type==="element"&&e.tagName==="pre"&&(c=e,e=s[s.length-2],i=!0),!e)return;const a=C.toText(c,{whitespace:"pre"});let t;try{t=h.default.renderToString(a,{...o,displayMode:i,throwOnError:!0})}catch(l){const d=l,N=d.name.toLowerCase();f.message("Could not render math with KaTeX",{ancestors:[...s,r],cause:d,place:r.position,ruleId:N,source:"rehype-katex"});try{t=h.default.renderToString(a,{...o,displayMode:i,strict:"ignore",throwOnError:!1})}catch{t=[{type:"element",tagName:"span",properties:{className:["katex-error"],style:"color:"+(o.errorColor||"#cc0000"),title:String(l)},children:[{type:"text",value:a}]}]}}typeof t=="string"&&(t=q.fromHtmlIsomorphic(t).children);const w=e.children.indexOf(c);return e.children.splice(w,1,...t),m.SKIP})}}module.exports=S;
//# sourceMappingURL=index.cjs.js.map
