From a1acabde664dac149d38d91f6914c052a80fdc9e Mon Sep 17 00:00:00 2001 From: Benjamin Blackwood Date: Fri, 2 Aug 2019 15:12:00 +1000 Subject: [PATCH] fix(article): only update links for relative images --- src/article.spec.ts | 4 ++++ src/article.ts | 2 +- test/article.md | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/article.spec.ts b/src/article.spec.ts index 8fb9a40..c2137ca 100644 --- a/src/article.spec.ts +++ b/src/article.spec.ts @@ -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)`); + }); }); }); diff --git a/src/article.ts b/src/article.ts index e65199a..c824ab2 100644 --- a/src/article.ts +++ b/src/article.ts @@ -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$/, ''); diff --git a/test/article.md b/test/article.md index 37ddd95..9418622 100644 --- a/test/article.md +++ b/test/article.md @@ -9,6 +9,8 @@ canonical_url: # This is my awesome article! +## Relative images + Hey, some text! Image 1: ![alt text 1](./image-1.png 'Title image 1') @@ -16,3 +18,7 @@ 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)