123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- let isMathjaxConfig = false;//用于标识是否配置
- const initMathjaxConfig = () => {
- if (!window.MathJax) {
- return;
- }
- window.MathJax.Hub.Config({
- showProcessingMessages: false, //关闭js加载过程信息
- messageStyle: "none", //不显示信息
- jax: ["input/TeX", "output/HTML-CSS"],
- tex2jax: {
- inlineMath: [["$", "$"], ["\\(", "\\)"]], //行内公式选择符
- displayMath: [["$$", "$$"], ["\\[", "\\]"]], //段内公式选择符
- skipTags: ["script", "noscript", "style", "textarea", "pre", "code", "a"] //避开某些标签
- },
- "HTML-CSS": {
- availableFonts: ["STIX", "TeX"], //可选字体
- showMathMenu: false //关闭右击菜单显示
- }
- });
- isMathjaxConfig = true; //配置完成,改为true
- };
- const _ensureMathjaxInit = function () {
- if (!isMathjaxConfig) initMathjaxConfig()
- }
- const _transferTikuQuestionImageUrls = function (docEle) {
- const imgList = docEle.getElementsByTagName('img')
- for (var i = 0; i < imgList.length; i++) {
- const img = imgList[i]
- const supportTagConfigs = [
- { tag: 'tikuimages', prefix: 'https://file.mingxuejinbang.com/tikubao/tikuimages' },
- { tag: 'mathJye', prefix: 'https://file.mingxuejinbang.com/tikubao/mathJye' }]
- for (let index = 0; index < supportTagConfigs.length; index++) {
- const config = supportTagConfigs[index];
- if (_transferTikuQuestionImageUrlsByTag(img, config)) break;
- }
- }
- }
- const _transferTikuQuestionImageUrlsByTag = function (img, config) {
- let srcParams = img.src.split(config.tag)
- if (srcParams.length > 1) {
- img.src = config.prefix + srcParams[1]
- return true
- }
- return false
- }
- const MathQueue = function (elementId) {
- _ensureMathjaxInit();
- const docEle = document.getElementById(elementId);
- if (!docEle) return;
- _transferTikuQuestionImageUrls(docEle);
- if (!window.MathJax) {
- return;
- }
- window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, docEle]);
- };
|