refactor(v2): add @theme-init alias to give access to initial components (#2464)

This commit is contained in:
Alexey Pyltsyn 2020-05-17 17:47:05 +03:00 committed by GitHub
parent d145f03ea8
commit d910ff118e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 339 deletions

View file

@ -10,11 +10,10 @@
import React, {useEffect, useState, useRef} from 'react';
import classnames from 'classnames';
import Highlight, {defaultProps} from 'prism-react-renderer';
import defaultTheme from 'prism-react-renderer/themes/palenight';
import Clipboard from 'clipboard';
import rangeParser from 'parse-numeric-range';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useThemeContext from '@theme/hooks/useThemeContext';
import usePrismTheme from '@theme/hooks/usePrismTheme';
import styles from './styles.module.css';
@ -113,10 +112,7 @@ export default ({children, className: languageClassName, metastring}) => {
let highlightLines = [];
let codeBlockTitle = '';
const {isDarkTheme} = useThemeContext();
const lightModeTheme = prism.theme || defaultTheme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
const prismTheme = usePrismTheme();
if (metastring && highlightLinesRangeRegex.test(metastring)) {
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];