Don't replace static assets linking in fenced code blocks ()

* Don't replace any relative links to static assets in a fenced code block

* revert unintended docs change

* improve regex

* remove test file :sob

* stronger regex test for replace assets

* super simplify solution
This commit is contained in:
Endilie Yacop Sucipto 2018-07-21 20:54:45 +07:00 committed by GitHub
parent 53993f1ba6
commit d42ecb943f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 148 additions and 11 deletions
lib/server/__tests__

View file

@ -49,9 +49,10 @@ const doc2 = fs.readFileSync(
'utf8'
);
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
describe('mdToHtmlify', () => {
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
const mdToHtml = metadataUtils.mdToHtml(Metadata, '/');
test('transform nothing', () => {
@ -129,6 +130,31 @@ describe('getFile', () => {
});
});
describe('replaceAssetsLink', () => {
test('transform document with valid assets link', () => {
const content1 = docs.replaceAssetsLink(rawContent1);
expect(content1).toMatchSnapshot();
expect(content1).toContain('![image1](/docs/assets/image1.png)');
expect(content1).toContain('![image2](/docs/assets/image2.jpg)');
expect(content1).toContain('![image3](/docs/assets/image3.gif)');
expect(content1).toContain('![image4](assets/image4.bmp)');
expect(content1).not.toContain('![image1](assets/image1.png)');
expect(content1).not.toContain('![image2](assets/image2.jpg)');
expect(content1).not.toContain('![image3](assets/image3.gif)');
expect(content1).not.toContain('![image4](/docs/assets/image4.bmp)');
expect(content1).not.toEqual(rawContent1);
});
test('does not transform document without valid assets link', () => {
const content2 = docs.replaceAssetsLink(rawContent2);
expect(content2).toMatchSnapshot();
expect(content2).not.toContain('![image1](/docs/assets/image1.png)');
expect(content2).not.toContain('![image2](/docs/assets/image2.jpg)');
expect(content2).not.toContain('![image3](/docs/assets/image3.gif)');
expect(content2).toEqual(rawContent2);
});
});
afterAll(() => {
process.chdir(originalCwd);
});