Skip to content

Commit 22edeab

Browse files
committed
refactor(theme-common): Do not fill invalid/missing options
1 parent 6355837 commit 22edeab

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ function getAllMagicCommentDirectiveStyles(
147147
}
148148
}
149149

150-
function parseCodeBlockTitle(metastring?: string): string {
151-
return metastring?.match(codeBlockTitleRegex)?.groups!.title ?? '';
152-
}
153-
154150
function getMetaLineNumbersStart(metastring?: string): number | undefined {
155151
const showLineNumbersMeta = metastring
156152
?.split(' ')
@@ -356,12 +352,23 @@ export function parseCodeBlockMetaOptions(
356352
// we keep the old custom logic which was moved from their old spots to here.
357353

358354
// normal codeblock
359-
parsedOptions.title = parseCodeBlockTitle(metastring);
360-
parsedOptions.showLineNumbers = getMetaLineNumbersStart(metastring);
355+
const title = metastring?.match(codeBlockTitleRegex)?.groups!.title;
356+
if (title !== undefined) {
357+
parsedOptions.title = title;
358+
}
359+
const showLineNumbers = getMetaLineNumbersStart(metastring);
360+
if (showLineNumbers !== undefined) {
361+
parsedOptions.showLineNumbers = showLineNumbers;
362+
}
361363

362364
// interactive code editor (theme-live-codeblock => Playground)
363-
parsedOptions.live = metastring?.split(' ').includes('live');
364-
parsedOptions.noInline = metastring?.includes('noInline');
365+
if (metastring?.split(' ').includes('live')) {
366+
parsedOptions.live = true;
367+
}
368+
369+
if (metastring?.includes('noInline')) {
370+
parsedOptions.noInline = true;
371+
}
365372

366373
return parsedOptions;
367374
}

0 commit comments

Comments
 (0)