Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade syntax highlighting dependencies, prism-react-renderer to v2, react-live to v4 #9316

Merged
merged 25 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0b713f0
chore: upgrade `prism-react-renderer` to v2
harryzcy Sep 17, 2023
549fbb3
chore: update usage of `prism-react-renderer` api
harryzcy Sep 17, 2023
f174bd7
fix(website): use new `prism-react-renderer` api
harryzcy Sep 17, 2023
37ea8b0
fix: update prism import path
harryzcy Sep 17, 2023
51d65df
fix: update function type and use prism-react-renderer exposed types
harryzcy Sep 17, 2023
de2e168
fix: bug with prism-react-renderer
harryzcy Sep 17, 2023
1ae1629
fix: revert version in examples
harryzcy Sep 19, 2023
42ae5fe
fix: revert less restrictive typing
harryzcy Sep 19, 2023
f7d1336
fix: typing for `PrismThemeEntry`
harryzcy Sep 19, 2023
59a8c79
chore: bump `react-live`
harryzcy Sep 19, 2023
05cbb63
fix: typing errors caused by `react-live`
harryzcy Sep 19, 2023
9e47fa0
docs: update website on theme usage
harryzcy Sep 19, 2023
56fbd1b
fix: missing closing quote
harryzcy Sep 19, 2023
000ee6d
chore: upgrade react-live again
harryzcy Sep 19, 2023
f2874aa
fix: eslint rule that doesn't need to be disabled
harryzcy Sep 20, 2023
3763ed5
fix: pages build issue
harryzcy Sep 25, 2023
5f7abda
chore: Merge branch 'main' into prism-react-renderer-v2
harryzcy Sep 25, 2023
7b603e6
fix: error TS2578: Unused "@ts-expect-error" directive
harryzcy Sep 25, 2023
f4cac9e
fix: ts-expect-error issue again
harryzcy Sep 25, 2023
df94ec3
Merge branch 'main' into prism-react-renderer-v2
slorber Oct 6, 2023
e062e62
regen lockfile
slorber Oct 6, 2023
4140168
prism-react-renderer 2.1.0
slorber Oct 6, 2023
6abdf22
Use vendored prism, remove prism props
slorber Oct 6, 2023
00c4947
Add missing prism languages
slorber Oct 6, 2023
bcc6bdf
add scss language
slorber Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/classic-typescript/docusaurus.config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/classic-typescript/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions examples/classic/docusaurus.config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/classic/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@docusaurus/preset-classic": "3.0.0-beta.0",
"@mdx-js/react": "^2.3.0",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"prism-react-renderer": "^2.0.6",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
// There are various equivalent ways to declare your Docusaurus config.
// See: https://docusaurus.io/docs/api/docusaurus-config

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const {themes} = require('prism-react-renderer');

