"use strict";(self.webpackChunkptjnb=self.webpackChunkptjnb||[]).push([[416],{416(e,t,n){n.r(t),n.d(t,{PARSERS:()=>o,convertIfMissing:()=>l,default:()=>f});var a=n(964);const o={parsePy:a.parsePy,parseSphinxGallery:a.parseSphinxGallery,parseClassicMd:a.parseClassicMd,parseMystMd:a.parseMystMd},r={parsePy:"Percent format (.py)",parseSphinxGallery:"Sphinx Gallery (.py)",parseClassicMd:"Classic Markdown (.md)",parseMystMd:"MyST Notebook (.md)"},s={parsePy:[".py"],parseSphinxGallery:[".py"],parseClassicMd:[".md"],parseMystMd:[".md"]},i={name:"xpython",display_name:"Python 3.13 (XPython)",language:"python"};async function c(e,t,n,a){var o,r,s,c;const l=(await e.get(t,{type:"file",format:"text",content:!0})).content,p=n(l);if(!(null===(o=p.metadata)||void 0===o?void 0:o.kernelspec)){p.metadata=null!==(r=p.metadata)&&void 0!==r?r:{};const e=null!==(c=null!==(s=function(e){var t,n;const a=e.replace(/\r\n/g,"\n").split("\n"),o=!!(null===(t=a[0])||void 0===t?void 0:t.match(/^#\s*---\s*$/)),r="---"===(null===(n=a[0])||void 0===n?void 0:n.trim());if(!o&&!r)return null;const s=[];let i=!1;for(let e=1;e<a.length;e++)if(o){if(a[e].match(/^#\s*---\s*$/)){i=!0;break}if(!a[e].startsWith("#"))break;s.push(a[e].replace(/^#\s?/,""))}else{if("---"===a[e].trim()){i=!0;break}s.push(a[e])}if(!i)return null;let c=!1,l=0;const p={};for(const e of s){if(""===e.trim())continue;const t=e.match(/^(\s*)/)[1].length,n=e.trim();if("kernelspec:"!==n){if(c){if(t<=l&&""!==n)break;const e=n.match(/^(\w+):\s*(.+)$/);e&&(p[e[1]]=e[2])}}else c=!0,l=t}return p.name&&p.display_name&&p.language?p:null}(l))&&void 0!==s?s:a)&&void 0!==c?c:i;p.metadata.kernelspec=e,p.metadata.language_info||(p.metadata.language_info={name:e.language})}const d=t.replace(/\.(py|md)$/,".ipynb");await e.save(d,{type:"notebook",format:"json",content:p})}async function l(e,t,n,a){const o=t.replace(/\.(py|md)$/,".ipynb");try{return void await e.get(o,{content:!1})}catch(e){}try{await c(e,t,n,a)}catch(e){console.error(`ptjnb: failed to convert "${t}"`,e)}}async function p(e,t,n,a){let o;try{o=await e.get(t,{content:!0})}catch(e){return void console.warn(`ptjnb: directory not found "${t}"`)}if("directory"===o.type)for(const t of o.content)"directory"===t.type?await p(e,t.path,n,a):"file"===t.type&&(t.name.endsWith(".py")||t.name.endsWith(".md"))&&await l(e,t.path,n,a)}var d=n(778),u=n(641),y=n(41),m=n(444);const f={id:"ptjnb:plugin",autoStart:!0,requires:[u.IFileBrowserFactory],activate:async(e,t)=>{var n;console.log("ptjnb extension activated!");const{commands:a,contextMenu:i}=e,l=y.PageConfig.getOption("plainTextNotebookConfig");let u={};try{u=l?JSON.parse(l):{}}catch(e){console.error("ptjnb: invalid plainTextNotebookConfig JSON")}const f=u.defaultKernelspec,v=()=>t.tracker.currentWidget;Object.keys(o).forEach(t=>{const n=`ptjnb:convert-${t}`,i=o[t],l=s[t];a.addCommand(n,{label:r[t],isVisible:()=>{const e=v();if(!e)return!1;const t=e.selectedItems().next();return!(t.done||!t.value)&&l.some(e=>t.value.path.endsWith(e))},execute:async()=>{const t=v();if(!t)return;const n=t.selectedItems().next();if(n.done||!n.value)return;const a=n.value.path,o=a.replace(/\.(py|md)$/,".ipynb"),r=e.serviceManager.contents;try{let e=!1;try{await r.get(o,{content:!1}),e=!0}catch(e){}if(e&&!(await(0,d.showDialog)({title:"Overwrite notebook?",body:`"${o}" already exists. Overwrite it?`,buttons:[d.Dialog.cancelButton(),d.Dialog.warnButton({label:"Overwrite"})]})).button.accept)return;await c(r,a,i,f)}catch(e){console.error("ptjnb: conversion failed",e)}}})});const b=new m.MenuSvg({commands:a});b.title.label="Convert to Notebook",b.addItem({command:"ptjnb:convert-parsePy"}),b.addItem({command:"ptjnb:convert-parseSphinxGallery"}),b.addItem({command:"ptjnb:convert-parseClassicMd"}),b.addItem({command:"ptjnb:convert-parseMystMd"}),i.addItem({type:"submenu",submenu:b,selector:'.jp-DirListing-item[data-isdir="false"]',rank:10}),(null===(n=u.rules)||void 0===n?void 0:n.length)&&await async function(e,t,n){for(const a of t){const t=o[a.parser];t?await p(e,a.dir,t,n):console.warn(`ptjnb: unknown parser "${a.parser}"`)}}(e.serviceManager.contents,u.rules,f)}}}}]);