Skip to content

Commit feb9ae5

Browse files
authored
Merge pull request #172 from codebtech/chore/wp66
New syntax highlighter
2 parents c5abc1a + d3e9a20 commit feb9ae5

18 files changed

+489
-533
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"prepare": "husky",
1414
"start": "wp-scripts start",
1515
"test:e2e": "wp-scripts test-playwright",
16+
"test:e2e:debug": "wp-scripts test-playwright --ui",
1617
"test:js": "wp-scripts test-unit-js",
18+
"test:js:update": "wp-scripts test-unit-js --updateSnapshot",
1719
"test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.ts",
1820
"test:performance:merge-reports": "playwright merge-reports --reporter tests/performance/config/performance-reporter.ts ./blob-report",
1921
"test:performance:results": "node tests/performance/cli/results.js",
@@ -29,6 +31,7 @@
2931
},
3032
"dependencies": {
3133
"@testing-library/user-event": "^14.5.2",
34+
"@types/react-highlight": "^0.12.8",
3235
"@wordpress/api-fetch": "^6.48.0",
3336
"@wordpress/components": "^27.1.0",
3437
"@wordpress/data": "^9.23.0",
@@ -39,7 +42,9 @@
3942
"dotenv": "^16.4.5",
4043
"react": "18.2.0",
4144
"react-dom": "18.2.0",
42-
"react-syntax-highlighter": "^15.5.0",
45+
"react-highlight": "^0.15.0",
46+
"react-highlight-syntax": "^1.2.1",
47+
"react-syntax-highlighter": "^15.4.3",
4348
"react-test-renderer": "^18.2.0",
4449
"ts-loader": "^9.5.1",
4550
"typescript": "^5.4.2"
@@ -50,7 +55,7 @@
5055
"@testing-library/react": "14.2.2",
5156
"@types/jest": "^29.5.12",
5257
"@types/node": "^20.12.5",
53-
"@types/react-syntax-highlighter": "^15.5.11",
58+
"@types/react-syntax-highlighter": "15.5.6",
5459
"@types/wordpress__components": "^23.0.11",
5560
"@wordpress/e2e-test-utils-playwright": "^0.22.0",
5661
"@wordpress/env": "^9.7.0",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
use: {
1818
baseURL: process.env.WP_BASE_URL,
1919
trace: 'on-first-retry',
20-
permissions: ['clipboard-read'],
20+
permissions: ['clipboard-write', 'clipboard-read'],
2121
},
2222

2323
projects: [

src/components/snippets/JsSnippet.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Snippet from './Snippet';
22
import { useMemo } from '@wordpress/element';
33
import { __ } from '@wordpress/i18n';
4-
import Clipboard from '../common/Clipboard';
54

65
const JsSnippet = ({ flag }: { flag: string }) => {
76
const jsSnippet = useMemo(() => {
@@ -18,8 +17,7 @@ domReady(function () {
1817
return (
1918
<div className="mr-feature-flag-js-snippet-container">
2019
<h3>{__('JavaScript Snippet', 'codeb-feature-flags')}</h3>
21-
<Clipboard text={jsSnippet} />
22-
<Snippet data={jsSnippet} language={'typescript'} />
20+
<Snippet data={jsSnippet} language="JavaScript" />
2321
</div>
2422
);
2523
};

src/components/snippets/PhpSnippet.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Snippet from './Snippet';
22
import { useMemo } from '@wordpress/element';
33
import { __ } from '@wordpress/i18n';
4-
import Clipboard from '../common/Clipboard';
54

65
const PhpSnippet = ({ flag }: { flag: string }) => {
76
const phpSnippet = useMemo(() => {
@@ -13,8 +12,7 @@ if ( class_exists( '\\CodeB\\FeatureFlags\\Flag' ) && Flag::is_enabled( '${flag}
1312
return (
1413
<div className="mr-feature-flag-php-snippet-container">
1514
<h3>{__('PHP Snippet', 'codeb-feature-flags')}</h3>
16-
<Clipboard text={phpSnippet} />
17-
<Snippet data={phpSnippet} language={'php'} />
15+
<Snippet data={phpSnippet} language="PHP" />
1816
</div>
1917
);
2018
};

src/components/snippets/Snippet.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import SyntaxHighlighter from 'react-syntax-highlighter';
2-
import { a11yDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
1+
import ReactHighlightSyntax from 'react-highlight-syntax';
2+
import type { Language } from 'react-highlight-syntax';
33

4-
const Snippet = ({
5-
data,
6-
language,
7-
}: {
8-
data: string;
9-
language: string;
10-
}): JSX.Element => {
4+
const Snippet = ({ data, language }: { data: string; language: Language }) => {
115
return (
12-
<SyntaxHighlighter language={language} style={a11yDark}>
6+
<ReactHighlightSyntax
7+
theme={'Base16Darcula'}
8+
language={language}
9+
copy={true}
10+
copyBtnTheme={'Dark'}
11+
>
1312
{data}
14-
</SyntaxHighlighter>
13+
</ReactHighlightSyntax>
1514
);
1615
};
1716

src/components/snippets/TsSupport.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useMemo } from '@wordpress/element';
22
import { __ } from '@wordpress/i18n';
3-
import Clipboard from '../common/Clipboard';
4-
53
import Snippet from './Snippet';
64

75
const TsSupport = (): JSX.Element => {
@@ -30,8 +28,7 @@ export {};`;
3028
<span className="codeb-feature-flags-slug"> src</span> directory
3129
) and add the following declaration.
3230
</p>
33-
<Clipboard text={tsSnippet} />
34-
<Snippet data={tsSnippet} language={'typescript'} />
31+
<Snippet data={tsSnippet} language="TypeScript" />
3532
</div>
3633
);
3734
};

0 commit comments

Comments
 (0)