@mdgate/text 0.6.11 → 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.
- package/dist/index.js +4 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{ConvertError as
|
|
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
|
|
4
|
-
`)?
|
|
5
|
-
`};if(
|
|
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.
|
|
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.
|
|
32
|
-
"@mdgate/document": "0.6.
|
|
33
|
-
"@mdgate/utils": "0.6.
|
|
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"
|