/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React from "react"; import { useThemeConfig, usePrismTheme } from "@docusaurus/theme-common"; import { parseCodeBlockTitle, parseLanguage, parseLines, containsLineNumbers, useCodeWordWrap, } from "@docusaurus/theme-common/internal"; import Container from "@theme/ApiExplorer/ApiCodeBlock/Container"; import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton"; import ExpandButton from "@theme/ApiExplorer/ApiCodeBlock/ExpandButton"; import Line from "@theme/ApiExplorer/ApiCodeBlock/Line"; import WordWrapButton from "@theme/ApiExplorer/ApiCodeBlock/WordWrapButton"; import type { Props } from "@theme/CodeBlock/Content/String"; import clsx from "clsx"; import { Highlight, Language } from "prism-react-renderer"; export default function CodeBlockString({ children, className: blockClassName = "", metastring, title: titleProp, showLineNumbers: showLineNumbersProp, language: languageProp, }: Props): React.JSX.Element { const { prism: { defaultLanguage, magicComments }, } = useThemeConfig(); const language = languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage; const prismTheme = usePrismTheme(); const wordWrap = useCodeWordWrap(); // We still parse the metastring in case we want to support more syntax in the // future. Note that MDX doesn't strip quotes when parsing metastring: // "title=\"xyz\"" => title: "\"xyz\"" const title = parseCodeBlockTitle(metastring) || titleProp; const { lineClassNames, code } = parseLines(children, { metastring, language, magicComments, }); const showLineNumbers = showLineNumbersProp ?? containsLineNumbers(metastring); return ( {title && (
{title}
)}
{({ className, tokens, getLineProps, getTokenProps }) => (
              
                {tokens.map((line, i) => (
                  
                ))}
              
            
)}
{(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( wordWrap.toggle()} isEnabled={wordWrap.isEnabled} /> )}
); }