feat: add comprehensive DOCX document support
- Install docx (v9.5.1) and mammoth (v1.11.0) packages - Create docxService.ts with full DOCX read/write functionality: - Extract text, HTML, and Markdown from DOCX files using mammoth - Generate DOCX files from Markdown with proper heading levels (H1-H3) - Generate DOCX files from HTML and plain text - Automatic paragraph formatting and spacing - Integrate DOCX conversions into pandocService.ts - Update README with DOCX support documentation - Add DOCX libraries to tech stack section Supported DOCX conversions: - DOCX → Text/HTML/Markdown - Markdown/HTML/Text → DOCX 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,14 @@ import {
|
||||
htmlToPDF,
|
||||
plainTextToPDF,
|
||||
} from './pdfService';
|
||||
import {
|
||||
docxToText,
|
||||
docxToHTML,
|
||||
docxToMarkdown,
|
||||
textToDOCX,
|
||||
markdownToDOCX,
|
||||
htmlToDOCX,
|
||||
} from './docxService';
|
||||
|
||||
// Import DOMPurify only on client side
|
||||
let DOMPurify: any;
|
||||
@@ -53,6 +61,20 @@ export async function convertWithPandoc(
|
||||
}
|
||||
}
|
||||
|
||||
// Handle DOCX conversions
|
||||
if (inputExt === 'docx') {
|
||||
// DOCX input
|
||||
if (outputFormat === 'txt') {
|
||||
return await docxToText(file, onProgress);
|
||||
} else if (outputFormat === 'html') {
|
||||
return await docxToHTML(file, onProgress);
|
||||
} else if (outputFormat === 'md' || outputFormat === 'markdown') {
|
||||
return await docxToMarkdown(file, onProgress);
|
||||
} else {
|
||||
throw new Error(`Conversion from DOCX to ${outputFormat} not supported`);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle conversions TO PDF
|
||||
if (outputFormat === 'pdf') {
|
||||
if (inputExt === 'md' || inputExt === 'markdown') {
|
||||
@@ -66,6 +88,19 @@ export async function convertWithPandoc(
|
||||
}
|
||||
}
|
||||
|
||||
// Handle conversions TO DOCX
|
||||
if (outputFormat === 'docx') {
|
||||
if (inputExt === 'md' || inputExt === 'markdown') {
|
||||
return await markdownToDOCX(file, onProgress);
|
||||
} else if (inputExt === 'html' || inputExt === 'htm') {
|
||||
return await htmlToDOCX(file, onProgress);
|
||||
} else if (inputExt === 'txt') {
|
||||
return await textToDOCX(file, onProgress);
|
||||
} else {
|
||||
throw new Error(`Conversion from ${inputExt} to DOCX not supported`);
|
||||
}
|
||||
}
|
||||
|
||||
// Perform conversion based on input and output formats
|
||||
if (inputExt === 'md' || inputExt === 'markdown') {
|
||||
// Markdown input
|
||||
|
||||
Reference in New Issue
Block a user