Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import * as vscode from 'vscode';
import * as mammoth from 'mammoth';
import { RuleConverter } from './converter';
import { convertContentWithAI } from '../import-service';
import { buildSystemPrompt } from './prompt-builder';
import type { CustomRule } from '../../types';
import { t } from '../../i18n/messages';
export class DocxConverter implements RuleConverter {
supportedExtensions = ['.docx'];
async convert(srcPath: string, context: vscode.ExtensionContext, existingRules?: CustomRule[]): Promise<string | null> {
let result: mammoth.Result;
try {
result = await mammoth.extractRawText({ path: srcPath });
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
vscode.window.showErrorMessage(t('import.docxReadFail', { 0: msg }));
return null;
}
const content = result.value.trim();
if (!content) {
vscode.window.showErrorMessage(t('import.docxEmpty'));
return null;
}
return convertContentWithAI(content, context, buildSystemPrompt('freeform', existingRules));
}
}
|