Skip to content

Commit 85eaa64

Browse files
committed
fix(markdown): proper bg color for code block depending on theme
1 parent 5591ddb commit 85eaa64

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/renderer/components/markdown/TheMarkdown.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { useAppStore } from '@/store/app'
1111
import { useSnippetStore } from '@/store/snippets'
1212
import sanitizeHtml from 'sanitize-html'
1313
import hljs from 'highlight.js'
14-
import 'highlight.js/styles/github.css'
15-
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
14+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
1615
import { ipc } from '@/electron'
1716
import { marked } from 'marked'
1817
import mermaid from 'mermaid'
18+
import { useHljsTheme } from '@/composable'
1919
2020
interface Props {
2121
value: string
@@ -27,6 +27,9 @@ const appStore = useAppStore()
2727
const snippetStore = useSnippetStore()
2828
2929
const forceRefresh = ref()
30+
const preTagBg = computed(() =>
31+
appStore.isLightTheme ? '#fff' : 'var(--color-contrast-high)'
32+
)
3033
3134
const init = () => {
3235
const renderer: marked.RendererObject = {
@@ -181,6 +184,18 @@ const height = computed(() => {
181184
return window.innerHeight - result + 'px'
182185
})
183186
187+
watch(
188+
() => appStore.isLightTheme,
189+
v => {
190+
if (v) {
191+
useHljsTheme('light')
192+
} else {
193+
useHljsTheme('dark')
194+
}
195+
},
196+
{ immediate: true }
197+
)
198+
184199
init()
185200
186201
onMounted(() => {
@@ -207,5 +222,8 @@ window.addEventListener('resize', () => {
207222
:deep(.ps) {
208223
height: v-bind(height);
209224
}
225+
:deep(pre) {
226+
background-color: v-bind(preTagBg);
227+
}
210228
}
211229
</style>

0 commit comments

Comments
 (0)