fix: code block filename not showing, consistent code block styling

This commit is contained in:
Usman Baig
2026-03-29 01:07:21 +01:00
parent 627613dc13
commit b1ed7518b1
2 changed files with 10 additions and 13 deletions

View File

@@ -17,26 +17,23 @@ import { getIntegrationGuide } from '@/lib/integration-content'
import { IntegrationGuide } from '@/components/IntegrationGuide' import { IntegrationGuide } from '@/components/IntegrationGuide'
// * ─── MDX Components ──────────────────────────────────────────── // * ─── MDX Components ────────────────────────────────────────────
// Maps markdown code fences to CodeBlock. The `filename` meta is passed // rehype-mdx-code-props passes meta (e.g. filename="app.tsx") as props
// as a prop via rehype-mdx-code-props (e.g. ```tsx filename="app.tsx"). // on the <pre> element. We intercept <pre> to extract filename and render CodeBlock.
const mdxComponents = { const mdxComponents = {
pre: ({ children }: { children: React.ReactNode }) => children, pre: ({ children, filename, ...props }: {
code: ({ children, className, filename, ...props }: { children: React.ReactElement
children: React.ReactNode
className?: string
filename?: string filename?: string
[key: string]: unknown [key: string]: unknown
}) => { }) => {
// Block code (inside <pre>) has className like "language-tsx" const code = children?.props?.children
if (className?.startsWith('language-') || filename) { if (typeof code === 'string') {
return ( return (
<CodeBlock filename={filename || 'code'}> <CodeBlock filename={filename || 'code'}>
{String(children).replace(/\n$/, '')} {code.replace(/\n$/, '')}
</CodeBlock> </CodeBlock>
) )
} }
// Inline code return <pre {...props}>{children}</pre>
return <code className={className} {...props}>{children}</code>
}, },
} }

View File

@@ -7,7 +7,7 @@
*/ */
import Link from 'next/link' import Link from 'next/link'
import { ArrowLeftIcon, ArrowRightIcon } from '@ciphera-net/ui' import { ArrowLeftIcon, ArrowRightIcon, CodeBlock } from '@ciphera-net/ui'
import { type ReactNode } from 'react' import { type ReactNode } from 'react'
import { type Integration, getIntegration, categoryLabels } from '@/lib/integrations' import { type Integration, getIntegration, categoryLabels } from '@/lib/integrations'
@@ -92,7 +92,7 @@ export function IntegrationGuide({ integration, children }: IntegrationGuideProp
Detect rage clicks and dead clicks by adding the frustration tracking Detect rage clicks and dead clicks by adding the frustration tracking
add-on after the core script: add-on after the core script:
</p> </p>
<pre><code>{`<script defer src="https://pulse.ciphera.net/script.frustration.js"></script>`}</code></pre> <CodeBlock filename="index.html">{`<script defer src="https://pulse.ciphera.net/script.frustration.js"></script>`}</CodeBlock>
<p> <p>
No extra configuration needed. Add <code>data-no-rage</code> or{' '} No extra configuration needed. Add <code>data-no-rage</code> or{' '}
<code>data-no-dead</code> to disable individual signals. <code>data-no-dead</code> to disable individual signals.