Skip to content

Commit 8df4e42

Browse files
committed
add custom codebox
1 parent bc40ac2 commit 8df4e42

21 files changed

+530
-90
lines changed

babel.config.json

+10
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,15 @@
22
"presets": [
33
[ "@babel/preset-env", { "targets": { "node": true } } ],
44
[ "@babel/preset-react" ]
5+
],
6+
"plugins": [
7+
[
8+
"prismjs",
9+
{
10+
"languages": ["js", "css", "yaml", "bash", "batch", "markup", "json", "powershell"],
11+
"plugins": [],
12+
"css": false
13+
}
14+
]
515
]
616
}

content/blog/gpg-signed-releases/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ signatures. You can then run the following command to check the signature by su
8888

8989
If you do not currently have the Adoptium project's public signing key you will get a message such as this:
9090

91-
```output
91+
```text
9292
gpg: directory '/home/sxa/.gnupg' created
9393
gpg: keybox '/home/sxa/.gnupg/pubring.kbx' created
9494
gpg: Signature made Mon Jul 4 18:20:31 2022 UTC
@@ -104,7 +104,7 @@ example to use the Ubuntu key servers run this command:
104104

105105
If you then run the verify command you will get a message indicating that the newly imported key has not been trusted:
106106

107-
```output
107+
```text
108108
gpg: Good signature from "Adoptium GPG Key (DEB/RPM Signing Key)
109109
<[email protected]>" [unknown] gpg: WARNING: This key is not certified
110110
with a trusted signature! gpg: There is no indication that the signature
@@ -122,7 +122,7 @@ gpg --edit-key 3B04D753C9050D9A5D343F39843C48A565F8F04B trust
122122

123123
The verification should then succeed as follows:
124124

125-
```output
125+
```text
126126
gpg: Signature made Mon Jul 4 18:20:31 2022 UTC
127127
gpg: using RSA key 3B04D753C9050D9A5D343F39843C48A565F8F04B
128128
gpg: checking the trustdb

content/blog/jlink-to-produce-own-runtime/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ the ones which your runtime supports with `java --list-modules`. At the time
6262
of writing, using the `jdk-17+35` release, the list of extra modules is as
6363
follows:
6464

65-
```output
65+
```text
6666
jdk.attach
6767
jdk.compiler
6868
jdk.editpad

content/mdx-docs/installation/linux/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Eclipse Temurin RPM and DEB packages are now available for installing on your fa
1414

1515
The following name schema is being used:
1616

17-
```output
17+
```text
1818
temurin-<version>-jdk
1919
e.g temurin-17-jdk or temurin-8-jdk
2020
```
2121

2222
## Deb installation on Debian or Ubuntu
2323

24-
. Ensure the necessary packages are present:
24+
Ensure the necessary packages are present:
2525

2626
```bash
2727
apt install -y wget apt-transport-https

gatsby-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ module.exports = {
140140
}
141141
},
142142
'gatsby-remark-autolink-headers',
143-
'gatsby-remark-prismjs',
143+
// 'gatsby-remark-prismjs',
144144
'gatsby-remark-copy-linked-files',
145145
'gatsby-remark-smartypants'
146146
]

package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"gatsby-remark-smartypants": "^6.4.0",
4040
"gatsby-source-filesystem": "^5.4.0",
4141
"gatsby-transformer-sharp": "^5.4.0",
42-
"highlight.js": "^11.6.0",
4342
"html-to-text": "^9.0.3",
4443
"i18next": "^22.4.9",
4544
"iso-639-1": "^2.1.15",
@@ -70,13 +69,15 @@
7069
"@testing-library/react": "^13.4.0",
7170
"@testing-library/user-event": "^14.4.3",
7271
"@types/gatsbyjs__reach-router": "^1.3.0",
72+
"@types/prismjs": "^1.26.0",
7373
"@types/react": "^18.0.26",
7474
"@types/react-dom": "^18.0.10",
7575
"@types/react-test-renderer": "^18.0.0",
7676
"@types/react-world-flags": "^1.4.2",
7777
"@types/testing-library__jest-dom": "^5.14.5",
7878
"@vitejs/plugin-react": "^3.0.1",
7979
"@vitest/coverage-c8": "^0.27.2",
80+
"babel-plugin-prismjs": "^2.1.0",
8081
"babel-preset-gatsby": "^3.4.0",
8182
"cross-fetch": "^3.1.5",
8283
"gatsby-cli": "^5.4.0",

