notebook-mdx
Version:
Jupyter Notebook support for MDX via Remark and Rehype plugins
1 lines • 1.43 kB
JavaScript
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`fs`)),n=e.__toESM(require(`path`)),r=e.__toESM(require(`unist-util-visit`)),i=e=>e===void 0?void 0:e===`true`||e===``,a=(e={})=>{let{componentName:a=`NotebookLoader`}=e;return(o,s)=>{(0,r.visit)(o,r=>{if(![`containerDirective`,`leafDirective`,`textDirective`].includes(r.type)||r.name!==`notebook`)return;r.type===`textDirective`&&s.fail("Unexpected `:notebook` text directive, use two colons for a leaf directive or three colons for a container directive",r);let o=r.attributes?.file;o||s.fail("Unexpected missing `file` attribute on `notebook` directive",r);try{let c=e.baseDir||(s.path?(0,n.dirname)(s.path):process.cwd()),l=(0,n.resolve)(c,o),u=s.data;u.dependencies||=[],u.dependencies.includes(l)||u.dependencies.push(l),s.history.includes(l)||s.history.push(l);let d=(0,t.readFileSync)(l,`utf-8`),f=JSON.parse(d),{file:p,...m}=r.attributes||{},h={notebookDataJson:JSON.stringify(f),...m};[`hideCode`,`showOutputs`,`showCellNumbers`,`showLanguageIndicators`,`interactive`].forEach(e=>{let t=i(m[e]);t!==void 0&&(h[e]=t)});let g=r.data||={};g.hName=a,g.hProperties=h,r.type===`containerDirective`&&r.children?.length>0&&(h.caption=r.children,r.children=[])}catch(e){s.fail(`Failed to process notebook file "${o}": ${e instanceof Error?e.message:String(e)}`,r)}})}};Object.defineProperty(exports,`remarkNotebookDirective`,{enumerable:!0,get:function(){return a}});