{"_id":"@bcibibi/docx-html-converter","_rev":"2-64f8330f12e9a87837934881846da0d7","name":"@bcibibi/docx-html-converter","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@bcibibi/docx-html-converter","version":"1.0.0","keywords":["docx","html","converter","convert"],"author":{"name":"bcibi"},"license":"MIT","_id":"@bcibibi/docx-html-converter@1.0.0","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"homepage":"https://github.com/bcibibi/docx-html-converter#readme","bugs":{"url":"https://github.com/bcibibi/docx-html-converter/issues"},"dist":{"shasum":"a34812133bb7737afd51a1e4dca6dcb04caa50b8","tarball":"https://registry.npmjs.org/@bcibibi/docx-html-converter/-/docx-html-converter-1.0.0.tgz","fileCount":125,"integrity":"sha512-HxMcOiIxVV5H+uBEq/QwUbv5rbZeGw1uWoY6mui7QN+V3BZ9V6iaNhMN/O/TNiSJUgcisLtElhEmtzFmbaVVog==","signatures":[{"sig":"MEQCIEk43ZLJEeLPn5CrF08xD5kB/gNXlthy2/qxjcauSSKRAiBA7KUZOlMY3LMOEIpGqFNG8abyMQH8ESyx3vqY5L9A6w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":107199},"main":"./dist/cjs/index.js","type":"module","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","exports":{".":{"types":"./dist/esm/index.d.ts","import":"./dist/esm/index.js","default":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"gitHead":"6a5fde1abcc53284f8fba268d162bbfbffee2aff","scripts":{"test":"NODE_OPTIONS=--experimental-vm-modules npx jest","build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:cjs":"tsc -p tsconfig.cjs.json","build:esm":"tsc -p tsconfig.esm.json","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\""},"_npmUser":{"name":"bcibi","email":"benoit.cibillon@gmail.com"},"repository":{"url":"git+https://github.com/bcibibi/docx-html-converter.git","type":"git"},"_npmVersion":"11.6.2","description":"convert html to docx","directories":{},"_nodeVersion":"24.11.1","dependencies":{"debug":"^4.4.3","dom-parser":"^1.1.5","color-convert":"^3.1.3","css-unit-converter":"^1.1.2","@csstools/css-tokenizer":"^4.0.0","@csstools/css-color-parser":"^4.1.1","@csstools/css-parser-algorithms":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.4.2","open":"^11.0.0","ts-jest":"^29.4.11","typescript":"^6.0.3","@types/jest":"^30.0.0","@types/node":"^25.9.1","@types/debug":"^4.1.13"},"peerDependencies":{"docx":"^9.6.1"},"_npmOperationalInternal":{"tmp":"tmp/docx-html-converter_1.0.0_1784573041005_0.7398887123143374","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@bcibibi/docx-html-converter","version":"1.0.1","description":"convert html to docx","keywords":["docx","html","converter","convert"],"homepage":"https://github.com/bcibibi/docx-html-converter#readme","bugs":{"url":"https://github.com/bcibibi/docx-html-converter/issues"},"repository":{"type":"git","url":"git+https://github.com/bcibibi/docx-html-converter.git"},"license":"MIT","author":{"name":"bcibi"},"type":"module","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","exports":{".":{"types":"./dist/esm/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js","default":"./dist/esm/index.js"}},"scripts":{"clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:esm":"tsc -p tsconfig.esm.json","build:cjs":"tsc -p tsconfig.cjs.json","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\"","build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","test":"NODE_OPTIONS=--experimental-vm-modules npx jest"},"devDependencies":{"@types/debug":"^4.1.13","@types/jest":"^30.0.0","@types/node":"^26.1.1","jest":"^30.4.2","open":"^11.0.0","ts-jest":"^29.4.11","typescript":"^6.0.3"},"peerDependencies":{"docx":"^9.6.1"},"dependencies":{"@csstools/css-color-parser":"^4.1.1","@csstools/css-parser-algorithms":"^4.0.0","@csstools/css-tokenizer":"^4.0.0","color-convert":"^3.1.3","css-unit-converter":"^1.1.2","debug":"^4.4.3","dom-parser":"^1.1.5"},"gitHead":"6a646f99f6efd9b7f616808abbf66d336fdf3b82","_id":"@bcibibi/docx-html-converter@1.0.1","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-EY9+PxzbQv6eqi65R10vn99zoh70l4GDWz7lEM98SE6kg3H4dem0mtGRNADE2xBlxm6g2IXzdrGK0eErS7EQgw==","shasum":"f1223ccfeeba44251435cbe9efcc1a1416c0df9f","tarball":"https://registry.npmjs.org/@bcibibi/docx-html-converter/-/docx-html-converter-1.0.1.tgz","fileCount":143,"unpackedSize":118735,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@bcibibi%2fdocx-html-converter@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCuwyQYf9IE1MTaZmajF3z1RhjI/sttm7BwtDzYAqcLoQIgfeMDZYDf1x4z2fFjeeEvr38lCxuLa1spczaXzcYj4Po="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3cfe2952-3f0b-4324-bf53-b199aa566f39"}},"directories":{},"maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/docx-html-converter_1.0.1_1785141664905_0.9287588764677417"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-20T18:44:00.829Z","modified":"2026-07-27T08:41:05.405Z","1.0.0":"2026-07-20T18:44:01.212Z","1.0.1":"2026-07-27T08:41:05.048Z"},"bugs":{"url":"https://github.com/bcibibi/docx-html-converter/issues"},"author":{"name":"bcibi"},"license":"MIT","homepage":"https://github.com/bcibibi/docx-html-converter#readme","keywords":["docx","html","converter","convert"],"repository":{"type":"git","url":"git+https://github.com/bcibibi/docx-html-converter.git"},"description":"convert html to docx","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"readme":"# @bcibibi/docx-html-converter\n\nConvert a subset of HTML into `docx` components (`FileChild[]`) so you can build Word documents with the [`docx`](https://www.npmjs.com/package/docx) library.\n\n## Features\n\n- Converts HTML to `docx` document children.\n- Supports common inline formatting (`bold`, `italic`, `underline`, `strike`, `sub`, `sup`).\n- Supports paragraphs and nested lists (`ul` / `ol` / `li`).\n- Supports inline image conversion from local files or HTTP(S) sources.\n- Supports inline CSS parsing for selected text styles.\n- Works in ESM and CommonJS builds.\n\n## Installation\n\n```bash\nnpm install @bcibibi/docx-html-converter docx\n```\n\n`docx` is a peer dependency and must be installed in your project.\n\n## Quick Start\n\n```ts\nimport { Document, Packer } from \"docx\";\nimport { writeFileSync } from \"node:fs\";\nimport { DocxHtmlConverter } from \"@bcibibi/docx-html-converter\";\n\nconst html = `\n\t<p>Hello <strong>World</strong></p>\n\t<ul>\n\t\t<li>First item</li>\n\t\t<li>Second item</li>\n\t</ul>\n`;\n\nconst children = await DocxHtmlConverter.convert(html);\n\nconst doc = new Document({\n\tsections: [{ children }],\n});\n\nconst buffer = await Packer.toBuffer(doc);\nwriteFileSync(\"output.docx\", buffer);\n```\n\n## Ordered Lists (`ol`)\n\nTo render ordered lists correctly, pass a numbering reference and define the corresponding numbering config in your `Document`.\n\n```ts\nimport { Document, Packer, convertInchesToTwip } from \"docx\";\nimport { DocxHtmlConverter } from \"@bcibibi/docx-html-converter\";\n\nconst numberingRef = \"my-numbering\";\nconst html = \"<ol><li>One</li><li>Two</li></ol>\";\n\nconst children = await DocxHtmlConverter.convert(html, { numbering: numberingRef });\n\nconst doc = new Document({\n\tsections: [{ children }],\n\tnumbering: {\n\t\tconfig: [\n\t\t\t{\n\t\t\t\treference: numberingRef,\n\t\t\t\tlevels: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlevel: 0,\n\t\t\t\t\t\tformat: \"decimal\",\n\t\t\t\t\t\ttext: \"%1.\",\n\t\t\t\t\t\talignment: \"left\",\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tparagraph: {\n\t\t\t\t\t\t\t\tindent: {\n\t\t\t\t\t\t\t\t\tleft: convertInchesToTwip(0.5),\n\t\t\t\t\t\t\t\t\thanging: convertInchesToTwip(0.25),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n});\n\nconst buffer = await Packer.toBuffer(doc);\n```\n\n## Images\n\n`<img>` tags are supported.\n\n- `src` can be a local path or an `http://` / `https://` URL.\n- `width` and `height` attributes are used for image size. Default is `100x100` when missing.\n- `style=\"float:left\"` and `style=\"float:right\"` are supported.\n- If an image cannot be loaded, a fallback text run is inserted: `[Image not found: ...]`.\n\nSupported image types (detected from file content):\n\n- `jpg`\n- `png`\n- `gif`\n- `bmp`\n\n## Supported HTML Tags\n\n- `#text`\n- `p`\n- `span`\n- `ul`\n- `ol`\n- `li`\n- `b`, `strong`\n- `i`, `em`\n- `u`\n- `strike`\n- `sub`\n- `sup`\n- `img`\n\n## Supported Inline CSS\n\nThe converter parses inline `style` attributes and maps these properties:\n\n- `font-weight: bold`\n- `font-style: italic`\n- `text-decoration: underline | line-through`\n- `vertical-align: sub | super`\n- `font-size` (unit conversion to half-points used by `docx`)\n- `color` (parsed and converted to hex)\n- `float: left | right` (for `img`)\n\n## API\n\n### `DocxHtmlConverter.convert(html, options?)`\n\nConverts HTML to an array of `FileChild` values.\n\n```ts\nimport type { FileChild, IRunOptions } from \"docx\";\n\ntype DocxHtmlConverterOptions = {\n\tnumbering?: string;\n\toptions?: IRunOptions;\n\tfileReader?: (src: string) => Promise<Buffer>;\n\t/** @deprecated Use fileReader */\n\tfileProvider?: new (src: string) => {\n\t\tgetFileContent(): Promise<Buffer>;\n\t};\n};\n\nfunction convert(\n\thtml: string,\n\toptions?: DocxHtmlConverterOptions\n): Promise<FileChild[]>;\n```\n\n### `options` option\n\n`options` lets you provide base `IRunOptions` that are applied before inline HTML/CSS styles are merged.\n\n```ts\nconst children = await DocxHtmlConverter.convert(\"<p>Hello</p>\", {\n\toptions: { italics: true },\n});\n```\n\n### `fileReader` option (recommended)\n\nUse `fileReader` to customize image loading behavior (auth, signed URLs, S3, CDN, in-memory assets, etc.).\n\n```ts\nimport { DocxHtmlConverter } from \"@bcibibi/docx-html-converter\";\n\nconst fileReader = async (src: string): Promise<Buffer> => {\n\tif (src.startsWith(\"my://\")) {\n\t\treturn Buffer.from([]);\n\t}\n\tthrow new Error(`Unsupported source: ${src}`);\n};\n\nconst children = await DocxHtmlConverter.convert(\"<img src='my://asset/logo' />\", {\n\tfileReader,\n});\n```\n\n### `fileProvider` option (deprecated)\n\n`fileProvider` is still available for backward compatibility but is deprecated and will be removed in a future version.\n\n```ts\nimport {\n\tDocxHtmlConverter,\n\tDocxHtmlFileProvider,\n} from \"@bcibibi/docx-html-converter\";\n\nclass MyFileProvider extends DocxHtmlFileProvider {\n\tasync getFileContent(): Promise<Buffer> {\n\t\treturn Buffer.from([]);\n\t}\n}\n\nconst children = await DocxHtmlConverter.convert(\"<img src='my://asset/logo' />\", {\n\tfileProvider: MyFileProvider,\n});\n```\n\n## Development\n\nInstall dependencies:\n\n```bash\nnpm ci\n```\n\nBuild the package:\n\n```bash\nnpm run build\n```\n\nRun tests:\n\n```bash\nnpm test\n```\n\nVerify both module outputs:\n\n```bash\nnpm run verify:modules\n```\n\n## License\n\nMIT","readmeFilename":"README.md"}