Skip to content

Commit

Permalink
feat: update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Mar 27, 2024
1 parent 95f26a5 commit e0d6764
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/client/theme-default/builtins/CodeGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ function CodeGroup(props: React.PropsWithChildren) {
const usefulChildren = toArray(children).filter(
(child) =>
typeof child === 'object' &&
child.key &&
typeof child.type === 'function' &&
child.type?.name === SourceCode.name,
) as React.ReactElement<SourceCodeProps>[];

const items = usefulChildren.map<Item>((child) => {
const items = usefulChildren.map<Item>((child, idx) => {
const { lang, title } = child.props ?? {};

return {
key: child.key as string,
key: String(child.key ?? idx),
label: title || lang || 'txt', // fallback to txt if no lang and title
children: child,
};
Expand Down
3 changes: 0 additions & 3 deletions src/loaders/markdown/transformer/rehypeEnhancedTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ export default function rehypeEnhancedTag(): Transformer<Root> {
const highlightLines = node.children[0].data
?.highlightLines as number[];

const uniqueKey = Math.random().toString(36).substring(7);

parent!.children.splice(i!, 1, {
type: 'element',
tagName: 'SourceCode',
properties: {
...rehypeCodeMeta(node.children[0].data?.meta as string),
lang,
key: uniqueKey,
},
data: node.children[0].data,
JSXAttributes: [
Expand Down

0 comments on commit e0d6764

Please sign in to comment.