diff --git a/src/components/CodeMirrorStyle.tsx b/src/components/CodeMirrorStyle.tsx index 80aa3b0121..ebc49b664f 100644 --- a/src/components/CodeMirrorStyle.tsx +++ b/src/components/CodeMirrorStyle.tsx @@ -10,6 +10,9 @@ const ThemeLink = ({ theme }: ThemeLinkProps) => { if (theme == null || theme === 'default') { return null } + if (theme === 'solarized-dark') { + theme = 'solarized' + } return ( { : this.props.keyMap this.codeMirror = CodeMirror.fromTextArea(this.textAreaRef.current!, { ...defaultCodeMirrorOptions, - theme: this.props.theme == null ? 'default' : this.props.theme, + theme: getCodeMirrorTheme(this.props.theme), indentWithTabs: this.props.indentType === 'tab', indentUnit: indentSize, tabSize: indentSize, @@ -77,7 +77,7 @@ class CodeEditor extends React.Component { this.codeMirror.setValue(this.props.value) } if (this.props.theme !== prevProps.theme) { - this.codeMirror.setOption('theme', this.props.theme) + this.codeMirror.setOption('theme', getCodeMirrorTheme(this.props.theme)) } if ( this.props.fontSize !== prevProps.fontSize || diff --git a/src/components/atoms/MarkdownPreviewer.tsx b/src/components/atoms/MarkdownPreviewer.tsx index f9e4f0461b..d6d488f7a0 100644 --- a/src/components/atoms/MarkdownPreviewer.tsx +++ b/src/components/atoms/MarkdownPreviewer.tsx @@ -45,10 +45,7 @@ function isElement(node: Node, tagName: string): node is Element { if (node == null) { return false } - if (node.tagName !== tagName) { - return false - } - return true + return node.tagName === tagName } function rehypeCodeMirrorAttacher(options: Partial) { @@ -72,7 +69,11 @@ function rehypeCodeMirrorAttacher(options: Partial) { parent.properties.className != null ? [...parent.properties.className] : [] - classNames.push(`cm-s-${theme}`, 'CodeMirror') + if (theme === 'solarized-dark') { + classNames.push(`cm-s-solarized`, `cm-s-dark`, 'CodeMirror') + } else { + classNames.push(`cm-s-${theme}`, 'CodeMirror') + } if (lang != null) { classNames.push('language-' + lang) } diff --git a/src/lib/CodeMirror.ts b/src/lib/CodeMirror.ts index ab97dba2a6..7792fd1bcc 100644 --- a/src/lib/CodeMirror.ts +++ b/src/lib/CodeMirror.ts @@ -19,6 +19,12 @@ export async function requireMode(mode: string) { dispatchModeLoad() } +export function getCodeMirrorTheme(theme?: string) { + if (theme == null) return 'default' + if (theme === 'solarized-dark') return 'solarized dark' + return theme +} + function loadMode(_CodeMirror: any) { const memoizedModeResult = new Map() function findModeByMIME(mime: string) { @@ -57,6 +63,7 @@ export const themes = [ 'neo', 'paraiso-light', 'solarized', + 'solarized-dark', 'twilight', 'zenburn', '3024-night',