-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.js
118 lines (103 loc) · 3.14 KB
/
diff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React from 'react';
import { render } from 'react-dom';
import SyntaxHighlighter from '../src/index';
import docco from '../src/styles/hljs/docco';
import ExamplesLinks from './examples-links';
const CODE = `const woah = fun => fun + 1;
const dude = woah(2) + 3;
function thisIsAFunction() {
return [1,2,3].map(n => n + 1).filter(n !== 3);
}
console.log('making up fake code is really hard');
function itIs() {
return 'no seriously really it is';
}`;
const ADDED = [1, 2];
const REMOVED = [6];
function DiffHighlight() {
return (
<div className="demo__root demo__root--diff">
<header>
<h1>React Syntax Highlighter Demo</h1>
<ExamplesLinks />
</header>
<main>
<div className="example__container">
<div style={{ flex: 1, width: '100%', flexDirection: 'column' }}>
<SyntaxHighlighter
style={docco}
wrapLines={true}
showLineNumbers={true}
lineProps={lineNumber => {
let style = { display: 'block' };
if (ADDED.includes(lineNumber)) {
style.backgroundColor = '#dbffdb';
} else if (REMOVED.includes(lineNumber)) {
style.backgroundColor = '#ffecec';
}
return { style };
}}
>
{CODE}
</SyntaxHighlighter>
<h2>The code to make this happen</h2>
<SyntaxHighlighter
style={docco}
wrapLines={true}
language="javascript"
>
{`import React from 'react';
import { render } from 'react-dom';
import SyntaxHighlighter from '../';
import docco from '../styles/docco';
const CODE = \`const woah = fun => fun + 1;
const dude = woah(2) + 3;
function thisIsAFunction() {
return [1,2,3].map(n => n + 1).filter(n !== 3);
}
console.log('making up fake code is really hard');
function itIs() {
return 'no seriously really it is';
}\`;
const ADDED = [1, 2];
const REMOVED = [6];
function DiffHighlight() {
const h1Style = {
fontSize: 42,
color: 'aliceblue'
};
return (
<div>
<h1 style={h1Style}>React SyntaxHighlighter</h1>
<div style={{paddingTop: 20, display: 'flex'}}>
<div style={{flex: 1, width: '100%', flexDirection: 'column'}}>
<SyntaxHighlighter
style={docco}
wrapLines={true}
lineProps={lineNumber => {
let style = { display: 'block' };
if (ADDED.includes(lineNumber)) {
style.backgroundColor = '#dbffdb';
} else if (REMOVED.includes(lineNumber)) {
style.backgroundColor = '#ffecec';
}
return { style };
}}
>
{CODE}
</SyntaxHighlighter>
</div>
</div>
</div>
);
}
render(<DiffHighlight />, document.getElementById('app'));
`}
</SyntaxHighlighter>
</div>
</div>
</main>
</div>
);
}
render(<DiffHighlight />, document.getElementById('app'));