Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(article): only update links for relative images #11

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)