web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.44k stars 133 forks source link

[Bug]:Incorrect file link processing in MD/MDX files #1280

Open takahiro-ngc opened 3 months ago

takahiro-ngc commented 3 months ago

Version

System:
  OS: Windows 11 10.0.22631
  CPU: (8) x64 AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx  
  Memory: 973.03 MB / 6.94 GB
Browsers:
  Edge: Chromium (126.0.2592.113)
  Internet Explorer: 11.0.22621.1
npmPackages:
  rspress: ^1.26.1 => 1.26.2

Details

When creating links to files in MD or MDX files, rspress incorrectly processes the href attributes, causing two issues:

  1. It appends ".html" to all file links.
  2. For image files (like .png), it generates an incorrect path.

For example, in /docs/guide/index.md:

Expected output in generated HTML:

Actual output in generated HTML:

Reproduce link

https://codesandbox.io/p/devbox/silly-sky-qg9smt?file=%2Fdocs%2Fguide%2Findex.md%3A6%2C1&workspaceId=ba5b3bb4-c28a-4756-b043-8178f97ca28d

Reproduce Steps

  1. Create a new rspress project.
  2. In any Markdown file (e.g. docs/guide/index.md), add the following content: [File Link](./document.pdf) [Image Link](./image.png)
  3. Run the rspress dev command.
  4. Check the generated HTML output for these links.
Timeless0911 commented 3 months ago

https://rspress.dev/guide/basic/static-assets#static-assets-used-in-mdx-files

You should use ![Image Link](./image.png), [Image Link](./image.png) means it is a link contain .png instead of assets.