在 TinyMCE 的本地预览插件中使用 mathjax 进行预览
Do previews using mathjax in TinyMCE's native preview plugin
如何让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>'
如何让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>'