markdown-magic icon indicating copy to clipboard operation
markdown-magic copied to clipboard

Transformation: current file name and exception handling

Open svdoever opened this issue 3 years ago • 1 comments

Is there a way to determine the current file being processed within a transform? I would like to be able to do error reporting when an exception occurs within a transform, and in this error reporting mention the file being processed.

svdoever avatar May 08 '22 22:05 svdoever

Found part of the solution.... there is a third argument to the transform function called config:

    interface TransformFunction {
        (content: string, options: Record<string, unknown>, config?: ProcessedConfig): string;
    }

    interface ProcessedConfig extends Configuration {
        readonly originalPath: string; // path of file being processed
        readonly originalFilePaths: string[]; // all files mathing thr glob pattern
        readonly outputDir: string; // directory where output files will be created
        readonly originalContent: string;
        readonly outputContent: string;
    }

This is incorrectly defined in the @types/markdown-magic npm package.

svdoever avatar May 10 '22 20:05 svdoever