Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add anchor links to h3 elements

Vasek Mlejnsky69d4f9fffbd0
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index 11e595ad8..6fef05e4c 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -1,4 +1,3 @@
-import Script from 'next/script'
import { Metadata } from 'next'
import { Analytics } from '@vercel/analytics/react'
@@ -72,9 +71,6 @@ export default async function RootLayout({ children }) {
</Suspense>
<Analytics />
</Providers>
-
- <Script src="https://js.chatlio.com/widget.js" strategy="lazyOnload" />
- <chatlio-widget widgetid={process.env.NEXT_PUBLIC_CHATLIO_WIDGET_ID} disable-favicon-badge></chatlio-widget>
</body>
</html>
)
diff --git a/apps/web/src/components/Heading.tsx b/apps/web/src/components/Heading.tsx
index ec46f7e9a..01126a121 100644
--- a/apps/web/src/components/Heading.tsx
+++ b/apps/web/src/components/Heading.tsx
@@ -17,7 +17,7 @@ function AnchorIcon(props: React.ComponentPropsWithoutRef<'svg'>) {
aria-hidden="true"
{...props}
>
- <path d="m6.5 11.5-.964-.964a3.535 3.535 0 1 1 5-5l.964.964m2 2 .964.964a3.536 3.536 0 0 1-5 5L8.5 13.5m0-5 3 3"/>
+ <path d="m6.5 11.5-.964-.964a3.535 3.535 0 1 1 5-5l.964.964m2 2 .964.964a3.536 3.536 0 0 1-5 5L8.5 13.5m0-5 3 3" />
</svg>
)
}
@@ -31,7 +31,7 @@ function Eyebrow({ tag, label }: { tag?: string; label?: string }) {
<div className="flex items-center gap-x-3">
{tag && <Tag>{tag}</Tag>}
{tag && label && (
- <span className="h-0.5 w-0.5 rounded-full bg-zinc-300 dark:bg-zinc-600"/>
+ <span className="h-0.5 w-0.5 rounded-full bg-zinc-300 dark:bg-zinc-600" />
)}
{label && <span className="font-mono text-xs text-zinc-400">{label}</span>}
</div>
@@ -39,10 +39,10 @@ function Eyebrow({ tag, label }: { tag?: string; label?: string }) {
}
function Anchor({
- id,
- inView,
- children,
- }: {
+ id,
+ inView,
+ children,
+}: {
id: string
inView: boolean
children: React.ReactNode
@@ -58,7 +58,7 @@ function Anchor({
<div
className="group/anchor block h-5 w-5 rounded-lg bg-zinc-50 ring-1 ring-inset ring-zinc-300 transition hover:ring-zinc-500 dark:bg-zinc-800 dark:ring-zinc-700 dark:hover:bg-zinc-700 dark:hover:ring-zinc-600">
<AnchorIcon
- className="h-5 w-5 stroke-zinc-500 transition dark:stroke-zinc-400 dark:group-hover/anchor:stroke-white"/>
+ className="h-5 w-5 stroke-zinc-500 transition dark:stroke-zinc-400 dark:group-hover/anchor:stroke-white" />
</div>
</div>
)}
@@ -68,13 +68,13 @@ function Anchor({
}
export function Heading<Level extends 2 | 3>({
- children,
- tag,
- label,
- level,
- anchor = true,
- ...props
- }: React.ComponentPropsWithoutRef<`h${Level}`> & {
+ children,
+ tag,
+ label,
+ level,
+ anchor = true,
+ ...props
+}: React.ComponentPropsWithoutRef<`h${Level}`> & {
id: string
tag?: string
label?: string
@@ -89,12 +89,16 @@ export function Heading<Level extends 2 | 3>({
const inView = useInView(ref, {
margin: `${remToPx(-3.5)}px 0px 0px 0px`,
amount: 'all',
+
})
useEffect(() => {
if (level === 2) {
registerHeading({ id: props.id, ref, offsetRem: tag || label ? 8 : 6 })
}
+ if (level === 3) {
+ registerHeading({ id: props.id, ref, offsetRem: 2 })
+ }
})
return (
diff --git a/apps/web/src/components/mdx.tsx b/apps/web/src/components/mdx.tsx
index 86b483a25..3d4596987 100644
--- a/apps/web/src/components/mdx.tsx
+++ b/apps/web/src/components/mdx.tsx
@@ -28,6 +28,17 @@ export const h2 = function H2(
)
}
+export const h3 = function H3(
+ props: Omit<React.ComponentPropsWithoutRef<typeof Heading>, 'level'>,
+) {
+ return (
+ <Heading
+ level={3}
+ {...props}
+ />
+ )
+}
+
function InfoIcon(props: React.ComponentPropsWithoutRef<'svg'>) {
return (
<svg
diff --git a/apps/web/src/mdx/rehype.mjs b/apps/web/src/mdx/rehype.mjs
index 48aaafb78..d1fc3327e 100644
--- a/apps/web/src/mdx/rehype.mjs
+++ b/apps/web/src/mdx/rehype.mjs
@@ -194,6 +194,9 @@ function rehypeSlugify() {
if (node.tagName === 'h2' && !node.properties.id) {
node.properties.id = slugify(toString(node))
}
+ if (node.tagName === 'h3' && !node.properties.id) {
+ node.properties.id = slugify(toString(node))
+ }
})
}
}
@@ -232,7 +235,7 @@ function getSections(node) {
let sections = []
for (let child of node.children ?? []) {
- if (child.type === 'element' && child.tagName === 'h2') {
+ if (child.type === 'element' && (child.tagName === 'h2' || child.tagName === 'h3')) {
sections.push(`{
title: ${JSON.stringify(toString(child))},
id: ${JSON.stringify(child.properties.id)},