Skip to content

Commit 16f91c9

Browse files
Kirill BolotskyPepe Cano
authored andcommitted
refactor: initial migration step from gatsby-remark-prismjs to prismjs-react-renderer
- Refactored Code, CodeGroup components - Added CodeInline component - removed custom elements replacement in favor native mdx renderer - removed gatsby-remark-prismjs and prismjs from project deps - removed global prism styles - adjusted 02 Installation.md to work under new conditions Side: - added "hooks" exception to no-unresolved eslint rule
1 parent 2d8a403 commit 16f91c9

File tree

19 files changed

+220
-262
lines changed

19 files changed

+220
-262
lines changed

gatsby-config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ const plugins = [
6464
options: {
6565
extensions: ['.md'],
6666
gatsbyRemarkPlugins: [
67-
{
68-
resolve: 'gatsby-remark-prismjs',
69-
options: {
70-
showLineNumbers: true,
71-
noInlineHighlight: true,
72-
},
73-
},
7467
{
7568
resolve: 'gatsby-remark-relative-images',
7669
},

package-lock.json

Lines changed: 4 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@
5050
"gatsby-plugin-svgr-svgo": "^1.0.12",
5151
"gatsby-remark-copy-linked-files": "^2.3.19",
5252
"gatsby-remark-images": "^3.3.33",
53-
"gatsby-remark-prismjs": "^3.5.16",
5453
"gatsby-remark-relative-images": "^2.0.2",
5554
"gatsby-source-filesystem": "^2.3.34",
5655
"gatsby-transformer-json": "^2.4.14",
5756
"gatsby-transformer-sharp": "^2.5.17",
5857
"node-sass": "^4.14.1",
59-
"prismjs": "^1.21.0",
58+
"prism-react-renderer": "^1.1.1",
6059
"qs": "^6.9.1",
6160
"react": "^16.10.2",
6261
"react-clipboard.js": "^2.0.16",

src/components/blocks/html-content/html-content.module.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@
7070
}
7171
}
7272

73-
p code,
74-
ol code {
75-
font-family: $font-family-secondary;
76-
padding: 3px 5px 2px;
77-
}
78-
7973
table {
8074
border: 1px solid $color-additional-2;
8175
border-collapse: collapse;
@@ -103,12 +97,6 @@
10397
line-height: $line-height-sm;
10498
vertical-align: baseline;
10599
line-height: 25px;
106-
107-
code {
108-
font-size: $font-size-code;
109-
color: $color-accent-primary;
110-
font-family: $font-family-secondary;
111-
}
112100
}
113101
}
114102
& > * + * {

src/components/blocks/html-content/html-content.view.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import PropTypes from 'prop-types';
2+
import React, { useRef } from 'react';
3+
4+
import styles from './html-content.module.scss';
5+
16
import './html-content.scss';
27
import { MDXProvider } from '@mdx-js/react';
38
import { MDXRenderer } from 'gatsby-plugin-mdx';
49
import { useElementsReplacement } from 'hooks';
5-
import React, { useRef } from 'react';
610

711
import styles from './html-content.module.scss';
812

@@ -35,3 +39,17 @@ export const HtmlContent = ({
3539
</MDXProvider>
3640
);
3741
};
42+
43+
HtmlContent.propTypes = {
44+
content: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
45+
className: PropTypes.string,
46+
componentsForCustomReplacement: PropTypes.shape({}),
47+
componentsForNativeReplacement: PropTypes.shape({}),
48+
};
49+
50+
HtmlContent.defaultProps = {
51+
content: null,
52+
className: undefined,
53+
componentsForCustomReplacement: {},
54+
componentsForNativeReplacement: {},
55+
};

src/components/shared/blockquote/blockquote.module.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ blockquote {
1212
p {
1313
margin: 0;
1414
}
15-
span[class='code-inline'] {
16-
background-color: $color-additional-2;
15+
& span[class='code-inline'] {
16+
background: $color-additional-2;
17+
}
18+
& div[class^='with-copy-button'] {
19+
margin-top: 15px;
1720
}
1821
}
1922

src/components/shared/code-group/code-group.view.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/components/shared/code-group/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import PropTypes from 'prop-types';
2+
import React, { useState } from 'react';
3+
import { getRandomKey } from 'utils';
4+
5+
import Code from './code';
6+
import styles from './code-group.module.scss';
7+
8+
const CodeGroup = ({ children, labels, lineNumbers }) => {
9+
const [currentIndex, setCurrentIndex] = useState(0);
10+
const randomKey = getRandomKey();
11+
return (
12+
<div className={styles.wrapper}>
13+
{labels && labels.length ? (
14+
<div className={styles.header}>
15+
{labels.map((label, i) => (
16+
<div
17+
key={`lb-${i}`}
18+
className={`${styles.codeTab} ${
19+
i === currentIndex ? styles.codeTab_active : ''
20+
}`}
21+
onClick={() => setCurrentIndex(i)}
22+
onKeyPress={() => setCurrentIndex(i)}
23+
role={'button'}
24+
tabIndex={i}
25+
>
26+
{label}
27+
</div>
28+
))}
29+
</div>
30+
) : null}
31+
<style>
32+
{`.${styles.itemsContainer}.${randomKey} > div:nth-child(${
33+
currentIndex + 1
34+
}) { display: block; }`}
35+
</style>
36+
<div className={`${styles.itemsContainer} ${randomKey}`}>
37+
{React.Children.map(children, (child, i) => (
38+
<Code showLineNumbers={lineNumbers[i]} key={i}>
39+
{child.props.children}
40+
</Code>
41+
))}
42+
</div>
43+
</div>
44+
);
45+
};
46+
47+
CodeGroup.propTypes = {
48+
children: PropTypes.node,
49+
labels: PropTypes.arrayOf(PropTypes.string),
50+
lineNumbers: PropTypes.arrayOf(PropTypes.bool),
51+
};
52+
53+
CodeGroup.defaultProps = {
54+
children: null,
55+
labels: [],
56+
lineNumbers: [],
57+
};
58+
59+
export default CodeGroup;
File renamed without changes.

0 commit comments

Comments
 (0)