tijiao
This commit is contained in:
110
public/js/global-math.js
Normal file
110
public/js/global-math.js
Normal file
@@ -0,0 +1,110 @@
|
||||
// 确保 MathJax 配置正确
|
||||
window.MathJax = window.MathJax || {
|
||||
loader: {
|
||||
load: ['[tex]/ams', '[tex]/newcommand']
|
||||
},
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
||||
displayMath: [['$$', '$$'], ['\\[', '\\]']]
|
||||
},
|
||||
a11y: {
|
||||
// 启用 MathJax 可访问性功能,确保使用 aria-label
|
||||
texHints: true,
|
||||
screenReader: true,
|
||||
mathml: {
|
||||
enable: true,
|
||||
},
|
||||
label: {
|
||||
// 公式的 aria-label 配置
|
||||
enable: true,
|
||||
texClass: 'MathJax-Label',
|
||||
form: 'LaTeX'
|
||||
}
|
||||
},
|
||||
svg: { fontCache: 'global' }
|
||||
};
|
||||
|
||||
// **定义全局渲染方法**
|
||||
window.renderMathJax = function (tinymceId) {
|
||||
// if (window.MathJax && typeof window.MathJax.typesetPromise === "function") {
|
||||
// console.log("正在渲染 MathJax 公式...");
|
||||
|
||||
// // 如果提供了 TinyMCE 编辑器 ID
|
||||
// if (tinymceId) {
|
||||
// const editorInstance = window.tinymce.get(tinymceId); // 根据 ID 获取编辑器实例
|
||||
// if (!editorInstance) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 获取指定的 TinyMCE 编辑器中的内容
|
||||
// const editorBody = editorInstance.getBody();
|
||||
|
||||
// // 渲染 editorBody 中所有 <wmath> 标签,并使用 data-latex 的值
|
||||
// const wmathElements = editorBody.querySelectorAll('wmath');
|
||||
// wmathElements.forEach((element) => {
|
||||
// // 检查 <wmath> 标签是否包含有效的 data-latex 属性值
|
||||
// const latexContent = element.getAttribute('data-latex');
|
||||
// if (latexContent) {
|
||||
// // 将元素的内部内容替换为 data-latex 的值
|
||||
// element.innerHTML = latexContent;
|
||||
|
||||
// // 渲染 MathJax 公式
|
||||
// window.MathJax.typesetPromise([element]).catch((err) => {
|
||||
// console.warn("TinyMCE MathJax 渲染失败:", err);
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// // 渲染 editorBody 中所有 <math> 标签(MathML 内容)
|
||||
// const mathElements = editorBody.querySelectorAll('math');
|
||||
// mathElements.forEach((element) => {
|
||||
// // 渲染 MathJax 公式
|
||||
// window.MathJax.typesetPromise([element]).catch((err) => {
|
||||
// console.warn("MathJax 渲染失败:", err);
|
||||
// });
|
||||
// });
|
||||
|
||||
// } else {
|
||||
// // 处理全局文档中的 <wmath> 标签
|
||||
// const wmathElements = document.querySelectorAll('wmath');
|
||||
// wmathElements.forEach((element) => {
|
||||
// // 检查 <wmath> 标签是否包含有效的 data-latex 属性值
|
||||
// const latexContent = element.getAttribute('data-latex');
|
||||
// if (latexContent) {
|
||||
// // 将元素的内部内容替换为 data-latex 的值
|
||||
// element.innerHTML = latexContent;
|
||||
|
||||
// // 渲染 MathJax 公式
|
||||
// window.MathJax.typesetPromise([element]).catch((err) => {
|
||||
// console.warn("MathJax 渲染失败:", err);
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// // 处理全局文档中的 <math> 标签(MathML 内容)
|
||||
// const mathElements = document.querySelectorAll('math');
|
||||
// mathElements.forEach((element) => {
|
||||
// // 渲染 MathJax 公式
|
||||
// window.MathJax.typesetPromise([element]).catch((err) => {
|
||||
// console.warn("MathJax 渲染失败:", err);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// console.warn("MathJax 未正确加载!");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user