1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Merge branch 'master' into add-markdownlint-rules-form

This commit is contained in:
roottool
2019-05-06 20:53:59 +09:00
5 changed files with 95 additions and 48 deletions

View File

@@ -255,7 +255,7 @@ export default class MarkdownPreview extends React.Component {
return return
} }
// No contextMenu was passed to us -> execute our own link-opener // No contextMenu was passed to us -> execute our own link-opener
if (event.target.tagName.toLowerCase() === 'a') { if (event.target.tagName.toLowerCase() === 'a' && event.target.getAttribute('href')) {
const href = event.target.href const href = event.target.href
const isLocalFile = href.startsWith('file:') const isLocalFile = href.startsWith('file:')
if (isLocalFile) { if (isLocalFile) {
@@ -670,14 +670,14 @@ export default class MarkdownPreview extends React.Component {
) )
} }
GetCodeThemeLink (theme) { GetCodeThemeLink (name) {
theme = consts.THEMES.some(_theme => _theme === theme) && const theme = consts.THEMES.find(theme => theme.name === name)
theme !== 'default'
? theme if (theme) {
: 'elegant' return `${appPath}/${theme.path}`
return theme.startsWith('solarized') } else {
? `${appPath}/node_modules/codemirror/theme/solarized.css` return `${appPath}/node_modules/codemirror/theme/elegant.css`
: `${appPath}/node_modules/codemirror/theme/${theme}.css` }
} }
rewriteIframe () { rewriteIframe () {
@@ -735,9 +735,9 @@ export default class MarkdownPreview extends React.Component {
} }
) )
codeBlockTheme = consts.THEMES.some(_theme => _theme === codeBlockTheme) codeBlockTheme = consts.THEMES.find(theme => theme.name === codeBlockTheme)
? codeBlockTheme
: 'default' const codeBlockThemeClassName = codeBlockTheme ? codeBlockTheme.className : 'cm-s-default'
_.forEach( _.forEach(
this.refs.root.contentWindow.document.querySelectorAll('.code code'), this.refs.root.contentWindow.document.querySelectorAll('.code code'),
@@ -760,14 +760,11 @@ export default class MarkdownPreview extends React.Component {
}) })
} }
} }
el.parentNode.appendChild(copyIcon) el.parentNode.appendChild(copyIcon)
el.innerHTML = '' el.innerHTML = ''
if (codeBlockTheme.indexOf('solarized') === 0) { el.parentNode.className += ` ${codeBlockThemeClassName}`
const [refThema, color] = codeBlockTheme.split(' ')
el.parentNode.className += ` cm-s-${refThema} cm-s-${color}`
} else {
el.parentNode.className += ` cm-s-${codeBlockTheme}`
}
CodeMirror.runMode(content, syntax.mime, el, { CodeMirror.runMode(content, syntax.mime, el, {
tabSize: indentSize tabSize: indentSize
}) })

View File

