All files / src/rules/converters pptx-converter.ts

43.33% Statements 13/30
100% Branches 1/1
50% Functions 1/2
43.33% Lines 13/30

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 311x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                   1x  
import * as vscode from 'vscode';
import { OfficeParser, type OfficeParserAST } from 'officeparser';
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 PptxConverter implements RuleConverter {
  supportedExtensions = ['.pptx'];
 
  async convert(srcPath: string, context: vscode.ExtensionContext, existingRules?: CustomRule[]): Promise<string | null> {
    let ast: OfficeParserAST;
    try {
      ast = await OfficeParser.parseOffice(srcPath);
    } catch (err) {
      const msg = err instanceof Error ? err.message : String(err);
      vscode.window.showErrorMessage(t('import.pptxReadFail', { 0: msg }));
      return null;
    }

    const text = ast.toText().trim();
    if (!text) {
      vscode.window.showErrorMessage(t('import.pptxEmpty'));
      return null;
    }

    return convertContentWithAI(text, context, buildSystemPrompt('freeform', existingRules));
  }
}