浏览代码

fix: missing code highlighting when toggling markdown preview (#1484)

NGPixel 5 年之前
父节点
当前提交
bf9c6dda1c
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      client/components/editor/editor-markdown.vue

+ 10 - 0
client/components/editor/editor-markdown.vue

@@ -347,6 +347,16 @@ export default {
     mode: get('editor/mode'),
     activeModal: sync('editor/activeModal')
   },
+  watch: {
+    previewShown (newValue, oldValue) {
+      if (newValue && !oldValue) {
+        this.$nextTick(() => {
+          Prism.highlightAllUnder(this.$refs.editorPreview)
+          Array.from(this.$refs.editorPreview.querySelectorAll('pre.line-numbers')).forEach(pre => pre.classList.add('prismjs'))
+        })
+      }
+    }
+  },
   methods: {
     toggleModal(key) {
       this.activeModal = (this.activeModal === key) ? '' : key