Skip to content

Commit e65970f

Browse files
committed
[update] code highlight
1 parent b587c42 commit e65970f

File tree

5 files changed

+145
-2
lines changed

5 files changed

+145
-2
lines changed

Diff for: main/actions/exported-styles.js

+60
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,64 @@ body mark {
154154
background-color: #058ecd;
155155
color: #fff;
156156
}
157+
.hljs {
158+
display: block;
159+
overflow-x: auto;
160+
padding: 0.5em;
161+
background: #272822;
162+
color: #ddd
163+
}
164+
.hljs-tag,
165+
.hljs-keyword,
166+
.hljs-selector-tag,
167+
.hljs-literal,
168+
.hljs-strong,
169+
.hljs-name {
170+
color: #f92672
171+
}
172+
.hljs-code {
173+
color: #66d9ef
174+
}
175+
.hljs-class .hljs-title {
176+
color: white
177+
}
178+
.hljs-attribute,
179+
.hljs-symbol,
180+
.hljs-regexp,
181+
.hljs-link {
182+
color: #bf79db
183+
}
184+
.hljs-string,
185+
.hljs-bullet,
186+
.hljs-subst,
187+
.hljs-title,
188+
.hljs-section,
189+
.hljs-emphasis,
190+
.hljs-type,
191+
.hljs-built_in,
192+
.hljs-builtin-name,
193+
.hljs-selector-attr,
194+
.hljs-selector-pseudo,
195+
.hljs-addition,
196+
.hljs-variable,
197+
.hljs-template-tag,
198+
.hljs-template-variable {
199+
color: #a6e22e
200+
}
201+
.hljs-comment,
202+
.hljs-quote,
203+
.hljs-deletion,
204+
.hljs-meta {
205+
color: #75715e
206+
}
207+
.hljs-keyword,
208+
.hljs-selector-tag,
209+
.hljs-literal,
210+
.hljs-doctag,
211+
.hljs-title,
212+
.hljs-section,
213+
.hljs-type,
214+
.hljs-selector-id {
215+
font-weight: bold
216+
}
157217
`

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"dependencies": {
6767
"app-root-path": "^2.0.1",
6868
"electron-is-dev": "^0.1.2",
69+
"highlight.js": "^9.11.0",
6970
"next": "^3.0.0-beta5",
7071
"prop-types": "^15.5.10",
7172
"pulse-editor": "^1.0.0",

Diff for: renderer/components/export-button.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ import { Base } from 'pulse-editor/buttons'
33
import { ipcRenderer } from 'electron'
44
import { string, func } from 'prop-types'
55
import Icon from 'react-icons/lib/fa/file-code-o'
6+
import highlight from 'highlight.js'
67
import createParser from '@platzi/markdown'
78

8-
const parser = createParser()
9+
const parser = createParser({
10+
highlight(code, lang) {
11+
if (lang && highlight.getLanguage(lang)) {
12+
return highlight.highlight(lang, code).value;
13+
}
14+
return highlight.highlightAuto(code).value;
15+
}
16+
})
917

1018
export default class NewButton extends Component {
1119
static contextTypes = {

Diff for: renderer/pages/index.js

+71-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Heading,
1616
Youtube
1717
} from 'pulse-editor/buttons'
18+
import highlight from 'highlight.js'
1819

1920
import Save from '../components/save-button'
2021
import Open from '../components/open-button'
@@ -157,7 +158,16 @@ export default class extends Component {
157158

158159
<div className='PulseEditor-content'>
159160
<Field />
160-
<Preview />
161+
<Preview
162+
parser={{
163+
highlight(code, lang) {
164+
if (lang && highlight.getLanguage(lang)) {
165+
return highlight.highlight(lang, code).value;
166+
}
167+
return highlight.highlightAuto(code).value;
168+
}
169+
}}
170+
/>
161171
</div>
162172

163173
<EmojiBar />
@@ -459,6 +469,66 @@ export default class extends Component {
459469
background-color: #058ecd;
460470
color: #fff;
461471
}
472+
.hljs {
473+
display: block;
474+
overflow-x: auto;
475+
padding: 0.5em;
476+
background: #272822;
477+
color: #ddd
478+
}
479+
.hljs-tag,
480+
.hljs-keyword,
481+
.hljs-selector-tag,
482+
.hljs-literal,
483+
.hljs-strong,
484+
.hljs-name {
485+
color: #f92672
486+
}
487+
.hljs-code {
488+
color: #66d9ef
489+
}
490+
.hljs-class .hljs-title {
491+
color: white
492+
}
493+
.hljs-attribute,
494+
.hljs-symbol,
495+
.hljs-regexp,
496+
.hljs-link {
497+
color: #bf79db
498+
}
499+
.hljs-string,
500+
.hljs-bullet,
501+
.hljs-subst,
502+
.hljs-title,
503+
.hljs-section,
504+
.hljs-emphasis,
505+
.hljs-type,
506+
.hljs-built_in,
507+
.hljs-builtin-name,
508+
.hljs-selector-attr,
509+
.hljs-selector-pseudo,
510+
.hljs-addition,
511+
.hljs-variable,
512+
.hljs-template-tag,
513+
.hljs-template-variable {
514+
color: #a6e22e
515+
}
516+
.hljs-comment,
517+
.hljs-quote,
518+
.hljs-deletion,
519+
.hljs-meta {
520+
color: #75715e
521+
}
522+
.hljs-keyword,
523+
.hljs-selector-tag,
524+
.hljs-literal,
525+
.hljs-doctag,
526+
.hljs-title,
527+
.hljs-section,
528+
.hljs-type,
529+
.hljs-selector-id {
530+
font-weight: bold
531+
}
462532
`}</style>
463533
</Editor>
464534
)

Diff for: yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,10 @@ hawk@~3.1.3:
26592659
hoek "2.x.x"
26602660
sntp "1.x.x"
26612661

2662+
highlight.js@^9.11.0:
2663+
version "9.11.0"
2664+
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.11.0.tgz#47f98c7399918700db2caf230ded12cec41a84ae"
2665+
26622666
hmac-drbg@^1.0.0:
26632667
version "1.0.1"
26642668
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"

0 commit comments

Comments
 (0)