import React, { Suspense } from "react";
import type { HighlightedCode, AnnotationHandler } from "codehike/code";
import { InnerLine, Pre } from "codehike/code";
import { Theme } from "@code-hike/lighter";
import { Text } from "../../writer/Text"
import { CodeTheme, type CodeThemeBlockProps } from "../CodeTheme";
import * as cn from "./Code.styles";
import { CodeLoader } from "./CodeLoader";
import { Icon } from "src/writer/Icon";
import {useCodeSampleAnalytics} from "../CodeSample/CodeSampleAnalytics";
export interface CodeProps {
codeblocks?: CodeThemeBlockProps[];
theme?: Theme
children: React.ReactNode
}
export function Code(props: CodeProps) {
return
is the element that scrolls, so it's the one that has to be focusable - name it
// with the same `meta || lang` the tabs use, otherwise it reads as an unlabelled region
const label = codeblock?.meta || codeblock?.lang
let description: React.ReactNode | null = null
if (props.descriptionHead || props.descriptionContent) {
description =
{props.descriptionIcon ? : <_DefaultDescriptionIcon />}
{props.descriptionHead}
{props.descriptionContent}
}
return
{description}
}
/**
* FOR SOME REASONS FOR SINGLE CODE BLOCKS LAST TOKEN IS EMPTY STRING
*
* @todo: fix this
*/
function fixLastToken(codeblock: HighlightedCode) {
const lastToken = codeblock.tokens[codeblock.tokens.length - 1]
if (typeof lastToken === 'string' && (lastToken === ' ' || lastToken === '\n')) {
codeblock.tokens.pop()
}
}
function _DefaultDescriptionIcon() {
return
}