Skip to content

Commit

Permalink
normalize styles, rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmann committed Jan 19, 2024
1 parent 7ad0eef commit 6a4c673
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/markdown/remark/src/shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ export async function createShikiHighlighter({
node.tagName = 'code';
}

const classValue = normalizeMaybeArray(node.properties.class) ?? '';

// Cast to string as shikiji will always pass them as strings instead of any other types
const styleValue = (node.properties.style as string) ?? '';
const classValue = normalizePropAsString(node.properties.class) ?? '';
const styleValue = normalizePropAsString(node.properties.style) ?? '';

// Replace "shiki" class naming with "astro-code"
node.properties.class = classValue.replace(/shiki/g, 'astro-code');
Expand Down Expand Up @@ -131,7 +129,7 @@ export async function createShikiHighlighter({
};
}

function normalizeMaybeArray(value: Properties[string]): string | null {
function normalizePropAsString(value: Properties[string]): string | null {
return Array.isArray(value) ? value.join(' ') : (value as string | null);
}

Expand Down

0 comments on commit 6a4c673

Please sign in to comment.