fix(v1): fenced block detection (#3340)

This commit is contained in:
adinaja 2020-08-27 10:06:10 +02:00 committed by GitHub
parent 306d3afc0a
commit 8fd5375b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -91,4 +91,20 @@ describe('server utils', () => {
expect(utils.getSubDir(docE, docsDir)).toBeNull();
expect(utils.getSubDir(docE, translatedDir)).toEqual('lol/lah');
});
describe('replaceAssetsLink', () => {
test('verifies asset link is replaced after code block', () => {
const content = '```Some block```\n![alt](assets/my.png) more text';
const link = utils.replaceAssetsLink(content, 'thelocation');
expect(link).toBe(
'```Some block```\n![alt](thelocation/assets/my.png) more text',
);
});
test('verifies asset link is not replaced inside a fenced code block', () => {
const content = '```\n![alt](assets/my.png)\n```';
const link = utils.replaceAssetsLink(content, 'thelocation');
expect(link).toBe('```\n![alt](assets/my.png)\n```');
});
});
});

View file

@ -69,7 +69,7 @@ function autoPrefixCss(cssContent) {
function replaceAssetsLink(oldContent, location) {
let fencedBlock = false;
const lines = oldContent.split('\n').map((line) => {
if (line.trim().startsWith('```')) {
if (line.trim().startsWith('```') && line.match(/`/g).length === 3) {
fencedBlock = !fencedBlock;
}
return fencedBlock