@mdgate/onenote 0.5.0 → 0.5.2
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.
- package/dist/index.js +4 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{detectOleDoc as
|
|
2
|
-
`))return!1;if(r)return n.length<=80;if(!o)return!1;return n.length<=40&&!/[.!?]/.test(n)}function
|
|
1
|
+
import{detectOleDoc as Sn,detectZipDoc as Pn,Package as Yn}from"@mdgate/containers";import{ConvertError as d}from"@mdgate/core";import{documentToMarkdown as $,emptyDocument as Ln,heading as Mn,plain as i}from"@mdgate/document";import{fileExtension as q}from"@mdgate/utils";import{CompoundFile as j,hasOleMagic as T}from"@mdgate/containers";import{ConvertError as w}from"@mdgate/core";import{emptyDocument as N,heading as gn,plain as D}from"@mdgate/document";import{cleanText as kn,collapseWs as wn,isAlphanumeric as cn}from"@mdgate/utils";import{CompoundFile as y,detectOleDoc as t,hasOleMagic as R}from"@mdgate/containers";var b=[228,82,92,123,140,216,167,77,174,177,83,120,208,41,150,211],s=[250,55,221,31,190,73,208,17,140,85,0,192,79,217,15,133],e=[161,47,255,67,217,239,118,76,158,226,16,234,87,34,118,95],nn=[63,221,154,16,27,145,245,73,165,208,23,145,237,200,174,216],rn=[b,s,e],on=["{7B5C52E4-D88C-4DA7-AEB1-5378D02996D3}","{1FDD37FA-49BE-11D0-8C55-00C04FD90F85}","{43FF2FA1-EFD9-4C76-9EE2-10EA5722765F}"],un=[79,78,69,32];function z(n){if(t(n)==="one")return!0;return mn(n)}function mn(n){if(!R(n))return!1;try{let r=y.open(n);for(let o of r.readRootStorage())if(o.name.length>=7&&o.name.slice(0,7).toLowerCase()==="onenote")return!0}catch{return!1}return!1}function k(n){return z(n)||pn(n)}function pn(n){if(P(n)||Y(n)||L(n))return!0;return M(n)}function S(n){if(P(n))return n.length>=1024?1024:16;if(L(n))return 4;if(M(n))return 38;if(Y(n))return n.length>=1024?1024:64;return 0}function P(n){for(let r of rn)if(K(n,r,0))return!0;return!1}function Y(n){return K(n,nn,48)}function L(n){return K(n,un,0)}function M(n){for(let r of on)if(dn(n,r,0))return!0;return!1}function A(n){let r=vn(n);return fn(n,"%PDF-",r)}function Z(n){return n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4}function B(n){return R(n)}function vn(n){let r=0;if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)r=3;while(r<n.length){let o=n[r];if(o!==9&&o!==10&&o!==13&&o!==32)break;r+=1}return r}function K(n,r,o){if(o+r.length>n.length)return!1;for(let u=0;u<r.length;u+=1)if(n[o+u]!==r[u])return!1;return!0}function fn(n,r,o){if(o+r.length>n.length)return!1;for(let u=0;u<r.length;u+=1)if(n[o+u]!==r.charCodeAt(u))return!1;return!0}function dn(n,r,o){if(o+r.length>n.length)return!1;for(let u=0;u<r.length;u+=1){let p=n[o+u],m=r.charCodeAt(u);if(p===m)continue;let f=p>=65&&p<=90?p+32:p,v=m>=65&&m<=90?m+32:m;if(f!==v)return!1}return!0}var J=4,$n=2,zn=/^\{?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}?$/i,Zn=["jcid","fcr","objectspace","filedatastore","persistable","onenote_","microsoft.office","http://","https://","xmlns","application/"];function W(n){try{if(T(n))return Kn(n);return H(E(n))}catch(r){if(r instanceof w&&(r.code==="encrypted"||r.isFatal()))throw r;try{return H(E(n))}catch(o){if(o instanceof w&&o.isFatal())throw o;return N()}}}function F(n){if(T(n))try{let r=j.open(n);if(r.exists("EncryptionInfo")||r.exists("EncryptedPackage"))return!0}catch{}return h(n,"this section is password protected")||h(n,"this notebook is password protected")||O(n,"this section is password protected")||O(n,"this notebook is password protected")}function Kn(n){let r=j.open(n);if(r.exists("EncryptionInfo")||r.exists("EncryptedPackage"))throw w.encrypted();let o=[];for(let u of r.readRootStorage()){if(u.type!==$n)continue;try{X(r.readStream(u.name),o)}catch(p){if(p instanceof w&&p.isFatal())throw p}}if(o.length===0)X(n,o);return H(o)}function E(n){let r=[];return X(n,r),r}function X(n,r){let o=S(n),u=o>0?n.subarray(o):n;Xn(u,r),Hn(u,r)}function Xn(n,r){let o=new TextDecoder("utf-16le");for(let u of[0,1]){let p=-1,m=(v)=>{if(p>=0){if(v-p>>1>=J)U(o.decode(n.subarray(p,v)),r)}p=-1};for(let v=u;v+1<n.length;v+=2){let g=n[v]|n[v+1]<<8;if(g!==0&&G(g)){if(p<0)p=v}else m(v)}let f=n.length-(n.length-u&1);m(f)}}function Hn(n,r){let o=new TextDecoder("utf-8",{fatal:!1}).decode(n),u=-1,p=(m)=>{if(u>=0&&m-u>=J)U(o.slice(u,m),r);u=-1};for(let m=0;m<o.length;m+=1){let f=o.charCodeAt(m);if(G(f)){if(u<0)u=m}else p(m)}p(o.length)}function U(n,r){let o=wn(kn(n)).trim();if(!Jn(o))return;if(r.includes(o))return;r.push(o)}function G(n){if(n===9||n===10||n===13||n===32)return!0;if(n<32||n>=127&&n<=159)return!1;return n!==65534&&n!==65535}function Jn(n){if(n.length<J)return!1;if(zn.test(n))return!1;if(Qn(n.toLowerCase()))return!1;let r=0;for(let o of n)if(cn(o))r+=1;if(r<2)return!1;if(r*4<n.length)return!1;return!0}function Qn(n){for(let r of Zn)if(n.startsWith(r))return!0;return n.includes("xmlns")||n.includes("http://schemas.")||n.includes("https://schemas.")}function H(n){let r=N(),o=new Set,u=!0,p=!1;for(let m of n){if(o.has(m))continue;o.add(m);let f=Vn(m,u,p);r.blocks.push(f),p=f.type==="paragraph",u=!1}return r}function Vn(n,r,o){if(qn(n,r,o))return gn(r?1:2,[D(n)]);return{type:"paragraph",inlines:[D(n)]}}function qn(n,r,o){if(n.includes(`
|
|
2
|
+
`))return!1;if(r)return n.length<=80;if(!o)return!1;return n.length<=40&&!/[.!?]/.test(n)}function O(n,r){if(r.length===0||n.length<r.length)return!1;let o=r.length,u=r.charCodeAt(0),p=u>=65&&u<=90?u+32:u;for(let m=0;m<=n.length-o;m+=1){let f=n[m];if((f>=65&&f<=90?f+32:f)!==p)continue;if(Cn(n,m,r))return!0}return!1}function h(n,r){let o=r.length;if(o===0||n.length<o*2)return!1;let u=r.charCodeAt(0),p=u>=65&&u<=90?u+32:u;for(let m of[0,1])for(let f=m;f+o*2<=n.length;f+=2){let v=n[f]|n[f+1]<<8;if((v>=65&&v<=90?v+32:v)!==p)continue;if(Rn(n,f,r))return!0}return!1}function Cn(n,r,o){for(let u=1;u<o.length;u+=1){let p=n[r+u],m=o.charCodeAt(u),f=p>=65&&p<=90?p+32:p,v=m>=65&&m<=90?m+32:m;if(f!==v)return!1}return!0}function Rn(n,r,o){for(let u=1;u<o.length;u+=1){let p=n[r+u*2]|n[r+u*2+1]<<8,m=o.charCodeAt(u),f=p>=65&&p<=90?p+32:p,v=m>=65&&m<=90?m+32:m;if(f!==v)return!1}return!0}var x=new Set(["one","onetoc2","onepkg"]);function C(){return{id:"onenote",sniff(n,r){if(k(n))return 2;if(r?.path!==void 0&&x.has(q(r.path)??""))return 1;return 0},convert(n,r){if(An(n,r?.path),F(n))throw d.encrypted();if(Z(n))return Bn(n,r);return{markdown:$(W(n))}}}}function An(n,r){if(A(n))throw d.unsupported("pdf");let o=Sn(n);if(o!==void 0&&o!=="one"&&!z(n))throw d.unsupported(o);if(B(n)&&!k(n)&&!_(r))throw d.unsupported(o??"ole");let u=Pn(n);if(u!==void 0)throw d.unsupported(u);if(Z(n))return;if(k(n)||_(r))return;throw d.unsupported("onenote")}function _(n){if(n===void 0)return!1;return x.has(q(n)??"")}function Bn(n,r){let o;try{o=Yn.open(n)}catch(m){throw Wn(m)}let u=En(o),p=u.length>0?u:On(o);if(r?.convert!==void 0&&u.length>0)return Dn(o,u,r.convert);return{markdown:$(jn(p))}}async function Dn(n,r,o){let u=[];for(let p of r){let m=Tn(p),f;try{f=n.part(p)}catch(v){if(v instanceof d&&v.isFatal())throw v;if(V(v))throw d.encrypted();u.push(c(m,Q(I(v))));continue}if(f===void 0){u.push(c(m,Q(`missing required part: ${p}`)));continue}try{let v=await o(f,{path:p});u.push(c(m,v.trimEnd()))}catch(v){if(v instanceof d&&v.isFatal())throw v;if(V(v))throw d.encrypted();u.push(c(m,Q(I(v))))}}return{markdown:Nn(u)}}function En(n){let r=[];for(let o of n.partNames()){if(!hn(o))continue;r.push(o)}return r}function On(n){let r=[];for(let o of n.partNames()){if(o.endsWith("/"))continue;if(a(o))continue;r.push(o)}return r}function hn(n){if(n.endsWith("/")||a(n))return!1;let r=q(n);return r==="one"||r==="onetoc2"}function a(n){for(let r of n.split("/"))if(r==="__MACOSX")return!0;return!1}function jn(n){if(n.length===0)return Ln();return{blocks:[{type:"list",list:{marker:"bullet",start:1,items:n.map((r)=>({blocks:[{type:"paragraph",inlines:[i(r)]}],checked:void 0,markerLabel:void 0}))}}],notes:[],assets:[]}}function Tn(n){return $({blocks:[Mn(2,[i(n)])],notes:[],assets:[]}).trimEnd()}function Q(n){return $({blocks:[{type:"paragraph",inlines:[i(`could not convert: ${n}`)]}],notes:[],assets:[]}).trimEnd()}function c(n,r){return r.length===0?n:`${n}
|
|
3
3
|
|
|
4
|
-
${r}`}function
|
|
4
|
+
${r}`}function Nn(n){let r=n.filter((o)=>o.length>0);return r.length===0?"":`${r.join(`
|
|
5
5
|
|
|
6
6
|
`)}
|
|
7
|
-
`}function
|
|
7
|
+
`}function I(n){return n instanceof Error?n.message:String(n)}function Wn(n){if(n instanceof d){if(n.code==="encrypted"||V(n))return d.encrypted();if(n.isFatal())return n;return d.unsupported("zip")}let r=n instanceof Error?n.message:String(n);if(l(r))return d.encrypted();return d.unsupported("zip")}function V(n){if(n instanceof d&&n.code==="encrypted")return!0;let r=n instanceof d?n.detail??"":"",o=n instanceof Error?`${n.message} ${r}`:String(n);return l(o)}function l(n){let r=n.toLowerCase();return r.includes("encrypted")||r.includes("password")}import{create as Fn}from"@mdgate/core";var Un=Fn([C()]);function Gn(n,r){return Un(n,r)}export{Gn as toMarkdown,C as onenote};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/onenote",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "mdgate OneNote converter (.one / .onetoc2 / .onepkg)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"prepublishOnly": "bun run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@mdgate/containers": "0.5.
|
|
26
|
-
"@mdgate/core": "0.5.
|
|
27
|
-
"@mdgate/document": "0.5.
|
|
28
|
-
"@mdgate/utils": "0.5.
|
|
25
|
+
"@mdgate/containers": "0.5.2",
|
|
26
|
+
"@mdgate/core": "0.5.2",
|
|
27
|
+
"@mdgate/document": "0.5.2",
|
|
28
|
+
"@mdgate/utils": "0.5.2"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|