Skip to content

Commit

Permalink
Fix a bug that Japanese files were not displayed correctly. (#9866)
Browse files Browse the repository at this point in the history
* Fix: Fix a bug that Japanese files were not displayed correctly.

* chore: generate change description

* Update .changeset/cool-colts-watch.md

* add test case for non-UTF-8 file name

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
  • Loading branch information
ktym4a and ematipico committed Jan 29, 2024
1 parent a994d60 commit 44c957f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-colts-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/markdown-remark": patch
---

Fixes a bug where non-UTF-8 file names are not displayed when using relative paths in markdowns.
6 changes: 4 additions & 2 deletions packages/astro/test/astro-assets-prefix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ describe('Assets Prefix - Static', () => {
it('markdown image src start with assetsPrefix', async () => {
const html = await fixture.readFile('/markdown/index.html');
const $ = cheerio.load(html);
const imgAsset = $('img');
expect(imgAsset.attr('src')).to.match(assetsPrefixRegex);
const imgAssets = $('img');
imgAssets.each((i, el) => {
expect(el.attribs.src).to.match(assetsPrefixRegex);
});
});

it('content collections image src start with assetsPrefix', async () => {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
Relative image has assetsPrefix

![Relative image](../assets/penguin1.jpg)

![non-UTF-8 file name image](../assets/ペンギン.jpg)
2 changes: 2 additions & 0 deletions packages/markdown/remark/src/rehype-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function rehypeImages() {
if (node.tagName !== 'img') return;

if (node.properties?.src) {
node.properties.src = decodeURI(node.properties.src);

if (file.data.imagePaths?.has(node.properties.src)) {
const { ...props } = node.properties;

Expand Down

0 comments on commit 44c957f

Please sign in to comment.