Skip to content

Commit

Permalink
Merge pull request #11 from BBlackwo/dev-bblackwo-only-update-relativ…
Browse files Browse the repository at this point in the history
…e-images

fix(article): only update links for relative images
  • Loading branch information
maxime1992 authored Aug 26, 2019
2 parents 1d7a972 + a1acabd commit 0eb6607
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/article.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ describe(`Article`, () => {
`Image 3: ![alt text 3](https://raw.githubusercontent.com/${repository.username}/${repository.name}/master/test/image-3.png)`,
);
});

it(`should NOT rewrite absolute images URLs to match the raw file on github`, () => {
expect(articleRead).toContain(`Absolute image: ![alt text](http://google.com/absolute-image.png)`);
});
});
});
2 changes: 1 addition & 1 deletion src/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ArticleFrontMatter {
title: string;
}

const imagesRe: RegExp = /\!\[.*\]\(.*\)/g;
const imagesRe: RegExp = /\!\[.*\]\(\.\/.*\)/g;
const imageRe: RegExp = /\!\[(.*)\]\(([^ \)]*)(?: '(.*)')?\)/;

const excludeArticleFromPath = (path: string): string => path.replace(/\/[^\/]+\.md$/, '');
Expand Down
6 changes: 6 additions & 0 deletions test/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ canonical_url:

# This is my awesome article!

## Relative images

Hey, some text!

Image 1: ![alt text 1](./image-1.png 'Title image 1')

Image 2: ![alt text 2](./image-2.png 'Title image 2')

Image 3: ![alt text 3](./image-3.png)

## Absolute images

Absolute image: ![alt text](http://google.com/absolute-image.png)

0 comments on commit 0eb6607

Please sign in to comment.