@mdgate/text 0.6.10 → 0.6.12

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.
Files changed (2) hide show
  1. package/dist/index.js +4 -4
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import{ConvertError as Q}from"@mdgate/core";import{documentToMarkdown as L}from"@mdgate/document";import{fileExtension as I}from"@mdgate/utils";import{emptyDocument as $,plain as P}from"@mdgate/document";import{trim as k}from"@mdgate/utils";var N="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";function z(q){return C(O(q))}function j(q){let G=$(),H=q.replace(/\r\n/g,`
1
+ import{ConvertError as j}from"@mdgate/core";import{documentToMarkdown as R}from"@mdgate/document";import{fileExtension as I}from"@mdgate/utils";import{emptyDocument as G,plain as U}from"@mdgate/document";import{trim as D}from"@mdgate/utils";var W="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";function L(H){return S(f(H))}function z(H){let Q=G(),J=H.replace(/\r\n/g,`
2
2
  `).replace(/\r/g,`
3
- `);for(let J of H.split(/\n(?:[ \t]*\n)+/)){let Z=k(J);if(Z.length===0)continue;G.blocks.push({type:"paragraph",inlines:[P(Z)]})}return G}function K(q,G){let H=$();return H.blocks.push({type:"codeBlock",lang:G,text:q}),H}function O(q){if(q.length>=2&&q[0]===255&&q[1]===254)return new TextDecoder("utf-16le").decode(q);if(q.length>=2&&q[0]===254&&q[1]===255)return new TextDecoder("utf-16be").decode(q);let G=q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191?q.subarray(3):q;try{return new TextDecoder("utf-8",{fatal:!0}).decode(G)}catch{return w(G)}}function w(q){let G="";for(let H=0;H<q.length;H+=1){let J=q[H];if(J<128||J>=160)G+=String.fromCharCode(J);else G+=N[J-128]}return G}function C(q){return q.charCodeAt(0)===65279?q.slice(1):q}var A=new Set(["txt","text"]),B=new Set(["md","markdown","mdx"]),D=new Set(["js","jsx","ts","tsx","py","rb","go","rs","java","kt","c","h","cc","cpp","cs","swift","sh","bash","zsh","sql","css","scss","less","graphql"]),R=new Set([...A,...B,...D]);function Y(){return{id:"text",sniff(q,G){let H=G?.path!==void 0?I(G.path):void 0;if(H==="txt"&&M(q)&&X(q.subarray(3)))return 2;if(H!==void 0&&R.has(H))return 1;return 0},convert(q,G){F(q);let H=G?.path!==void 0?I(G.path):void 0;if(H===void 0||!R.has(H))throw Q.unsupported(H??"text");let J=z(q);if(B.has(H))return{markdown:J.endsWith(`
4
- `)?J:`${J}
5
- `};if(A.has(H))return{markdown:L(j(J))};return{markdown:L(K(J,H))}}}}function F(q){let G=q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191?q.subarray(3):q;if(V(G,[37,80,68,70,45]))throw Q.unsupported("pdf");if(V(G,[208,207,17,224,161,177,26,225]))throw Q.unsupported("ole");if(V(G,[80,75,3,4]))throw Q.unsupported("zip")}function M(q){return q.length>=3&&q[0]===239&&q[1]===187&&q[2]===191}function X(q){try{let G=new TextDecoder("utf-8",{fatal:!0}).decode(q);for(let H=0;H<G.length;H+=1){let J=G.charCodeAt(H);if(J===9||J===10||J===13)continue;if(J<32||J===127)return!1}return!0}catch{return!1}}function V(q,G){if(q.length<G.length)return!1;for(let H=0;H<G.length;H+=1)if(q[H]!==G[H])return!1;return!0}import{create as f}from"@mdgate/core";var U=f([Y()]);function W(q,G){return U(q,G)}export{W as toMarkdown,Y as text};
3
+ `);for(let V of J.split(/\n(?:[ \t]*\n)+/)){let q=D(V);if(q.length===0)continue;Q.blocks.push({type:"paragraph",inlines:[U(q)]})}return Q}function K(H,Q){let J=G();return J.blocks.push({type:"codeBlock",lang:Q,text:H}),J}function f(H){if(H.length>=2&&H[0]===255&&H[1]===254)return new TextDecoder("utf-16le").decode(H);if(H.length>=2&&H[0]===254&&H[1]===255)return new TextDecoder("utf-16be").decode(H);let Q=H.length>=3&&H[0]===239&&H[1]===187&&H[2]===191?H.subarray(3):H;try{return new TextDecoder("utf-8",{fatal:!0}).decode(Q)}catch{return v(Q)}}function v(H){let Q="";for(let J=0;J<H.length;J+=1){let V=H[J];if(V<128||V>=160)Q+=String.fromCharCode(V);else Q+=W[V-128]}return Q}function S(H){return H.charCodeAt(0)===65279?H.slice(1):H}var F=new Set(["txt","text"]),M=new Set(["md","markdown","mdx"]),E=new Set(["js","jsx","ts","tsx","py","rb","go","rs","java","kt","c","h","cc","cpp","cs","swift","sh","bash","zsh","sql","css","scss","less","graphql","gv"]),O=new Set([...F,...M,...E]);function B(){return{id:"text",sniff(H,Q){let J=Q?.path!==void 0?I(Q.path):void 0;if(P(J)&&C(l(H)))return 2;if(J==="txt"&&u(H)&&k(H.subarray(3)))return 2;if(J!==void 0&&O.has(J))return 1;return 0},convert(H,Q){T(H);let J=Q?.path!==void 0?I(Q.path):void 0,V=L(H);if(J!==void 0&&M.has(J))return{markdown:V.endsWith(`
4
+ `)?V:`${V}
5
+ `};if(P(J)&&C(V))return{markdown:R(K(V,"dot"))};if(J===void 0||!O.has(J))throw j.unsupported(J??"text");if(F.has(J))return{markdown:R(z(V))};return{markdown:R(K(V,J))}}}}function T(H){let Q=H.length>=3&&H[0]===239&&H[1]===187&&H[2]===191?H.subarray(3):H;if(A(Q,[37,80,68,70,45]))throw j.unsupported("pdf");if(A(Q,[208,207,17,224,161,177,26,225]))throw j.unsupported("ole");if(A(Q,[80,75,3,4]))throw j.unsupported("zip")}function u(H){return H.length>=3&&H[0]===239&&H[1]===187&&H[2]===191}function k(H){try{let Q=new TextDecoder("utf-8",{fatal:!0}).decode(H);for(let J=0;J<Q.length;J+=1){let V=Q.charCodeAt(J);if(V===9||V===10||V===13)continue;if(V<32||V===127)return!1}return!0}catch{return!1}}function A(H,Q){if(H.length<Q.length)return!1;for(let J=0;J<Q.length;J+=1)if(H[J]!==Q[J])return!1;return!0}function P(H){return H===void 0||H==="dot"||H==="gv"}function l(H){let Q=new TextDecoder("utf-8").decode(H.subarray(0,8192));return Q.charCodeAt(0)===65279?Q.slice(1):Q}function C(H){let Q=Math.min(H.length,8192),J=0,V=()=>{while(J<Q){let Y=H.charCodeAt(J);if(Y===32||Y===9||Y===10||Y===13){J+=1;continue}if(Y===47&&J+1<Q){let Z=H.charCodeAt(J+1);if(Z===47){J+=2;while(J<Q&&H.charCodeAt(J)!==10)J+=1;continue}if(Z===42){J+=2;while(J+1<Q&&!(H.charCodeAt(J)===42&&H.charCodeAt(J+1)===47))J+=1;J=J+1<Q?J+2:Q;continue}}break}},q=(Y)=>{if(J+Y.length>Q)return!1;if(H.slice(J,J+Y.length).toLowerCase()!==Y)return!1;let Z=J+Y.length;if(Z<Q){let $=H.charCodeAt(Z);if($>=65&&$<=90||$>=97&&$<=122||$>=48&&$<=57||$===95)return!1}return J+=Y.length,!0};if(V(),q("strict"))V();if(!q("digraph")&&!q("graph"))return!1;if(V(),J>=Q)return!1;if(H[J]==="{")return!0;if(H[J]==='"'){J+=1;while(J<Q){if(H[J]==="\\"){J+=2;continue}if(H[J]==='"'){J+=1;break}J+=1}return V(),H[J]==="{"}if(H[J]==="<"){J+=1;let Y=1;while(J<Q&&Y>0){if(H[J]==="<")Y+=1;else if(H[J]===">")Y-=1;J+=1}return V(),H[J]==="{"}if(!N())return!1;return V(),H[J]==="{";function N(){if(J>=Q)return!1;let Y=H.charCodeAt(J);if(Y===45||Y>=48&&Y<=57||Y===46&&_()){if(Y===45)J+=1;let Z=!1;if(J<Q&&H.charCodeAt(J)===46)J+=1;while(J<Q&&H.charCodeAt(J)>=48&&H.charCodeAt(J)<=57)Z=!0,J+=1;if(J<Q&&H.charCodeAt(J)===46){J+=1;while(J<Q&&H.charCodeAt(J)>=48&&H.charCodeAt(J)<=57)Z=!0,J+=1}return Z}if(!X(Y))return!1;J+=1;while(J<Q&&w(H.charCodeAt(J)))J+=1;return!0}function _(){return J+1<Q&&H.charCodeAt(J+1)>=48&&H.charCodeAt(J+1)<=57}}function X(H){return H>=65&&H<=90||H>=97&&H<=122||H===95||H>=128}function w(H){return X(H)||H>=48&&H<=57}import{create as g}from"@mdgate/core";var p=g([B()]);function h(H,Q){return p(H,Q)}export{h as toMarkdown,B as text};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/text",
3
- "version": "0.6.10",
3
+ "version": "0.6.12",
4
4
  "description": "mdgate plain text, markdown, and source converter",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,9 +28,9 @@
28
28
  "prepublishOnly": "bun run build"
29
29
  },
30
30
  "dependencies": {
31
- "@mdgate/core": "0.6.10",
32
- "@mdgate/document": "0.6.10",
33
- "@mdgate/utils": "0.6.10"
31
+ "@mdgate/core": "0.6.12",
32
+ "@mdgate/document": "0.6.12",
33
+ "@mdgate/utils": "0.6.12"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"