mdast2docx 0.0.0 → 0.1.0
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/chunk-3ZZBJC3M.mjs +1 -0
- package/dist/chunk-7LR5HC5O.mjs +4 -0
- package/dist/chunk-7W4N3GRD.mjs +75 -0
- package/dist/{chunk-KPLOM3EF.mjs → chunk-GM6UUFDK.mjs} +2 -2
- package/dist/chunk-XIRSNIMN.mjs +1 -0
- package/dist/chunk-Z5DPYROV.mjs +31 -0
- package/dist/chunk-ZKNVKZAF.mjs +1 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/multipart-parser-WKN2UV32.mjs +2 -0
- package/dist/plugins/image.d.ts +19 -11
- package/dist/plugins/image.js +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/index.js +75 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/list.js +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/math.d.ts +6 -0
- package/dist/plugins/math.js +75 -1
- package/dist/plugins/math.mjs +1 -1
- package/dist/plugins/node-image.d.ts +27 -0
- package/dist/plugins/node-image.js +35 -0
- package/dist/plugins/node-image.mjs +1 -0
- package/dist/plugins/node.d.ts +1 -0
- package/dist/plugins/node.js +35 -0
- package/dist/plugins/node.mjs +1 -0
- package/dist/plugins/table.mjs +1 -1
- package/dist/section.js +1 -1
- package/dist/section.mjs +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +6 -2
- package/dist/chunk-RFHTB4AU.mjs +0 -1
- package/dist/chunk-XY2A2A66.mjs +0 -1
package/dist/section.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";var O=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var l in n)y(e,l,{get:n[l],enumerable:!0})},T=(e,n,l,P)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of N(n))!B.call(e,s)&&s!==l&&y(e,s,{get:()=>n[s],enumerable:!(P=M(n,s))||P.enumerable});return e};var E=(e,n,l)=>(l=e!=null?O(S(e)):{},T(n||!e||!e.__esModule?y(l,"default",{value:e,enumerable:!0}):l,e)),F=e=>T(y({},"__esModule",{value:!0}),e);var K={};v(K,{toSection:()=>j});module.exports=F(K);var k=require("@mayank1513/docx");var I=e=>{var n,l;return(n=e.children)!=null&&n.length?e.children.map(I).join(""):(l=e.value)!=null?l:""};var g={useTitle:!0,plugins:[]};var R=E(require("@mayank1513/docx")),H=(e,n,l)=>{let P=async(a,f)=>{var t,u,c;let r=Object.assign({},f),p=(await Promise.all(l.map(i=>{var h,x;return(x=(h=i.inline)==null?void 0:h.call(i,R,a,r,e,n,s))!=null?x:[]}))).flat(),d=(u=a.url)!=null?u:e[(t=a.identifier)==null?void 0:t.toUpperCase()];switch(a.type){case"text":return[...p,new k.TextRun({text:a.value,...r})];case"break":return[...p,new k.TextRun({break:1})];case"inlineCode":return[...p,new k.TextRun({text:a.value,...r,style:"code",font:{name:"Consolas"}})];case"emphasis":return r.italics=!0,[...p,...await s(a,r)];case"strong":return r.bold=!0,[...p,...await s(a,r)];case"delete":return r.strike=!0,[...p,...await s(a,r)];case"link":case"linkReference":return[...p,d.startsWith("#")?new k.InternalHyperlink({anchor:d.slice(1),children:await s(a,r)}):new k.ExternalHyperlink({link:d,children:await s(a,r)})];case"footnoteReference":return[...p,new k.FootnoteReferenceRun((c=n[a.identifier].id)!=null?c:0)];default:return[...p]}},s=async(a,f=new Set)=>{var r;return(await Promise.all((r=a.children)==null?void 0:r.map(p=>P(p,f)))).flat()};return s},j=async(e,n,l,P)=>{let{plugins:s,useTitle:a,...f}={...g,...P},r=H(n,l,s),p=async(t,u)=>{var h,x,b,C;let c=Object.assign({},u),i=(await Promise.all(s.map(m=>{var w,D;return(D=(w=m.block)==null?void 0:w.call(m,R,t,c,d,r))!=null?D:[]}))).flat();switch(t.type){case"paragraph":return[...i,new k.Paragraph({...u,children:await r(t)})];case"heading":return[new k.Paragraph({...i,heading:a?t.depth===1?"Title":`Heading${t.depth-1}`:`Heading${t.depth}`,children:[new k.Bookmark({id:I(t).replace(/[. ]+/g,"-").toLowerCase(),children:await r(t)})]})];case"code":return[...i,new k.Paragraph({alignment:"start",style:"blockCode",children:t.value.split(`
|
|
2
|
-
`).map(m=>new k.TextRun({text:m,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return t.ordered?(c.bullet={level:((x=(h=c.bullet)==null?void 0:h.level)!=null?x:-1)+1},console.warn("Please add numbering plugin to support ordered lists. For now, we use only bullets for both the ordered and the unordered list.")):c.bullet={level:((C=(b=c.bullet)==null?void 0:b.level)!=null?C:-1)+1},[...i,...await d(t,c)];case"blockquote":return[...i,...await d(t,c)];case"listItem":return[...i,...await d(t,c)];case"thematicBreak":return[...i,new k.Paragraph({border:{top:{style:k.BorderStyle.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return i;case"table":return console.warn("Please add table plugin to support tables."),i;case"":return i;case"yaml":case"html":default:return console.warn(`
|
|
2
|
+
`).map(m=>new k.TextRun({text:m,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return t.ordered?(c.bullet={level:((x=(h=c.bullet)==null?void 0:h.level)!=null?x:-1)+1},console.warn("Please add numbering plugin to support ordered lists. For now, we use only bullets for both the ordered and the unordered list.")):c.bullet={level:((C=(b=c.bullet)==null?void 0:b.level)!=null?C:-1)+1},[...i,...await d(t,c)];case"blockquote":return[...i,...await d(t,c)];case"listItem":return[...i,...await d(t,c)];case"thematicBreak":return[...i,new k.Paragraph({border:{top:{style:k.BorderStyle.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return i;case"table":return console.warn("Please add table plugin to support tables."),i;case"":return i;case"yaml":case"html":default:return console.warn(`May be an unsupported node type: ${t.type}`,t),i}},d=async(t,u)=>{var c;return(await Promise.all((c=t.children)==null?void 0:c.map(i=>p(i,u)))).flat()};return{...f,children:await d(e,{})}};0&&(module.exports={toSection});
|
package/dist/section.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-GM6UUFDK.mjs";import"./chunk-YKZOUIFR.mjs";import"./chunk-3ZZBJC3M.mjs";export{a as toSection};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalHyperlink, ImageRun, InternalHyperlink, IParagraphOptions, TextRun, Table, Paragraph, IRunOptions, IPropertiesOptions,
|
|
1
|
+
import { ExternalHyperlink, ImageRun, InternalHyperlink, IParagraphOptions, TextRun, Table, Paragraph, IRunOptions, IPropertiesOptions, Math as DOCXMath } from "@mayank1513/docx";
|
|
2
2
|
import * as DOCX from "@mayank1513/docx";
|
|
3
3
|
import { BlockContent, DefinitionContent, Parent, Root, RootContent } from "mdast";
|
|
4
4
|
export { convertInchesToTwip, convertMillimetersToTwip } from "@mayank1513/docx";
|
|
@@ -74,7 +74,7 @@ export type IDocxProps = Omit<Mutable<IPropertiesOptions>, "sections" | "footnot
|
|
|
74
74
|
*/
|
|
75
75
|
export type MutableRunOptions = Mutable<Omit<IRunOptions, "children">>;
|
|
76
76
|
export type InlineParentType = "strong" | "emphasis" | "delete" | "link";
|
|
77
|
-
export type InlineDocxNodes = TextRun | ImageRun | InternalHyperlink | ExternalHyperlink |
|
|
77
|
+
export type InlineDocxNodes = TextRun | ImageRun | InternalHyperlink | ExternalHyperlink | DOCXMath;
|
|
78
78
|
export type InlineProcessor = (node: ExtendedRootContent, runProps: MutableRunOptions) => Promise<InlineDocxNodes[]>;
|
|
79
79
|
export type InlineChildrenProcessor = (node: Parent, runProps?: MutableRunOptions) => Promise<InlineDocxNodes[]>;
|
|
80
80
|
/**
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},
|
|
1
|
+
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},x=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!d.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var u=t=>x(s({},"__esModule",{value:!0}),t);var y={};P(y,{convertInchesToTwip:()=>i.convertInchesToTwip,convertMillimetersToTwip:()=>i.convertMillimetersToTwip,defaultProps:()=>h,getDefinitions:()=>p,getTextContent:()=>a,uuid:()=>f});module.exports=u(y);var i=require("@mayank1513/docx"),p=t=>{let e={},n={};return t.forEach(o=>{var r;o.type==="definition"?e[o.identifier.toUpperCase()]=o.url:o.type==="footnoteDefinition"?n[o.identifier.toUpperCase()]={children:o.children}:(r=o.children)!=null&&r.length&&Object.assign(e,p(o.children))}),{definitions:e,footnoteDefinitions:n}},a=t=>{var e,n;return(e=t.children)!=null&&e.length?t.children.map(a).join(""):(n=t.value)!=null?n:""},f=()=>Math.random().toString(16).slice(2),h={useTitle:!0,plugins:[]};0&&(module.exports={convertInchesToTwip,convertMillimetersToTwip,defaultProps,getDefinitions,getTextContent,uuid});
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f}from"./chunk-YKZOUIFR.mjs";export{e as convertInchesToTwip,f as convertMillimetersToTwip,d as defaultProps,a as getDefinitions,b as getTextContent,c as uuid};
|
|
1
|
+
import{a,b,c,d,e,f}from"./chunk-YKZOUIFR.mjs";import"./chunk-3ZZBJC3M.mjs";export{e as convertInchesToTwip,f as convertMillimetersToTwip,d as defaultProps,a as getDefinitions,b as getTextContent,c as uuid};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mdast2docx",
|
|
3
3
|
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.1.0",
|
|
6
6
|
"description": "Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.",
|
|
7
7
|
"license": "MPL-2.0",
|
|
8
8
|
"main": "./dist/index.js",
|
|
@@ -30,18 +30,22 @@
|
|
|
30
30
|
"@testing-library/react": "^16.2.0",
|
|
31
31
|
"@types/mdast": "^4.0.4",
|
|
32
32
|
"@types/node": "^22.13.10",
|
|
33
|
+
"@unified-latex/unified-latex-types": "^1.8.0",
|
|
34
|
+
"@unified-latex/unified-latex-util-parse": "^1.8.2",
|
|
33
35
|
"@vitest/coverage-v8": "^3.0.8",
|
|
34
36
|
"esbuild-plugin-rdi": "^0.0.0",
|
|
35
37
|
"jsdom": "^26.0.0",
|
|
38
|
+
"node-fetch": "^3.3.2",
|
|
36
39
|
"remark-gfm": "^4.0.1",
|
|
37
40
|
"remark-parse": "^11.0.0",
|
|
41
|
+
"sharp": "0.33.5",
|
|
38
42
|
"tsup": "^8.4.0",
|
|
39
43
|
"typescript": "^5.8.2",
|
|
40
44
|
"unified": "^11.0.5",
|
|
41
45
|
"vite-tsconfig-paths": "^5.1.4",
|
|
42
46
|
"vitest": "^3.0.8"
|
|
43
47
|
},
|
|
44
|
-
"
|
|
48
|
+
"peerDependencies": {
|
|
45
49
|
"@mayank1513/docx": "^9.2.0"
|
|
46
50
|
},
|
|
47
51
|
"funding": [
|
package/dist/chunk-RFHTB4AU.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var r=()=>({inline:async(t,n)=>{var e;return n.type!=="inlineMath"?[]:(console.log("inline math",n.value),[new t.MathRun((e=n.value)!=null?e:"")])},block:async(t,n,e)=>{var a;return n.type!=="math"?[]:[new t.Paragraph({...e,children:[new t.MathRun((a=n.value)!=null?a:"")]})]}});export{r as a};
|
package/dist/chunk-XY2A2A66.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=a=>{let e=new Uint8Array(a).slice(0,4);if(e[0]===66&&e[1]===77)return"bmp";switch(e.reduce((r,n)=>r+n.toString(16).padStart(2,"0"),"")){case"89504E47":return"png";case"47494638":return"gif";case"FFD8FFE0":case"FFD8FFE1":case"FFD8FFE2":case"FFD8FFE3":case"FFD8FFE8":return"jpg"}},p=3,u=async(a,e)=>{let t=document.createElement("canvas"),r=t.getContext("2d");if(!r)throw new Error("Canvas context not available");let n=new Image;n.src=a,await new Promise(o=>n.onload=o);let i=n.width*e,s=n.height*e;return t.width=i,t.height=s,r.drawImage(n,0,0,i,s),{data:t.toDataURL("image/png"),type:"png",transformation:{width:i/e,height:s/e}}},h=async a=>{let t=await(await fetch(a)).arrayBuffer(),r=c(t)||"png",n=await createImageBitmap(new Blob([t],{type:r}));return{type:r,data:t,transformation:{width:n.width,height:n.height}}},l=async(a,e)=>{var t;try{return a.startsWith("data:")?await u(a,(t=e==null?void 0:e.scale)!=null?t:p):await h(a)}catch(r){return console.error(`Error resolving image: ${a}`,r),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},I=a=>({inline:async(e,t,r,n)=>{var i,s,o;if(/^image/.test(t.type)){let g=(s=t.url)!=null?s:n[(i=t.identifier)==null?void 0:i.toUpperCase()],m=(o=t.alt)!=null?o:g==null?void 0:g.split("/").pop();return t.type="",[new e.ImageRun({...await l(g,a),altText:{description:m,name:m,title:m}})]}return[]}});export{c as a,I as b};
|