Skip to content

Commit

Permalink
fix(doc-core): flatten error when meeting $ in mdx file (#4234)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 authored Jul 18, 2023
1 parent 5129771 commit 5dabe04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/bright-flies-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/doc-core': patch
---

fix(doc-core): flatten error when meeting `$` in mdx file

fix(doc-core): 当出现 `$` 字符时,mdx 内容扁平化结果异常
9 changes: 5 additions & 4 deletions packages/cli/doc-core/src/node/utils/flattenMdxContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ export async function flattenMdxContent(
if (MDX_REGEXP.test(absoluteImportPath)) {
// replace import statement with the content of the imported file
const importedContent = fs.readFileSync(absoluteImportPath, 'utf-8');

result = result.replace(
new RegExp(`<${id}\\s*/>`),
await flattenMdxContent(importedContent, absoluteImportPath, alias),
const replacedValue = await flattenMdxContent(
importedContent,
absoluteImportPath,
alias,
);
result = result.replace(new RegExp(`<${id}\\s*/>`), () => replacedValue);
}
}

Expand Down

0 comments on commit 5dabe04

Please sign in to comment.