Skip to content

Commit 67d9b9e

Browse files
committed
satisfy types
1 parent d57d7e4 commit 67d9b9e

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

packages/mdx/lib/shiki.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ const LANGUAGE_PREFIX = 'language-';
1313
const CODE_TAG = 'code';
1414
const PRE_TAG = 'pre';
1515

16+
type Metadata = undefined | { meta: string };
17+
1618
/**
1719
* Extracts a parameter value from a meta string
1820
*/
1921
export function getMetaParameter(
20-
meta?: string | null,
22+
data: Metadata,
2123
key?: string
2224
): string | undefined {
23-
if (!meta || !key) return undefined;
25+
if (!data?.meta || !key) return undefined;
2426

25-
const match = meta.match(new RegExp(`${key}="([^"]*)"`));
27+
const match = data?.meta.match(new RegExp(`${key}="([^"]*)"`));
2628
const value = match?.[1];
2729

2830
return value?.length ? value : undefined;
@@ -65,10 +67,10 @@ export function processCodeTabs(tree: Node): void {
6567

6668
// Extract meta information
6769
const displayName =
68-
getMetaParameter(codeElement.data?.meta, 'displayName')?.replaceAll(
69-
'|',
70-
''
71-
) || '';
70+
getMetaParameter(
71+
codeElement.data as Metadata,
72+
'displayName'
73+
)?.replaceAll('|', '') || '';
7274
displayNames.push(displayName);
7375

7476
// Extract language from class name
@@ -86,7 +88,9 @@ export function processCodeTabs(tree: Node): void {
8688
codeTabsChildren.push(preElement);
8789

8890
// Check if this tab should be the default active one
89-
if (getMetaParameter(codeElement.data?.meta, 'active') === 'true') {
91+
if (
92+
getMetaParameter(codeElement.data as Metadata, 'active') === 'true'
93+
) {
9094
defaultTab = String(codeTabsChildren.length - 1);
9195
}
9296

@@ -155,7 +159,7 @@ export function processCodeHighlighting(tree: Node): void {
155159

156160
// Add copy button if specified
157161
const showCopyButton = getMetaParameter(
158-
codeElement.data?.meta,
162+
codeElement.data as Metadata,
159163
'showCopyButton'
160164
);
161165
if (showCopyButton === 'true' || showCopyButton === 'false') {

0 commit comments

Comments
 (0)