{"_id":"@aidalinfo/office-to-markdown","_rev":"3-89b3a4f347dd1b2219146860f64f5f07","name":"@aidalinfo/office-to-markdown","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@aidalinfo/office-to-markdown","version":"1.0.0","keywords":["office","docx","markdown","document-conversion","office-to-markdown","docx-to-markdown","mammoth","turndown","typescript","bun","math-equations","omml","latex","table-conversion","document-processing"],"author":{"name":"aidalinfo","email":"contact@aidalinfo.com"},"license":"ISC","_id":"@aidalinfo/office-to-markdown@1.0.0","maintainers":[{"name":"aidalinfo","email":"dev@aidalinfo.fr"}],"homepage":"https://github.com/aidalinfo/extract-kit#readme","bugs":{"url":"https://github.com/aidalinfo/extract-kit/issues"},"dist":{"shasum":"05f101b869e42479aaaefa4471e3bc2f14f3f88b","tarball":"https://registry.npmjs.org/@aidalinfo/office-to-markdown/-/office-to-markdown-1.0.0.tgz","fileCount":28,"integrity":"sha512-/XnGskxEj7ehtyrcZl6m6nQwzihWVcpRDc+dqP8RC9dGKKp9+CecKEy5mm+DyewOenDGrRtZY3hEYLRB0g3s6g==","signatures":[{"sig":"MEYCIQDr1eNvd5kuMjDnqjd8Gb7+evZwNm/+lxEDP+PkFajVAwIhAOpk6heak5S+9L2eaPV1cYhAKLC4I/qqyY65wAixDJS2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":103826},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.js","engines":{"bun":">=1.2.0","node":">=20.0.0"},"gitHead":"9ac6deb35cc87018ad2966347f6019ba97868b79","private":false,"scripts":{"dev":"bun run --watch src/index.ts","test":"bun test","build":"bun run clean && bun run build:esm && bun run build:types","clean":"rm -rf dist","start":"bun run src/index.ts","build:esm":"bun build src/index.ts --outdir dist --format esm --target node --external mammoth --external turndown --external jszip","build:types":"tsc --project tsconfig.build.json","prepublishOnly":"bun run build"},"_npmUser":{"name":"aidalinfo","email":"dev@aidalinfo.fr"},"repository":{"url":"git+https://github.com/aidalinfo/extract-kit.git","type":"git","directory":"packages/office-to-markdown"},"_npmVersion":"10.9.2","description":"Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.","directories":{},"_nodeVersion":"22.17.1","dependencies":{"jszip":"^3.10.1","mammoth":"^1.10.0","turndown":"^7.2.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"bun":"^1.2.19","bun-types":"latest","@types/bun":"latest","typescript":"^5.4.2","@types/node":"^24.2.1","@types/turndown":"^5.0.5"},"peerDependencies":{"typescript":">=4.5.0"},"_npmOperationalInternal":{"tmp":"tmp/office-to-markdown_1.0.0_1754918466349_0.7936314443566461","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@aidalinfo/office-to-markdown","version":"1.0.1","keywords":["office","docx","markdown","document-conversion","office-to-markdown","docx-to-markdown","mammoth","turndown","typescript","bun","math-equations","omml","latex","table-conversion","document-processing"],"author":{"name":"aidalinfo","email":"contact@aidalinfo.com"},"license":"MIT","_id":"@aidalinfo/office-to-markdown@1.0.1","maintainers":[{"name":"aidalinfo","email":"dev@aidalinfo.fr"}],"homepage":"https://github.com/aidalinfo/extract-kit#readme","bugs":{"url":"https://github.com/aidalinfo/extract-kit/issues"},"dist":{"shasum":"8222ebe0d719f4e96786d09995446dcb7e526706","tarball":"https://registry.npmjs.org/@aidalinfo/office-to-markdown/-/office-to-markdown-1.0.1.tgz","fileCount":27,"integrity":"sha512-+i6uxicGgYp87ybb+qQ/cl6W9ovO6REYGjVXjpxGwLSNAY1Se9CLJPqWxZlyR9hALtKeKwbF47UxKhq37gIv6w==","signatures":[{"sig":"MEUCIQC/7pwwsyDzdyi/pdtJwjtkU8pDWepOdqC+7HriPfh5fQIgMTEDFNJ6GKW+zao5kDMutGtUbnByrA1Nwoe/1KVHuNk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":100630},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.js","engines":{"bun":">=1.2.0","node":">=20.0.0"},"gitHead":"4caac5b11776f88056a899e4349c24606f0594b7","private":false,"scripts":{"dev":"bun run --watch src/index.ts","test":"bun test","build":"bun run clean && bun run build:esm && bun run build:types","clean":"rm -rf dist","start":"bun run src/index.ts","build:esm":"bun build src/index.ts --outdir dist --format esm --target node --external mammoth --external turndown --external jszip","build:types":"tsc --project tsconfig.build.json","prepublishOnly":"bun run build"},"_npmUser":{"name":"aidalinfo","email":"dev@aidalinfo.fr"},"repository":{"url":"git+https://github.com/aidalinfo/extract-kit.git","type":"git","directory":"packages/office-to-markdown"},"_npmVersion":"10.9.2","description":"Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.","directories":{},"_nodeVersion":"22.17.1","dependencies":{"jszip":"^3.10.1","mammoth":"^1.10.0","turndown":"^7.2.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"bun":"^1.2.19","bun-types":"latest","@types/bun":"latest","typescript":"^5.4.2","@types/node":"^24.2.1","@types/turndown":"^5.0.5"},"peerDependencies":{"typescript":">=4.5.0"},"_npmOperationalInternal":{"tmp":"tmp/office-to-markdown_1.0.1_1754921494552_0.9226575000077928","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@aidalinfo/office-to-markdown","version":"1.0.2","description":"Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.","main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","type":"module","private":false,"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"scripts":{"dev":"bun run --watch src/index.ts","start":"bun run src/index.ts","build":"bun run clean && bun run build:esm && bun run build:types","build:esm":"bun build src/index.ts --outdir dist --format esm --target node --external mammoth --external turndown --external jszip","build:types":"tsc --project tsconfig.build.json","test":"bun test","prepublishOnly":"bun run build","clean":"rm -rf dist"},"keywords":["office","docx","markdown","document-conversion","office-to-markdown","docx-to-markdown","mammoth","turndown","typescript","bun","math-equations","omml","latex","table-conversion","document-processing"],"author":{"name":"aidalinfo","email":"contact@aidalinfo.com"},"license":"MIT","homepage":"https://github.com/aidalinfo/extract-kit#readme","repository":{"type":"git","url":"git+https://github.com/aidalinfo/extract-kit.git","directory":"packages/office-to-markdown"},"bugs":{"url":"https://github.com/aidalinfo/extract-kit/issues"},"engines":{"node":">=20.0.0","bun":">=1.2.0"},"dependencies":{"jszip":"^3.10.1","mammoth":"^1.10.0","turndown":"^7.2.0"},"devDependencies":{"@types/bun":"latest","@types/node":"^24.2.1","@types/turndown":"^5.0.5","bun":"^1.2.19","bun-types":"latest","typescript":"^5.4.2"},"peerDependencies":{"typescript":">=4.5.0"},"_id":"@aidalinfo/office-to-markdown@1.0.2","gitHead":"a1f624a7ea859b3960fe1b04fae07e96060f763b","_nodeVersion":"22.17.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-bT0t8jmSdI5B2Hcx9KD6gnuQG1n/1xDsvTtTm7FTlEcRU9SdqNeFXCpZY8zgzAQi3KSGv/qgdHJ3DH1L3xAR7g==","shasum":"a5dff8d6b9224a1676d0414957e912341668c83c","tarball":"https://registry.npmjs.org/@aidalinfo/office-to-markdown/-/office-to-markdown-1.0.2.tgz","fileCount":27,"unpackedSize":100837,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCPF11I56sXh0qrZ8RSaGLERZf0XPTCyok07YCx95gz3wIhANe11fiRUmUwLMm+1dGIpwzzENgmDOf35mC+Ku4luoJ8"}]},"_npmUser":{"name":"aidalinfo","email":"dev@aidalinfo.fr"},"directories":{},"maintainers":[{"name":"aidalinfo","email":"dev@aidalinfo.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/office-to-markdown_1.0.2_1756306842261_0.9960577224966884"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-11T13:21:06.250Z","modified":"2025-08-27T15:00:42.620Z","1.0.0":"2025-08-11T13:21:06.598Z","1.0.1":"2025-08-11T14:11:34.721Z","1.0.2":"2025-08-27T15:00:42.437Z"},"bugs":{"url":"https://github.com/aidalinfo/extract-kit/issues"},"author":{"name":"aidalinfo","email":"contact@aidalinfo.com"},"license":"MIT","homepage":"https://github.com/aidalinfo/extract-kit#readme","keywords":["office","docx","markdown","document-conversion","office-to-markdown","docx-to-markdown","mammoth","turndown","typescript","bun","math-equations","omml","latex","table-conversion","document-processing"],"repository":{"type":"git","url":"git+https://github.com/aidalinfo/extract-kit.git","directory":"packages/office-to-markdown"},"description":"Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.","maintainers":[{"name":"aidalinfo","email":"dev@aidalinfo.fr"}],"readme":"# 📄 @aidalinfo/office-to-markdown\n\n[![npm version](https://badge.fury.io/js/%40aidalinfo%2Foffice-to-markdown.svg)](https://badge.fury.io/js/%40aidalinfo%2Foffice-to-markdown)\n[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)\n[![Bun](https://img.shields.io/badge/Bun-%23000000.svg?style=flat&logo=bun&logoColor=white)](https://bun.sh/)\n\nA modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for the Bun ecosystem with advanced support for mathematical equations and tables.\n\n> **🔬 Created through reverse engineering of Microsoft's [MarkItDown](https://github.com/microsoft/markitdown)** - A TypeScript reimplementation that brings Python's document conversion capabilities to the JavaScript/Bun ecosystem with enhanced performance and type safety.\n\n## 🚀 Features\n\n- ✅ **DOCX to Markdown conversion** with structure preservation\n- ✅ **Mathematical equation support** (OMML → LaTeX)\n- ✅ **Table handling** with automatic formatting\n- ✅ **Style preservation** (bold, italic, headings)\n- ✅ **Image processing** with alt text\n- ✅ **Simple and advanced API** for different use cases\n- ✅ **Robust error handling** with specific error codes\n- ✅ **Optimized performance** with Bun runtime\n- ✅ **Complete TypeScript types** for better DX\n\n## 📦 Installation\n\n### With Bun (recommended)\n```bash\nbun add @aidalinfo/office-to-markdown\n```\n\n### With npm/yarn/pnpm\n```bash\nnpm install @aidalinfo/office-to-markdown\n# or\nyarn add @aidalinfo/office-to-markdown\n# or  \npnpm add @aidalinfo/office-to-markdown\n```\n\n### Required Dependencies\nThe following dependencies are automatically installed:\n- `mammoth` - DOCX to HTML conversion\n- `turndown` - HTML to Markdown conversion  \n- `jszip` - ZIP archive manipulation (DOCX)\n\n## 🛠️ Conversion Workflow\n\nThe conversion process follows these steps:\n\n1. **File Detection** - MIME type and extension verification\n2. **Preprocessing** - DOCX content extraction and modification\n3. **Math Processing** - OMML → LaTeX conversion\n4. **Main Conversion** - DOCX → HTML via mammoth\n5. **Post-processing** - HTML → Markdown with custom rules\n\n## 🎯 Simple Usage\n\n### Basic Conversion\n\n```typescript\nimport { docxToMarkdown } from '@aidalinfo/office-to-markdown';\n\n// Simple file conversion\nconst markdown = await docxToMarkdown('./document.docx');\nconsole.log(markdown);\n```\n\n### Advanced API\n\n```typescript\nimport { OfficeToMarkdown } from '@aidalinfo/office-to-markdown';\n\nconst converter = new OfficeToMarkdown({\n  headingStyle: 'atx',           // Use ## for headings\n  preserveTables: true,          // Preserve tables\n  convertMath: true,             // Convert equations to LaTeX\n});\n\n// Conversion with options\nconst result = await converter.convertDocx('./document.docx');\nconsole.log('Title:', result.title);\nconsole.log('Content:', result.markdown);\n```\n\n### Conversion from Different Sources\n\n```typescript\nimport { OfficeToMarkdown } from '@aidalinfo/office-to-markdown';\n\nconst converter = new OfficeToMarkdown();\n\n// From file path\nconst result1 = await converter.convert('./document.docx');\n\n// From Buffer\nconst buffer = await Bun.file('./document.docx').arrayBuffer();\nconst result2 = await converter.convert(buffer);\n\n// From Bun file\nconst file = Bun.file('./document.docx');\nconst result3 = await converter.convert(file);\n\n// Batch processing\nconst results = await converter.convertMultiple([\n  './doc1.docx',\n  './doc2.docx',\n  buffer\n]);\n```\n\n## ⚙️ Configuration Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `headingStyle` | `'atx' \\| 'setext'` | `'atx'` | Markdown heading style |\n| `preserveTables` | `boolean` | `true` | Preserve tables |\n| `convertMath` | `boolean` | `true` | Convert mathematical equations |\n| `styleMap` | `string` | - | Custom mapping for mammoth |\n\n## 🔧 Technical Architecture\n\n### Module Structure\n\n```\nsrc/\n├── converters/           # Document converters\n│   ├── base-converter.ts    # Abstract base class\n│   └── docx-converter.ts    # Specialized DOCX converter\n├── preprocessing/        # Preliminary processing\n│   └── docx-preprocessor.ts # DOCX preprocessing (math)\n├── math/                # Mathematical processing\n│   └── omml-processor.ts    # OMML → LaTeX converter\n├── utils/               # Utilities\n│   ├── html-to-markdown.ts # HTML → Markdown conversion\n│   ├── file-detector.ts     # File type detection\n│   └── error-handler.ts     # Error handling\n└── types/               # TypeScript definitions\n    ├── converter.ts         # Converter types\n    ├── result.ts           # Result types\n    └── stream-info.ts      # File info types\n```\n\n### Conversion Pipeline\n\n1. **File Detection** - MIME type and extension verification\n2. **Preprocessing** - DOCX content extraction and modification\n3. **Mathematical Processing** - OMML → LaTeX conversion\n4. **Main Conversion** - DOCX → HTML via mammoth\n5. **Post-processing** - HTML → Markdown with custom rules\n\n### Mathematical Equation Handling\n\nThe equation conversion follows this process:\n\n```typescript\n// OMML (Office Math Markup Language)\n<m:f>\n  <m:num>1</m:num>\n  <m:den>2</m:den>\n</m:f>\n\n// ↓ Preprocessing\n\n<w:r><w:t>$\\frac{1}{2}$</w:t></w:r>\n\n// ↓ Mammoth (HTML)\n\n<p>$\\frac{1}{2}$</p>\n\n// ↓ Turndown (Markdown)\n\n$\\frac{1}{2}$\n```\n\n### Supported Mathematical Elements\n\n| OMML | LaTeX | Description |\n|------|-------|-------------|\n| `<m:f>` | `\\frac{}{}` | Fractions |\n| `<m:sSup>` | `^{}` | Exponents |\n| `<m:sSub>` | `_{}` | Subscripts |\n| `<m:rad>` | `\\sqrt{}` | Square roots |\n| `<m:rad><m:deg>` | `\\sqrt[]{}` | Nth roots |\n\n## 🎨 Advanced Usage Examples\n\n### Error Handling\n\n```typescript\nimport { \n  OfficeToMarkdown, \n  FileConversionException, \n  UnsupportedFormatException \n} from '@aidalinfo/office-to-markdown';\n\nasync function convertSafely(filePath: string) {\n  try {\n    const converter = new OfficeToMarkdown();\n    const result = await converter.convertDocx(filePath);\n    return result.markdown;\n  } catch (error) {\n    if (error instanceof UnsupportedFormatException) {\n      console.error('Unsupported format:', error.message);\n    } else if (error instanceof FileConversionException) {\n      console.error('Conversion error:', error.message);\n    } else {\n      console.error('Unexpected error:', error.message);\n    }\n    throw error;\n  }\n}\n```\n\n### Capability Checking\n\n```typescript\nimport { OfficeToMarkdown } from '@aidalinfo/office-to-markdown';\n\nconst converter = new OfficeToMarkdown();\n\n// Check supported types\nconst info = converter.getSupportedTypes();\nconsole.log('Extensions:', info.extensions); // ['.docx']\nconsole.log('MIME types:', info.mimeTypes);\n\n// Check if a file is supported\nconst isSupported = await converter.isSupported('./document.pdf');\nconsole.log('PDF supported:', isSupported); // false\n\n// Get file information\nconst fileInfo = await converter.getFileInfo('./document.docx');\nconsole.log('MIME type:', fileInfo.mimetype);\nconsole.log('Supported:', fileInfo.supported);\n```\n\n### Usage with Node.js\n\n```typescript\nimport { readFile } from 'fs/promises';\nimport { OfficeToMarkdown } from '@aidalinfo/office-to-markdown';\n\n// From Node.js Buffer\nconst buffer = await readFile('./document.docx');\nconst converter = new OfficeToMarkdown();\nconst result = await converter.convert(buffer);\n\nconsole.log(result.markdown);\n```\n\n## 🧪 Testing and Validation\n\n### Test Results\n\n- ✅ HTML → Markdown conversion with tables\n- ✅ File type detection (DOCX vs others)\n- ✅ OMML → LaTeX mathematical conversion\n- ✅ Error handling with specific codes\n- ✅ Complete pipeline tested with real documents\n\n### Performance\n\n- **Speed**: ~80ms for an average document (7KB)\n- **Fidelity**: Complete preservation of structure and content\n- **Robustness**: Graceful error handling with fallbacks\n\n## 🔧 Development\n\n### Prerequisites\n\n- **Bun** >= 1.2.0 (recommended) or **Node.js** >= 20.0.0\n- **TypeScript** >= 4.5.0\n\n### Development Installation\n\n```bash\ngit clone https://github.com/aidalinfo/extract-kit.git\ncd extract-kit/packages/office-to-markdown\nbun install\n```\n\n### Available Scripts\n\n```bash\nbun run build          # Complete build (ESM + types)\nbun run dev            # Development mode with watch\nbun run clean          # Clean dist/ folder\n```\n\n### Testing\n\n```bash\n# Basic functionality test\nbun run src/test.ts\n\n# Test with real DOCX file\nbun run test-docx.ts \"your-file.docx\"\n```\n\n## 🚀 Roadmap\n\n- [ ] **PPT/PPTX format support** - Presentation conversion\n- [ ] **XLS/XLSX format support** - Spreadsheet conversion\n- [ ] **Streaming API** - Large file streaming processing\n- [ ] **Plugin system** - Support for custom converters\n- [ ] **Web interface** - Optional user interface\n- [ ] **Embedded image support** - Image extraction and conversion\n- [ ] **CLI batch mode** - Command-line interface\n\n## 🤝 Contributing\n\nContributions are welcome! Please see our [contribution guide](https://github.com/aidalinfo/extract-kit/blob/main/CONTRIBUTING.md).\n\n### Contribution Process\n\n1. **Fork** the repository\n2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)\n3. **Commit** your changes (`git commit -m 'Add amazing feature'`)\n4. **Push** to the branch (`git push origin feature/amazing-feature`)\n5. **Open** a Pull Request\n\n## 📄 License\n\nThis project is licensed under **MIT** - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Inspired by Microsoft's [MarkItDown](https://github.com/microsoft/markitdown) project\n- Uses [mammoth.js](https://github.com/mwilliamson/mammoth.js) for DOCX → HTML conversion  \n- Uses [turndown](https://github.com/mixmark-io/turndown) for HTML → Markdown conversion\n- Optimized for [Bun](https://bun.sh/) runtime\n\n## 📞 Support\n\n- **Issues**: [GitHub Issues](https://github.com/aidalinfo/extract-kit/issues)\n- **Documentation**: [GitHub Repository](https://github.com/aidalinfo/extract-kit/tree/main/packages/office-to-markdown)\n- **Email**: contact@aidalinfo.com\n\n---\n\n<div align=\"center\">\n  \n**[@aidalinfo/office-to-markdown](https://www.npmjs.com/package/@aidalinfo/office-to-markdown)**\n\n*Simple, fast, and reliable DOCX to Markdown conversion* ⚡\n\n</div>","readmeFilename":"README.md"}