如何使TinyMCE的能够在本地预览插件使用MathJax?在前台界面TinyMCE的编辑器在function.php文件中使用类似的代码被设置为这个
function editor_settings($args = array()){
return array(
'textarea_name' => 'post_content',
'tinymce' => array(
'plugins' => "preview",
'toolbar' => "redo undo bold italic preview",
'setup' => "function(ed){
ed.onChange.add(function(ed, l) {
var content = ed.getContent();
if(ed.isDirty() || content === '' ){
ed.save();
jQuery(ed.getElement()).blur(); // trigger change event for textarea
}
}"
));
}
而我使用MathJax的CDN复印件和MathJax我的配置代码如下:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'],["\\(","\\)"] ],
displayMath: [['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
"HTML-CSS": {
matchFontHeight: false,
availableFonts: ["TeX"],
webFont: 'Latin-Modern',
preferredFont: 'Latin-Modern',
scale: 100,
},
CommonHTML: {
matchFontHeight: false
},
SVG: {
matchFontHeight: false
}
});
</script>
我能解决这个问题。修改在插件的文件“plugin.min.js”,可以找到这条路/wp-includes/js/tinymce/plugins/preview/
你需要寻找做
e += '<link type="text/css" rel="stylesheet" href="' + f(c.documentBaseURI.toAbsolute(a)) + '">'
并插入这两行加载和配置MathJax
e += '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'
e += '<script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { matchFontHeight: false, availableFonts: ["TeX"], webFont: \'Latin-Modern\', preferredFont: \'Latin-Modern\', scale: 100, }, CommonHTML: { matchFontHeight: false }, SVG: { matchFontHeight: false } }); </script>'