From eb50b702145ef5b7de58a0edfe00323d01311fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Fri, 29 Dec 2023 16:47:30 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8DChrome=E4=BD=8E?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=85=AC=E5=BC=8F=E6=97=A0=E6=B3=95=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/Formula.js | 24 +++++++++++++++++++----- simple-mind-map/src/utils/index.js | 9 +++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/simple-mind-map/src/plugins/Formula.js b/simple-mind-map/src/plugins/Formula.js index 82783e51..624404d2 100644 --- a/simple-mind-map/src/plugins/Formula.js +++ b/simple-mind-map/src/plugins/Formula.js @@ -1,5 +1,7 @@ import katex from 'katex' import Quill from 'quill' +import 'katex/dist/katex.min.css' +import { getChromeVersion } from '../utils/index' // 数学公式支持插件 // 该插件在富文本模式下可用 @@ -12,19 +14,31 @@ class Formula { this.extendQuill() } + // 获取katex配置 + getKatexConfig() { + const config = { + throwOnError: false, + errorColor: '#f00', + output: 'mathml' // 默认只输出公式 + } + // Chrome内核100以下,mathml配置公式无法正确渲染 + const chromeVersion = getChromeVersion() + if (chromeVersion && chromeVersion <= 100) { + config.output = 'html' + } + return config + } + // 修改formula格式工具 extendQuill() { const QuillFormula = Quill.import('formats/formula') + const self = this class CustomFormulaBlot extends QuillFormula { static create(value) { let node = super.create(value) if (typeof value === 'string') { - katex.render(value, node, { - throwOnError: false, - errorColor: '#f00', - output: 'mathml' // 增加该配置,默认只输出公式 - }) + katex.render(value, node, self.getKatexConfig()) node.setAttribute('data-value', value) } return node diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 824f4386..b0f3ebec 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -1018,3 +1018,12 @@ export const checkNodeListIsEqual = (list1, list2) => { } return true } + +// 获取浏览器的chrome内核版本 +export const getChromeVersion = () => { + const match = navigator.userAgent.match(/\s+Chrome\/(.*)\s+/) + if (match && match[1]) { + return Number.parseFloat(match[1]) + } + return '' +}