Epiceditor与MathJax配对

时间:2014-02-27 16:54:07

标签: javascript mathjax epiceditor

无论如何将脚本(例如MathJax)加载到EpicEditor预览iFrame中?我希望我的预览是正确的Markdown,然后运行javascript来预览MathJax内容。

谢谢!

1 个答案:

答案 0 :(得分:2)

似乎你应该手动将MathJax脚本注入预览器iframe。像这样:

var editor = new EpicEditor(opts).load();

previewer = editor.getElement('previewer');
var mathjax = previewer.createElement('script');
mathjax.type = 'text/javascript';
mathjax.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
previewer.body.appendChild(mathjax);

var config = previewer.createElement('script');
config.type = 'text/x-mathjax-config';
config.text = "MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']], displayMath: [['$$','$$']], processEscapes: true}});";
previewer.body.appendChild(config);

然后你可以在预览事件上渲染方程式:

editor.on('preview', function() {
    editor.getElement('previewerIframe').contentWindow.eval(
        'MathJax.Hub.Queue(["Typeset",MathJax.Hub]);');
});

这也适用于全屏实时编辑模式。

相关问题