const lightCodeTheme = themes.github;
const darkCodeTheme = themes.dracula;

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@docusaurus/preset-classic": "3.0.0-beta.0",
"@mdx-js/react": "^2.3.0",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"prism-react-renderer": "^2.0.6",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lodash": "^4.17.21",
"nprogress": "^0.2.0",
"postcss": "^8.4.26",
"prism-react-renderer": "^1.3.5",
"prism-react-renderer": "^2.0.6",
"prismjs": "^1.29.0",
"react-router-dom": "^5.3.4",
"rtlcss": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
normalizeThemeConfig,
normalizePluginOptions,
} from '@docusaurus/utils-validation';
import theme from 'prism-react-renderer/themes/github';
import darkTheme from 'prism-react-renderer/themes/dracula';
import {themes} from 'prism-react-renderer';
import {ThemeConfigSchema, DEFAULT_CONFIG, validateOptions} from '../options';
import type {Options, PluginOptions} from '@docusaurus/theme-classic';
import type {ThemeConfig} from '@docusaurus/theme-common';
Expand All @@ -36,8 +35,8 @@ describe('themeConfig', () => {
it('accepts valid theme config', () => {
const userConfig = {
prism: {
theme,
darkTheme,
theme: themes.github,
darkTheme: themes.dracula,
defaultLanguage: 'javaSCRIPT',
additionalLanguages: ['koTLin', 'jaVa'],
magicComments: [
Expand Down Expand Up @@ -579,7 +578,7 @@ describe('themeConfig', () => {
const prismConfig = {
prism: {
additionalLanguages: ['kotlin', 'java'],
theme: darkTheme,
theme: themes.dracula,
magicComments: [],
},
};
Expand All @@ -590,7 +589,7 @@ describe('themeConfig', () => {
const prismConfig2 = {
prism: {
additionalLanguages: [],
theme: darkTheme,
theme: themes.dracula,
magicComments: [
{
className: 'a',
Expand All @@ -606,7 +605,7 @@ describe('themeConfig', () => {
const prismConfig3 = {
prism: {
additionalLanguages: [],
theme: darkTheme,
theme: themes.dracula,
magicComments: [
{
className: 'a',
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/src/deps.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/docusaurus-theme-classic/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import defaultPrismTheme from 'prism-react-renderer/themes/palenight';
import {themes} from 'prism-react-renderer';
import {Joi, URISchema} from '@docusaurus/utils-validation';
import type {Options, PluginOptions} from '@docusaurus/theme-classic';
import type {ThemeConfig} from '@docusaurus/theme-common';
Expand All @@ -14,6 +14,7 @@ import type {
OptionValidationContext,
} from '@docusaurus/types';

const defaultPrismTheme = themes.palenight;
const DEFAULT_DOCS_CONFIG: ThemeConfig['docs'] = {
versionPersistence: 'localStorage',
sidebar: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import Prism from 'prism-react-renderer/prism';
import {Prism} from 'prism-react-renderer';
import prismIncludeLanguages from '@theme/prism-include-languages';

prismIncludeLanguages(Prism);
21 changes: 9 additions & 12 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,20 @@ declare module '@theme/CodeBlock/Content/String' {
}

declare module '@theme/CodeBlock/Line' {
import type {ComponentProps} from 'react';
import type Highlight from 'prism-react-renderer';

// Lib does not make this easy
type RenderProps = Parameters<
ComponentProps<typeof Highlight>['children']
>[0];
type GetLineProps = RenderProps['getLineProps'];
type GetTokenProps = RenderProps['getTokenProps'];
type Token = RenderProps['tokens'][number][number];
import type {
LineInputProps,
LineOutputProps,
Token,
TokenInputProps,
TokenOutputProps,
} from 'prism-react-renderer';

export interface Props {
readonly line: Token[];
readonly classNames: string[] | undefined;
readonly showLineNumbers: boolean;
readonly getLineProps: GetLineProps;
readonly getTokenProps: GetTokenProps;
readonly getLineProps: (input: LineInputProps) => LineOutputProps;
readonly getTokenProps: (input: TokenInputProps) => TokenOutputProps;
}

export default function CodeBlockLine(props: Props): JSX.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
containsLineNumbers,
useCodeWordWrap,
} from '@docusaurus/theme-common/internal';
import Highlight, {defaultProps, type Language} from 'prism-react-renderer';
import {Highlight, type Language} from 'prism-react-renderer';
import Prism from 'prismjs';
import Line from '@theme/CodeBlock/Line';
import CopyButton from '@theme/CodeBlock/CopyButton';
import WordWrapButton from '@theme/CodeBlock/WordWrapButton';
Expand Down Expand Up @@ -74,16 +75,17 @@ export default function CodeBlockString({
{title && <div className={styles.codeBlockTitle}>{title}</div>}
<div className={styles.codeBlockContent}>
<Highlight
{...defaultProps}
prism={Prism}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the issue, we used the "vendored prism library" and should keep using it so passing a prism instance is not needed now. I'll remove it.

theme={prismTheme}
code={code}
language={(language ?? 'text') as Language}>
{({className, tokens, getLineProps, getTokenProps}) => (
{({className, style, tokens, getLineProps, getTokenProps}) => (
<pre
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
tabIndex={0}
ref={wordWrap.codeBlockRef}
className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
className={clsx(className, styles.codeBlock, 'thin-scrollbar')}
style={style}>
<code
className={clsx(
styles.codeBlockLines,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/react-router-config": "*",
"clsx": "^1.2.1",
"parse-numeric-range": "^1.3.0",
"prism-react-renderer": "^1.3.5",
"prism-react-renderer": "^2.0.6",
slorber marked this conversation as resolved.
Show resolved Hide resolved
"tslib": "^2.6.0",
"utility-types": "^3.10.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function parseLines(
}

export function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties {
const mapping: {[name: keyof PrismTheme['plain']]: string} = {
const mapping: {[name: string]: string} = {
slorber marked this conversation as resolved.
Show resolved Hide resolved
color: '--prism-color',
backgroundColor: '--prism-background-color',
};
Expand Down
4 changes: 3 additions & 1 deletion website/src/utils/prismDark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import darkTheme from 'prism-react-renderer/themes/vsDark/index.cjs.js';
import {themes} from 'prism-react-renderer';

const darkTheme = themes.vsDark;

export default {
plain: {
Expand Down
4 changes: 3 additions & 1 deletion website/src/utils/prismLight.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import lightTheme from 'prism-react-renderer/themes/github/index.cjs.js';
import {themes} from 'prism-react-renderer';

const lightTheme = themes.github;

export default {
...lightTheme,
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13636,11 +13636,19 @@ pretty-time@^1.1.0:
resolved "https://registry.yarnpkg.com/pretty-time/-/pretty-time-1.1.0.tgz#ffb7429afabb8535c346a34e41873adf3d74dd0e"
integrity sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==

prism-react-renderer@^1.0.1, prism-react-renderer@^1.3.5:
prism-react-renderer@^1.0.1:
harryzcy marked this conversation as resolved.
Show resolved Hide resolved
version "1.3.5"
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.5.tgz#786bb69aa6f73c32ba1ee813fbe17a0115435085"
integrity sha512-IJ+MSwBWKG+SM3b2SUfdrhC+gu01QkV2KmRQgREThBfSQRoufqRfxfHUxpG1WcaFjP+kojcFyO9Qqtpgt3qLCg==

prism-react-renderer@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-2.0.6.tgz#24f0c1afbc07d4a268677fb05e77079ea80b6a2f"
integrity sha512-ERzmAI5UvrcTw5ivfEG20/dYClAsC84eSED5p9X3oKpm0xPV4A5clFK1mp7lPIdKmbLnQYsPTGiOI7WS6gWigw==
dependencies:
"@types/prismjs" "^1.26.0"
clsx "^1.2.1"

prismjs@^1.29.0:
version "1.29.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
Expand Down