/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx
42 строки
1 KB
Sébastien Lorber
refactor(theme): introduce CodeBlockContextProvider + split into smaller components (#11062)
04 апр 2025, 21:11
Не верифицирован
04 апр 2025, 21:11
31b279f
Код
Авторство
О чём код?
/** * 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 ReactNode} from 'react'; import {useThemeConfig} from '@docusaurus/theme-common'; import { CodeBlockContextProvider, type CodeBlockMetadata, createCodeBlockMetadata, useCodeWordWrap, } from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/CodeBlock/Content/String'; import CodeBlockLayout from '@theme/CodeBlock/Layout'; function useCodeBlockMetadata(props: Props): CodeBlockMetadata { const {prism} = useThemeConfig(); return createCodeBlockMetadata({ code: props.children, className: props.className, metastring: props.metastring, magicComments: prism.magicComments, defaultLanguage: prism.defaultLanguage, language: props.language, title: props.title, showLineNumbers: props.showLineNumbers, }); } // TODO Docusaurus v4: move this component at the root? export default function CodeBlockString(props: Props): ReactNode { const metadata = useCodeBlockMetadata(props); const wordWrap = useCodeWordWrap(); return ( <CodeBlockContextProvider metadata={metadata} wordWrap={wordWrap}> <CodeBlockLayout /> </CodeBlockContextProvider> ); }