Skip to content

Commit

Permalink
fix(preview): keep code element src prop if it is not a relative path (
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan committed Mar 5, 2024
1 parent dc9d657 commit 070e96b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-pots-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rspress/plugin-preview': patch
---

fix: keep code element src prop if it is not a relative path
9 changes: 5 additions & 4 deletions packages/plugin-preview/src/remarkPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, isAbsolute, dirname } from 'path';
import { join, resolve, dirname } from 'path';
import { visit } from 'unist-util-visit';
import { normalizePosixPath } from '@rspress/shared';
import fs from '@rspress/shared/fs-extra';
Expand Down Expand Up @@ -47,12 +47,13 @@ export const remarkCodeToDemo: Plugin<[RemarkPluginOptions], Root> = ({
externalDemoIndex?: number,
) {
if (isMobileMode) {
const relativePathReg = new RegExp(/^\.\.?\/.*$/);
demos[pageName].push({
title,
id: demoId,
path: isAbsolute(demoPath)
? demoPath
: join(vfile.dirname || dirname(vfile.path), demoPath),
path: relativePathReg.test(demoPath)
? resolve(vfile.dirname || dirname(vfile.path), demoPath)
: demoPath,
});
} else {
demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
Expand Down

0 comments on commit 070e96b

Please sign in to comment.