/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/index.tsx
81 строка
2 KB
Sébastien Lorber
refactor: various v4 code cleanups and soft breaking changes (#12104)
01 июн 2026, 18:48
Не верифицирован
01 июн 2026, 18:48
183fc6f
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React, {type ComponentProps, type ReactNode} from 'react'; import clsx from 'clsx'; import {useCodeBlockContext} from '@docusaurus/theme-common/internal'; import {usePrismTheme} from '@docusaurus/theme-common'; import {Highlight} from 'prism-react-renderer'; import type {Props} from '@theme/CodeBlock/Content'; import Line from '@theme/CodeBlock/Line'; import styles from './styles.module.css'; function Pre({className, ref, ...props}: ComponentProps<'pre'>) { return ( <pre ref={ref} /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */ tabIndex={0} {...props} className={clsx(className, styles.codeBlock, 'thin-scrollbar')} /> ); } function Code(props: ComponentProps<'code'>) { const {metadata} = useCodeBlockContext(); return ( <code {...props} className={clsx( props.className, styles.codeBlockLines, metadata.lineNumbersStart !== undefined && styles.codeBlockLinesWithNumbering, )} style={{ ...props.style, counterReset: metadata.lineNumbersStart === undefined ? undefined : `line-count ${metadata.lineNumbersStart - 1}`, }} /> ); } export default function CodeBlockContent({ className: classNameProp, }: Props): ReactNode { const {metadata, wordWrap} = useCodeBlockContext(); const prismTheme = usePrismTheme(); const {code, language, lineNumbersStart, lineClassNames} = metadata; return ( <Highlight theme={prismTheme} code={code} language={language}> {({className, style, tokens: lines, getLineProps, getTokenProps}) => ( <Pre ref={wordWrap.codeBlockRef} className={clsx(classNameProp, className)} style={style}> <Code> {lines.map((line, i) => ( <Line key={i} line={line} getLineProps={getLineProps} getTokenProps={getTokenProps} classNames={lineClassNames[i]} showLineNumbers={lineNumbersStart !== undefined} /> ))} </Code> </Pre> )} </Highlight> ); }