34 | {({ className, style, tokens, getLineProps, getTokenProps }) => (
35 |
36 | {cleanTokens(tokens).map((line, i) => {
37 | let lineClass = {};
38 |
39 | let isDiff = false;
40 |
41 | if (line[0] && line[0].content.length && line[0].content[0] === '+') {
42 | lineClass = { backgroundColor: 'rgba(76, 175, 80, 0.2)' };
43 | isDiff = true;
44 | } else if (line[0] && line[0].content.length && line[0].content[0] === '-') {
45 | lineClass = { backgroundColor: 'rgba(244, 67, 54, 0.2)' };
46 | isDiff = true;
47 | } else if (line[0] && line[0].content === '' && line[1] && line[1].content === '+') {
48 | lineClass = { backgroundColor: 'rgba(76, 175, 80, 0.2)' };
49 | isDiff = true;
50 | } else if (line[0] && line[0].content === '' && line[1] && line[1].content === '-') {
51 | lineClass = { backgroundColor: 'rgba(244, 67, 54, 0.2)' };
52 | isDiff = true;
53 | }
54 | const lineProps = getLineProps({ line, key: i });
55 |
56 | lineProps.style = lineClass;
57 | const diffStyle = {
58 | userSelect: 'none',
59 | MozUserSelect: '-moz-none',
60 | WebkitUserSelect: 'none',
61 | };
62 |
63 | let splitToken;
64 |
65 | return (
66 |
67 | {line.map((token, key) => {
68 | if (isDiff) {
69 | if (
70 | (key === 0 || key === 1) &
71 | (token.content.charAt(0) === '+' || token.content.charAt(0) === '-')
72 | ) {
73 | if (token.content.length > 1) {
74 | splitToken = {
75 | types: ['template-string', 'string'],
76 | content: token.content.slice(1),
77 | };
78 | const firstChar = {
79 | types: ['operator'],
80 | content: token.content.charAt(0),
81 | };
82 |
83 | return (
84 |
85 |
89 |
90 |
91 | );
92 | } else {
93 | return ;
94 | }
95 | }
96 | }
97 | return ;
98 | })}
99 |
100 | );
101 | })}
102 |
103 | )}
104 |
105 | );
106 | }
107 | };
108 |
109 | export default CodeBlock;
110 |
--------------------------------------------------------------------------------
/src/components/mdxComponents/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import styled from '@emotion/styled';
3 |
4 | import CodeBlock from './codeBlock';
5 | import AnchorTag from './anchor';
6 |
7 | const StyledPre = styled('pre')`
8 | padding: 16px;
9 | background: ${props => props.theme.colors.preFormattedText};
10 | `;
11 |
12 | export default {
13 | h1: props => (
14 |