Skip to content

Commit e74e49f

Browse files
committed
refactor(theme-common, theme-classic): Use metaOptions for showLineNumbers
1 parent e9ce4e3 commit e74e49f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function CodeBlockString({
7070
});
7171
const lineNumbersStart = getLineNumbersStart({
7272
showLineNumbers: showLineNumbersProp,
73-
metastring,
73+
metaOptions,
7474
});
7575

7676
return (

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,22 @@ export function getCodeBlockTitle({
183183

184184
export function getLineNumbersStart({
185185
showLineNumbers,
186-
metastring,
186+
metaOptions,
187187
}: {
188188
showLineNumbers: boolean | number | undefined;
189-
metastring: string | undefined;
189+
metaOptions: CodeBlockMetaOptions;
190190
}): number | undefined {
191+
const showLineNumbersValue = showLineNumbers ?? metaOptions.showLineNumbers;
192+
191193
const defaultStart = 1;
192-
if (typeof showLineNumbers === 'boolean') {
193-
return showLineNumbers ? defaultStart : undefined;
194+
if (typeof showLineNumbersValue === 'boolean') {
195+
return showLineNumbersValue ? defaultStart : undefined;
194196
}
195-
if (typeof showLineNumbers === 'number') {
196-
return showLineNumbers;
197+
if (typeof showLineNumbersValue === 'number') {
198+
return showLineNumbersValue;
197199
}
198-
return getMetaLineNumbersStart(metastring);
200+
201+
return undefined;
199202
}
200203

201204
/**
@@ -429,7 +432,7 @@ export function parseCodeBlockMetaOptions(
429432

430433
// normal codeblock
431434
parsedOptions.title = parseCodeBlockTitle(metastring);
432-
// parsedOptions.showLineNumbers = TODO;
435+
parsedOptions.showLineNumbers = getMetaLineNumbersStart(metastring);
433436

434437
// interactive code editor (theme-live-codeblock => Playground)
435438
parsedOptions.live = metastring?.split(' ').includes('live');

0 commit comments

Comments
 (0)