Skip to content

Commit

Permalink
fix: run Remark plugins on imported mdx/md files
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Apr 6, 2021
1 parent 4443355 commit 98e89f7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/remarkMdxImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ export function remarkMdxImport({
const splices = await Promise.all(
imports.map(
async ({ id, index }): Promise<Splice> => {
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]
}
Expand Down

0 comments on commit 98e89f7

Please sign in to comment.