From 98e89f7cb3bbc736ff48024332d0de229fc2f8c6 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 5 Apr 2021 18:21:08 -0400 Subject: [PATCH] fix: run Remark plugins on imported mdx/md files --- src/remarkMdxImport.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/remarkMdxImport.ts b/src/remarkMdxImport.ts index e4538c5..263f536 100644 --- a/src/remarkMdxImport.ts +++ b/src/remarkMdxImport.ts @@ -23,17 +23,20 @@ export function remarkMdxImport({ const splices = await Promise.all( imports.map( async ({ id, index }): Promise => { - const filePath = await resolve(id, file.path) - if (!filePath) { + const importedPath = await resolve(id, file.path) + if (!importedPath) { // Strip unresolved imports. return [index, 1, []] } - const code = await readFile(filePath) - const compiler = getCompiler(filePath) - const ast = compiler.parse({ - contents: code, - path: filePath - }) + const importedFile = { + path: importedPath, + contents: await readFile(importedPath) + } + const compiler = getCompiler(importedPath) + const ast = await compiler.run( + compiler.parse(importedFile), + importedFile + ) // Inject the AST of the imported markdown. return [index, 1, (ast as import('mdast').Root).children] }