feat: add md<->docx document converters
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -112,4 +112,33 @@ describe('document converters', () => {
|
||||
const detected = await detectInputMime(outputPath);
|
||||
expect(detected.mime).toBe('application/pdf');
|
||||
}, 20000);
|
||||
|
||||
it('converts DOCX to MD containing the source text', async () => {
|
||||
const outputPath = path.join(tmpDir, 'from-docx.md');
|
||||
const entry = resolve('docx', 'md');
|
||||
|
||||
await entry.convert(docxFixturePath, outputPath);
|
||||
|
||||
const markdown = await fs.readFile(outputPath, 'utf8');
|
||||
expect(markdown).toContain('Hello from the fixture document');
|
||||
}, 20000);
|
||||
|
||||
it('converts MD to DOCX preserving headings, bold text, and bullet lists', async () => {
|
||||
const inputPath = path.join(tmpDir, 'fixture-for-docx.md');
|
||||
await fs.writeFile(
|
||||
inputPath,
|
||||
'# Report Title\n\nSome **bold** finding.\n\n- first point\n- second point\n'
|
||||
);
|
||||
const outputPath = path.join(tmpDir, 'from-md.docx');
|
||||
const entry = resolve('md', 'docx');
|
||||
|
||||
await entry.convert(inputPath, outputPath);
|
||||
|
||||
const mammoth = await import('mammoth');
|
||||
const result = await mammoth.default.convertToHtml({ path: outputPath });
|
||||
expect(result.value).toContain('Report Title');
|
||||
expect(result.value).toContain('<strong>bold</strong>');
|
||||
expect(result.value).toContain('first point');
|
||||
expect(result.value).toContain('<li>');
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user