Skip to content

Commit

Permalink
fix: normalize relative paths when rewriting links
Browse files Browse the repository at this point in the history
closes #535
  • Loading branch information
joaomoreno committed Nov 2, 2021
1 parent d797b8d commit a537741
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/package.ts
Expand Up @@ -626,13 +626,13 @@ export class MarkdownProcessor extends BaseProcessor {
}

async onFile(file: IFile): Promise<IFile> {
const path = util.normalize(file.path);
const filePath = util.normalize(file.path);

if (!this.regexp.test(path)) {
if (!this.regexp.test(filePath)) {
return Promise.resolve(file);
}

this.assets.push({ type: this.assetType, path });
this.assets.push({ type: this.assetType, path: filePath });

let contents = await read(file);

Expand Down Expand Up @@ -665,7 +665,7 @@ export class MarkdownProcessor extends BaseProcessor {
return `${isImage}[${title}](${link})`;
}

return `${isImage}[${title}](${urljoin(prefix, link)})`;
return `${isImage}[${title}](${urljoin(prefix, path.normalize(link))})`;
};

// Replace Markdown links with urls
Expand All @@ -686,7 +686,7 @@ export class MarkdownProcessor extends BaseProcessor {
return all;
}

return all.replace(link, urljoin(prefix, link));
return all.replace(link, urljoin(prefix, path.normalize(link)));
});

if ((this.gitHubIssueLinking && this.isGitHub) || (this.gitLabIssueLinking && this.isGitLab)) {
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.branch.main.expected.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/username/repository/raw/main/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/username/repository/raw/main/images/SpellMDDemo2.gif)](https://github.com/username/repository/blob/main/monkey)
![](https://github.com/username/repository/raw/main/images/SpellMDDemo2.gif)
![](https://github.com/username/repository/raw/main/SpellMDDemo2.gif)
<img src="https://github.com/username/repository/raw/main/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/base/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/base/images/SpellMDDemo2.gif)](https://github.com/base/monkey)
![](https://github.com/base/images/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif)
<img src="https://github.com/base/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/base/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/base/images/SpellMDDemo2.gif)](https://github.com/username/repository/blob/main/monkey)
![](https://github.com/base/images/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif)
<img src="https://github.com/base/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.default.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/username/repository/raw/HEAD/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/username/repository/raw/HEAD/images/SpellMDDemo2.gif)](https://github.com/username/repository/blob/HEAD/monkey)
![](https://github.com/username/repository/raw/HEAD/images/SpellMDDemo2.gif)
![](https://github.com/username/repository/raw/HEAD/SpellMDDemo2.gif)
<img src="https://github.com/username/repository/raw/HEAD/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.expected.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/username/repository/raw/master/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/username/repository/raw/master/images/SpellMDDemo2.gif)](https://github.com/username/repository/blob/master/monkey)
![](https://github.com/username/repository/raw/master/images/SpellMDDemo2.gif)
![](https://github.com/username/repository/raw/master/SpellMDDemo2.gif)
<img src="https://github.com/username/repository/raw/master/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://gitlab.com/username/repository/-/raw/main/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://gitlab.com/username/repository/-/raw/main/images/SpellMDDemo2.gif)](https://gitlab.com/username/repository/-/blob/main/monkey)
![](https://gitlab.com/username/repository/-/raw/main/images/SpellMDDemo2.gif)
![](https://gitlab.com/username/repository/-/raw/main/SpellMDDemo2.gif)
<img src="https://gitlab.com/username/repository/-/raw/main/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://gitlab.com/base/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://gitlab.com/base/images/SpellMDDemo2.gif)](https://gitlab.com/base/monkey)
![](https://gitlab.com/base/images/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif)
<img src="https://gitlab.com/base/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://gitlab.com/base/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://gitlab.com/base/images/SpellMDDemo2.gif)](https://gitlab.com/username/repository/-/blob/main/monkey)
![](https://gitlab.com/base/images/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif)
<img src="https://gitlab.com/base/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.gitlab.default.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://gitlab.com/username/repository/-/raw/HEAD/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://gitlab.com/username/repository/-/raw/HEAD/images/SpellMDDemo2.gif)](https://gitlab.com/username/repository/-/blob/HEAD/monkey)
![](https://gitlab.com/username/repository/-/raw/HEAD/images/SpellMDDemo2.gif)
![](https://gitlab.com/username/repository/-/raw/HEAD/SpellMDDemo2.gif)
<img src="https://gitlab.com/username/repository/-/raw/HEAD/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.images.expected.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](https://github.com/username/repository/path/to/images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](https://github.com/username/repository/path/to/images/SpellMDDemo2.gif)](https://github.com/username/repository/blob/HEAD/monkey)
![](https://github.com/username/repository/path/to/images/SpellMDDemo2.gif)
![](https://github.com/username/repository/path/to/SpellMDDemo2.gif)
<img src="https://github.com/username/repository/path/to/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/readme/readme.md
Expand Up @@ -21,6 +21,7 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](images/SpellMDDemo2.gif)](http://shouldnottouchthis/)
[![Jump to issues](images/SpellMDDemo2.gif)](monkey)
![](images/SpellMDDemo2.gif)
![](./SpellMDDemo2.gif)
<img src="/images/myImage.gif">

The `spellMD.json` config file is watched so you can add more ignores or change mappings at will.
Expand Down

0 comments on commit a537741

Please sign in to comment.