Skip to content

Commit 2d46d12

Browse files
committed
Codeblock theme of markdown preview
1 parent 44f270f commit 2d46d12

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

browser/components/MarkdownEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MarkdownEditor extends React.Component {
9696
style={previewStyle}
9797
fontSize={config.preview.fontSize}
9898
fontFamily={config.preview.fontFamily}
99-
codeBlockTheme={config.preview.theme}
99+
codeBlockTheme={config.preview.codeBlockTheme}
100100
codeBlockFontFamily={config.editor.fontFamily}
101101
lineNumber={config.preview.lineNumber}
102102
ref='preview'

browser/components/MarkdownPreview.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { PropTypes } from 'react'
22
import markdown from 'browser/lib/markdown'
33
import _ from 'lodash'
4+
import hljsTheme from 'browser/lib/hljsThemes'
45

56
const markdownStyle = require('!!css!stylus?sourceMap!./markdown.styl')[0][1]
67
const { shell } = require('electron')
@@ -44,6 +45,7 @@ export default class MarkdownPreview extends React.Component {
4445
prevProps.fontFamily !== this.props.fontFamily ||
4546
prevProps.fontSize !== this.props.fontSize ||
4647
prevProps.codeBlockFontFamily !== this.props.codeBlockFontFamily ||
48+
prevProps.codeBlockTheme !== this.props.codeBlockTheme ||
4749
prevProps.lineNumber !== this.props.lineNumber
4850
) this.rewriteIframe()
4951
}
@@ -53,13 +55,14 @@ export default class MarkdownPreview extends React.Component {
5355
el.removeEventListener('click', goExternal)
5456
})
5557

56-
let { value, fontFamily, fontSize, codeBlockFontFamily, lineNumber } = this.props
58+
let { value, fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme } = this.props
5759
fontFamily = _.isString(fontFamily) && fontFamily.trim().length > 0
5860
? [fontFamily].concat(defaultFontFamily)
5961
: defaultFontFamily
6062
codeBlockFontFamily = _.isString(codeBlockFontFamily) && codeBlockFontFamily.trim().length > 0
6163
? [codeBlockFontFamily].concat(defaultCodeBlockFontFamily)
6264
: defaultCodeBlockFontFamily
65+
codeBlockTheme = hljsTheme().some((theme) => theme.name === codeBlockTheme) ? codeBlockTheme : 'xcode'
6366

6467
this.refs.root.contentWindow.document.head.innerHTML = `
6568
<style>
@@ -86,7 +89,7 @@ export default class MarkdownPreview extends React.Component {
8689
opacity: 0.5;
8790
}
8891
</style>
89-
<link rel="stylesheet" href="../node_modules/highlight.js/styles/xcode.css" id="hljs-css">
92+
<link rel="stylesheet" href="../node_modules/highlight.js/styles/${codeBlockTheme}.css">
9093
<link rel="stylesheet" href="../resources/katex.min.css">
9194
`
9295
this.refs.root.contentWindow.document.body.innerHTML = markdown(value)

browser/components/markdown.styl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ code
198198
margin-left 2px
199199
pre
200200
padding 1em !important
201-
background-color #f7f7f7 !important
201+
border solid 1px alpha(borderColor, 0.5)
202202
border-radius 5px
203203
overflow-x auto
204204
margin 0 0 1em
205205
line-height 1.35
206206
code
207207
margin 0
208+
background-color inherit
208209
padding 0
209210
border none
210211
border-radius 0

0 commit comments

Comments
 (0)