src/components/CodeBox/InlineCode.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import styles from './index.module.scss';
3+
4+
const InlineCode = ({ children }: React.PropsWithChildren): JSX.Element => (
5+
<code className={styles.code}>{children}</code>
6+
);
7+
8+
export default InlineCode;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import userEvent from '@testing-library/user-event';
3+
import { render, screen } from '@testing-library/react';
4+
import { vi } from 'vitest';
5+
6+
import CodeBox from '../index';
7+
8+
Object.assign(navigator, {
9+
clipboard: {
10+
writeText: vi.fn(),
11+
},
12+
});
13+
14+
const navigatorClipboardSpy = vi.spyOn(navigator.clipboard, 'writeText');
15+
16+
afterEach(() => {
17+
vi.clearAllMocks();
18+
});
19+
20+
describe('Codebox component', (): void => {
21+
it('renders correctly', (): void => {
22+
const textToCopy = <p>text to be copy</p>;
23+
const { container } = render(
24+
<CodeBox>
25+
{{
26+
props: {
27+
className: 'language-html',
28+
children: textToCopy,
29+
},
30+
}}
31+
</CodeBox>
32+
);
33+
expect(container).toMatchSnapshot();
34+
});
35+
36+
it('renders correctly', async () => {
37+
const textToCopy = <p>text to be copy</p>;
38+
39+
render(
40+
<CodeBox>
41+
{{
42+
props: {
43+
className: 'language-html',
44+
children: textToCopy,
45+
},
46+
}}
47+
</CodeBox>
48+
);
49+
50+
navigatorClipboardSpy.mockImplementationOnce(() => Promise.resolve());
51+
52+
const buttonElement = screen.getByText('copy');
53+
userEvent.click(buttonElement);
54+
55+
await screen.findByText('copied');
56+
57+
expect(navigatorClipboardSpy).toHaveBeenCalledTimes(1);
58+
expect(navigatorClipboardSpy).toHaveBeenCalledWith(textToCopy.toString());
59+
});
60+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import userEvent from '@testing-library/user-event';
3+
import { render, screen } from '@testing-library/react';
4+
5+
import InlineCode from '../InlineCode';
6+
7+
describe('InlineCode component', (): void => {
8+
it('renders correctly', (): void => {
9+
const { container } = render(
10+
<InlineCode>
11+
This is some sample code
12+
</InlineCode>
13+
);
14+
expect(container).toMatchSnapshot();
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Vitest Snapshot v1
2+
3+
exports[`Codebox component > renders correctly 1`] = `
4+
<div>
5+
<pre
6+
class="_pre_4cf629 language-html"
7+
>
8+
<div
9+
class="_top_4cf629"
10+
>
11+
<span>
12+
HTML
13+
</span>
14+
<button
15+
type="button"
16+
>
17+
copy
18+
</button>
19+
</div>
20+
<div
21+
class="_content_4cf629"
22+
>
23+
[object Object]
24+
</div>
25+
</pre>
26+
</div>
27+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Vitest Snapshot v1
2+
3+
exports[`InlineCode component > renders correctly 1`] = `
4+
<div>
5+
<code
6+
class="_code_4cf629"
7+
>
8+
This is some sample code
9+
</code>
10+
</div>
11+
`;

0 commit comments

Comments
 (0)