@@ -3,14 +3,43 @@ const fs = require('sander')
const { remote } = require('electron') const { remote } = require('electron')
const { app } = remote const { app } = remote
const themePath = process.env.NODE_ENV === 'production' const CODEMIRROR_THEME_PATH = 'node_modules/codemirror/theme'
? path.join(app.getAppPath(), './node_modules/codemirror/theme') const CODEMIRROR_EXTRA_THEME_PATH = 'extra_scripts/codemirror/theme'
: require('path').resolve('./node_modules/codemirror/theme')
const themes = fs.readdirSync(themePath) const isProduction = process.env.NODE_ENV === 'production'
.map((themePath) => { const paths = [
return themePath.substring(0, themePath.lastIndexOf('.')) isProduction ? path.join(app.getAppPath(), CODEMIRROR_THEME_PATH) : path.resolve(CODEMIRROR_THEME_PATH),
}) isProduction ? path.join(app.getAppPath(), CODEMIRROR_EXTRA_THEME_PATH) : path.resolve(CODEMIRROR_EXTRA_THEME_PATH)
themes.splice(themes.indexOf('solarized'), 1, 'solarized dark', 'solarized light') ]
const themes = paths
.map(directory => fs.readdirSync(directory).map(file => {
const name = file.substring(0, file.lastIndexOf('.'))
return {
name,
path: path.join(directory.split(/\//g).slice(-3).join('/'), file),
className: `cm-s-${name}`
}
}))
.reduce((accumulator, value) => accumulator.concat(value), [])
.sort((a, b) => a.name.localeCompare(b.name))
themes.splice(themes.findIndex(({ name }) => name === 'solarized'), 1, {
name: 'solarized dark',
path: `${CODEMIRROR_THEME_PATH}/solarized.css`,
className: `cm-s-solarized cm-s-dark`
}, {
name: 'solarized light',
path: `${CODEMIRROR_THEME_PATH}/solarized.css`,
className: `cm-s-solarized cm-s-light`
})
themes.splice(0, 0, {
name: 'default',
path: `${CODEMIRROR_THEME_PATH}/elegant.css`,
className: `cm-s-default`
})
const snippetFile = process.env.NODE_ENV !== 'test' const snippetFile = process.env.NODE_ENV !== 'test'
? path.join(app.getPath('userData'), 'snippets.json') ? path.join(app.getPath('userData'), 'snippets.json')
@@ -35,7 +64,7 @@ const consts = {
'Dodger Blue', 'Dodger Blue',
'Violet Eggplant' 'Violet Eggplant'
], ],
THEMES: ['default'].concat(themes), THEMES: themes,
SNIPPET_FILE: snippetFile, SNIPPET_FILE: snippetFile,
DEFAULT_EDITOR_FONT_FAMILY: [ DEFAULT_EDITOR_FONT_FAMILY: [
'Monaco', 'Monaco',

View File

@@ -135,16 +135,12 @@ function get () {
document.head.appendChild(editorTheme) document.head.appendChild(editorTheme)
} }
config.editor.theme = consts.THEMES.some((theme) => theme === config.editor.theme) const theme = consts.THEMES.find(theme => theme.name === config.editor.theme)
? config.editor.theme
: 'default'
if (config.editor.theme !== 'default') { if (theme) {
if (config.editor.theme.startsWith('solarized')) { editorTheme.setAttribute('href', `../${theme.path}`)
editorTheme.setAttribute('href', '../node_modules/codemirror/theme/solarized.css') } else {
} else { config.editor.theme = 'default'
editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + config.editor.theme + '.css')
}
} }
} }
@@ -180,16 +176,11 @@ function set (updates) {
editorTheme.setAttribute('rel', 'stylesheet') editorTheme.setAttribute('rel', 'stylesheet')
document.head.appendChild(editorTheme) document.head.appendChild(editorTheme)
} }
const newTheme = consts.THEMES.some((theme) => theme === newConfig.editor.theme)
? newConfig.editor.theme
: 'default'
if (newTheme !== 'default') { const newTheme = consts.THEMES.find(theme => theme.name === newConfig.editor.theme)
if (newTheme.startsWith('solarized')) {
editorTheme.setAttribute('href', '../node_modules/codemirror/theme/solarized.css') if (newTheme) {
} else { editorTheme.setAttribute('href', `../${newTheme.path}`)
editorTheme.setAttribute('href', '../node_modules/codemirror/theme/' + newTheme + '.css')
}
} }
ipcRenderer.send('config-renew', { ipcRenderer.send('config-renew', {

View File

@@ -131,8 +131,13 @@ class UiTab extends React.Component {
const newCodemirrorTheme = this.refs.editorTheme.value const newCodemirrorTheme = this.refs.editorTheme.value
if (newCodemirrorTheme !== codemirrorTheme) { if (newCodemirrorTheme !== codemirrorTheme) {
checkHighLight.setAttribute('href', `../node_modules/codemirror/theme/${newCodemirrorTheme.split(' ')[0]}.css`) const theme = consts.THEMES.find(theme => theme.name === newCodemirrorTheme)
if (theme) {
checkHighLight.setAttribute('href', `../${theme.path}`)
}
} }
this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, () => { this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, () => {
const {ui, editor, preview} = this.props.config const {ui, editor, preview} = this.props.config
this.currentConfig = {ui, editor, preview} this.currentConfig = {ui, editor, preview}
@@ -358,7 +363,7 @@ class UiTab extends React.Component {
> >
{ {
themes.map((theme) => { themes.map((theme) => {
return (<option value={theme} key={theme}>{theme}</option>) return (<option value={theme.name} key={theme.name}>{theme.name}</option>)
}) })
} }
</select> </select>
@@ -696,7 +701,7 @@ class UiTab extends React.Component {
> >
{ {
themes.map((theme) => { themes.map((theme) => {
return (<option value={theme} key={theme}>{theme}</option>) return (<option value={theme.name} key={theme.name}>{theme.name}</option>)
}) })
} }
</select> </select>

25
extra_scripts/codemirror/theme/nord.css vendored Normal file
View File

@@ -0,0 +1,25 @@
/* Theme: nord */
.cm-s-nord.CodeMirror { color: #d8dee9; }
.cm-s-nord.CodeMirror { background: #2e3440; }
.cm-s-nord .CodeMirror-cursor { color: #d8dee9; border-color: #d8dee9; }
.cm-s-nord .CodeMirror-activeline-background { background: #434c5e52 !important; }
.cm-s-nord .CodeMirror-selected { background: undefined; }
.cm-s-nord .cm-comment { color: #4c566a; }
.cm-s-nord .cm-string { color: #a3be8c; }
.cm-s-nord .cm-string-2 { color: #8fbcbb; }
.cm-s-nord .cm-property { color: #8fbcbb; }
.cm-s-nord .cm-qualifier { color: #8fbcbb; }
.cm-s-nord .cm-tag { color: #81a1c1; }
.cm-s-nord .cm-attribute { color: #8fbcbb; }
.cm-s-nord .cm-number { color: #b48ead; }
.cm-s-nord .cm-keyword { color: #81a1c1; }
.cm-s-nord .cm-operator { color: #81a1c1; }
.cm-s-nord .cm-error { background: #bf616a; color: #d8dee9; }
.cm-s-nord .cm-invalidchar { background: #bf616a; color: #d8dee9; }
.cm-s-nord .cm-variable { color: #d8dee9; }
.cm-s-nord .cm-variable-2 { color: #8fbcbb; }
.cm-s-nord .CodeMirror-gutters {
background: #3b4252;
color: #d8dee9;
}