Skip to content

Commit

Permalink
[update] code highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed May 26, 2017
1 parent b587c42 commit e65970f
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 2 deletions.
60 changes: 60 additions & 0 deletions main/actions/exported-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,64 @@ body mark {
background-color: #058ecd;
color: #fff;
}
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #272822;
color: #ddd
}
.hljs-tag,
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-strong,
.hljs-name {
color: #f92672
}
.hljs-code {
color: #66d9ef
}
.hljs-class .hljs-title {
color: white
}
.hljs-attribute,
.hljs-symbol,
.hljs-regexp,
.hljs-link {
color: #bf79db
}
.hljs-string,
.hljs-bullet,
.hljs-subst,
.hljs-title,
.hljs-section,
.hljs-emphasis,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #a6e22e
}
.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
color: #75715e
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-title,
.hljs-section,
.hljs-type,
.hljs-selector-id {
font-weight: bold
}
`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dependencies": {
"app-root-path": "^2.0.1",
"electron-is-dev": "^0.1.2",
"highlight.js": "^9.11.0",
"next": "^3.0.0-beta5",
"prop-types": "^15.5.10",
"pulse-editor": "^1.0.0",
Expand Down
10 changes: 9 additions & 1 deletion renderer/components/export-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import { Base } from 'pulse-editor/buttons'
import { ipcRenderer } from 'electron'
import { string, func } from 'prop-types'
import Icon from 'react-icons/lib/fa/file-code-o'
import highlight from 'highlight.js'
import createParser from '@platzi/markdown'

const parser = createParser()
const parser = createParser({
highlight(code, lang) {
if (lang && highlight.getLanguage(lang)) {
return highlight.highlight(lang, code).value;
}
return highlight.highlightAuto(code).value;
}
})

export default class NewButton extends Component {
static contextTypes = {
Expand Down
72 changes: 71 additions & 1 deletion renderer/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Heading,
Youtube
} from 'pulse-editor/buttons'
import highlight from 'highlight.js'

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

<div className='PulseEditor-content'>
<Field />
<Preview />
<Preview
parser={{
highlight(code, lang) {
if (lang && highlight.getLanguage(lang)) {
return highlight.highlight(lang, code).value;
}
return highlight.highlightAuto(code).value;
}
}}
/>
</div>

<EmojiBar />
Expand Down Expand Up @@ -459,6 +469,66 @@ export default class extends Component {
background-color: #058ecd;
color: #fff;
}
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #272822;
color: #ddd
}
.hljs-tag,
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-strong,
.hljs-name {
color: #f92672
}
.hljs-code {
color: #66d9ef
}
.hljs-class .hljs-title {
color: white
}
.hljs-attribute,
.hljs-symbol,
.hljs-regexp,
.hljs-link {
color: #bf79db
}
.hljs-string,
.hljs-bullet,
.hljs-subst,
.hljs-title,
.hljs-section,
.hljs-emphasis,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #a6e22e
}
.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
color: #75715e
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-title,
.hljs-section,
.hljs-type,
.hljs-selector-id {
font-weight: bold
}
`}</style>
</Editor>
)
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,10 @@ hawk@~3.1.3:
hoek "2.x.x"
sntp "1.x.x"

highlight.js@^9.11.0:
version "9.11.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.11.0.tgz#47f98c7399918700db2caf230ded12cec41a84ae"

hmac-drbg@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
Expand Down

0 comments on commit e65970f

Please sign in to comment.