Skip to content

Commit

Permalink
fix: support fragments in image URLs (#753)
Browse files Browse the repository at this point in the history
* fix: make tests fail

* fix: support hash character in URLs
  • Loading branch information
nhedger committed Jul 15, 2022
1 parent 955c760 commit 7e16ed7
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/package.ts
Expand Up @@ -709,7 +709,7 @@ export class MarkdownProcessor extends BaseProcessor {
contents = contents.replace(markdownPathRegex, urlReplace);

// Replace <img> links with urls
contents = contents.replace(/<img.+?src=["']([/.\w\s-]+)['"].*?>/g, (all, link) => {
contents = contents.replace(/<img.+?src=["']([/.\w\s#-]+)['"].*?>/g, (all, link) => {
const isLinkRelative = !/^\w+:\/\//.test(link) && link[0] !== '#';

if (!this.baseImagesUrl && isLinkRelative) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.branch.main.expected.md
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://github.com/username/repository/raw/main/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/username/repository/raw/main/images/myImage.gif">
<img src="https://github.com/username/repository/raw/main/images/myImage.gif#gh-light-mode-only">

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

Expand Down
Expand Up @@ -22,7 +22,9 @@ 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)](https://github.com/base/monkey)
![](https://github.com/base/images/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/base/images/myImage.gif">
<img src="https://github.com/base/images/myImage.gif#gh-light-mode-only">

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

Expand Down
Expand Up @@ -22,7 +22,9 @@ 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)](https://github.com/username/repository/blob/main/monkey)
![](https://github.com/base/images/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif)
![](https://github.com/base/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/base/images/myImage.gif">
<img src="https://github.com/base/images/myImage.gif#gh-light-mode-only">

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.default.md
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://github.com/username/repository/raw/HEAD/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/username/repository/raw/HEAD/images/myImage.gif">
<img src="https://github.com/username/repository/raw/HEAD/images/myImage.gif#gh-light-mode-only">

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.expected.md
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://github.com/username/repository/raw/master/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/username/repository/raw/master/images/myImage.gif">
<img src="https://github.com/username/repository/raw/master/images/myImage.gif#gh-light-mode-only">

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

Expand Down
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://gitlab.com/username/repository/-/raw/main/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://gitlab.com/username/repository/-/raw/main/images/myImage.gif">
<img src="https://gitlab.com/username/repository/-/raw/main/images/myImage.gif#gh-light-mode-only">

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

Expand Down
Expand Up @@ -22,7 +22,9 @@ 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)](https://gitlab.com/base/monkey)
![](https://gitlab.com/base/images/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://gitlab.com/base/images/myImage.gif">
<img src="https://gitlab.com/base/images/myImage.gif#gh-light-mode-only">

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

Expand Down
Expand Up @@ -22,7 +22,9 @@ 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)](https://gitlab.com/username/repository/-/blob/main/monkey)
![](https://gitlab.com/base/images/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif)
![](https://gitlab.com/base/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://gitlab.com/base/images/myImage.gif">
<img src="https://gitlab.com/base/images/myImage.gif#gh-light-mode-only">

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.gitlab.default.md
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://gitlab.com/username/repository/-/raw/HEAD/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://gitlab.com/username/repository/-/raw/HEAD/images/myImage.gif">
<img src="https://gitlab.com/username/repository/-/raw/HEAD/images/myImage.gif#gh-light-mode-only">

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.images.expected.md
Expand Up @@ -22,7 +22,9 @@ 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)](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)
![](https://github.com/username/repository/path/to/SpellMDDemo2.gif#gh-light-mode-only)
<img src="https://github.com/username/repository/path/to/images/myImage.gif">
<img src="https://github.com/username/repository/path/to/images/myImage.gif#gh-light-mode-only">

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/fixtures/readme/readme.md
Expand Up @@ -22,7 +22,9 @@ The status bar lets you quickly navigate to any issue and you can see all positi
[![Jump to issues](images/SpellMDDemo2.gif)](monkey)
![](images/SpellMDDemo2.gif)
![](./SpellMDDemo2.gif)
![](./SpellMDDemo2.gif#gh-light-mode-only)
<img src="/images/myImage.gif">
<img src="/images/myImage.gif#gh-light-mode-only">

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

Expand Down

0 comments on commit 7e16ed7

Please sign in to comment.