markdown-magic
markdown-magic copied to clipboard
Transformation: current file name and exception handling
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.
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.