Skip to content

Commit

Permalink
refactor(v2): clean up code blocks (#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored Oct 29, 2020
1 parent f085560 commit cf99862
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, {useEffect, useState, useRef} from 'react';
import clsx from 'clsx';
import Highlight, {defaultProps} from 'prism-react-renderer';
import Highlight, {defaultProps, Language} from 'prism-react-renderer';
import copy from 'copy-text-to-clipboard';
import rangeParser from 'parse-numeric-range';
import usePrismTheme from '@theme/hooks/usePrismTheme';
Expand Down Expand Up @@ -131,7 +131,9 @@ export default ({
}

let language =
languageClassName && languageClassName.replace(/language-/, '');
languageClassName &&
// Force Prism's language union type to `any` because it does not contain all available languages
((languageClassName.replace(/language-/, '') as Language) as any);

if (!language && prism.defaultLanguage) {
language = prism.defaultLanguage;
Expand Down Expand Up @@ -197,7 +199,6 @@ export default ({
key={String(mounted)}
theme={prismTheme}
code={code}
// @ts-expect-error: prism-react-renderer doesn't export Language type
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<>
Expand Down Expand Up @@ -240,9 +241,7 @@ export default ({
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={clsx(styles.copyButton, {
[styles.copyButtonWithTitle]: codeBlockTitle,
})}
className={clsx(styles.copyButton)}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>
Expand Down

0 comments on commit cf99862

Please sign in to comment.