mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 20:46:58 +02:00
fix(v1): fenced block detection (#3340)
This commit is contained in:
parent
306d3afc0a
commit
8fd5375b26
2 changed files with 17 additions and 1 deletions
|
@ -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 more text';
|
||||
const link = utils.replaceAssetsLink(content, 'thelocation');
|
||||
expect(link).toBe(
|
||||
'```Some block```\n more text',
|
||||
);
|
||||
});
|
||||
|
||||
test('verifies asset link is not replaced inside a fenced code block', () => {
|
||||
const content = '```\n\n```';
|
||||
const link = utils.replaceAssetsLink(content, 'thelocation');
|
||||
expect(link).toBe('```\n\n```');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue