diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx index ce137ffa2..ebee87245 100644 --- a/src/components/CodeBlock.tsx +++ b/src/components/CodeBlock.tsx @@ -167,7 +167,6 @@ export function CodeBlock({ setCodeElement(
pre]:h-full [&>pre]:rounded-none' : '', )} @@ -181,7 +180,7 @@ export function CodeBlock({ return (
-
+
{tabs.map((tab) => { return ( -
+
{children.map((child, index) => { const tab = tabs[index] if (!tab) return null @@ -76,14 +76,14 @@ const Tab = ({ title={tab.name} type="button" onClick={() => setActiveSlug(tab.slug)} - className={`inline-flex items-center justify-center gap-2 px-3 py-1.5 -mb-[1px] border-b-2 text-sm font-bold transition-colors ${ + className={`inline-flex items-center justify-center gap-2 px-3 py-1.5 -mb-[1px] border-b-2 text-sm font-bold transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 rounded-t-md overflow-y-none ${ activeSlug === tab.slug - ? 'border-current text-current' + ? 'border-current text-current bg-gray-100 dark:bg-gray-900' : 'border-transparent text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200' }`} > {options[0] ? ( - + ) : null} {tab.name} diff --git a/src/styles/app.css b/src/styles/app.css index 8fc5d9d7d..ede8c6e0e 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -772,10 +772,6 @@ html.dark .shiki.vitesse-dark span[style*='color: #51597D'] { @apply bg-gray-100 dark:bg-gray-900; } -[data-tab] > .codeblock:not(:only-child) pre { - @apply dark:bg-white/5! bg-black/5!; -} - [data-tab] > .markdown-alert [aria-label] svg { @apply stroke-current fill-current; } diff --git a/src/utils/markdown/plugins/collectHeadings.ts b/src/utils/markdown/plugins/collectHeadings.ts index 21e020b9d..c912d1736 100644 --- a/src/utils/markdown/plugins/collectHeadings.ts +++ b/src/utils/markdown/plugins/collectHeadings.ts @@ -1,5 +1,7 @@ import { visit } from 'unist-util-visit' import { toString } from 'hast-util-to-string' +import type { Element, Root } from 'hast' +import type { VFile } from 'vfile' import { isHeading } from './helpers' @@ -9,19 +11,44 @@ export type MarkdownHeading = { level: number } +const isTabsAncestor = (ancestor: Element) => { + if (ancestor.type !== 'element') { + console.log('skip') + return false + } + + if (ancestor.tagName !== 'md-comment-component') { + console.log('skip') + return false + } + + const component = ancestor.properties?.['data-component'] + console.log('dont skip', component) + return typeof component === 'string' && component.toLowerCase() === 'tabs' +} + export function rehypeCollectHeadings( - tree, - file, + _tree: Root, + _file: VFile, initialHeadings?: MarkdownHeading[], ) { const headings = initialHeadings ?? [] - return function collectHeadings(tree, file: any) { - visit(tree, 'element', (node) => { + return function collectHeadings(tree: Root, file?: VFile) { + visit(tree, 'element', (node: Element, _index, ancestors) => { if (!isHeading(node)) { return } + if (Array.isArray(ancestors)) { + const insideTabs = ancestors.some((ancestor) => + isTabsAncestor(ancestor as Element), + ) + if (insideTabs) { + return + } + } + const id = typeof node.properties?.id === 'string' ? node.properties.id : '' if (!id) { diff --git a/src/utils/markdown/plugins/parseCommentComponents.ts b/src/utils/markdown/plugins/parseCommentComponents.ts index 62d0154e9..ccf823b73 100644 --- a/src/utils/markdown/plugins/parseCommentComponents.ts +++ b/src/utils/markdown/plugins/parseCommentComponents.ts @@ -1,6 +1,6 @@ import { unified } from 'unified' import rehypeParse from 'rehype-parse' -import { visit } from 'unist-util-visit' +import { SKIP, visit } from 'unist-util-visit' const COMPONENT_PREFIX = '::' const START_PREFIX = '::start:'