1

我试图让 MatJax 和 Markdown 一起工作,通过使用几乎标准的代码,我能够让它工作,但现在我面临一个奇怪的问题。我的 WMD 预览仅在交替击键时更新......!!

初始化 WMD 的 javascript 如下

Preview.Init();

    (function() {
        var converter1 = Markdown.getSanitizingConverter();
        var editor1 = new Markdown.Editor(converter1);
        converter1.hooks.chain("postConversion", function(text) {   
            Preview.CreatePreview();
            return text; 
        });
        editor1.hooks.set("insertImageDialog", function(callback) {
            setTimeout(function() {
                $('#uploadmodal').modal({
                    keyboard : true,
                    backdrop:false
                });
                fileCallback = callback
            }, 500);
            return true; // tell the editor that we'll take care of getting the image url
        });
        editor1.run();
    })();

MathJAX 集成是通过以下代码完成的

var Preview = {
          delay: 150,        // delay after keystroke before updating

          preview: null,     // filled in by Init below
          buffer: null,      // filled in by Init below

          timeout: null,     // store setTimout id
          mjRunning: false,  // true when MathJax is processing
          oldText: null,     // used to check if an update is needed

          Init: function () {
            this.preview = document.getElementById("wmd-preview");
            this.buffer =   document.getElementById("MathBuffer");
          },

          SwapBuffers: function () {
            var buffer = this.preview, preview = this.buffer;
            this.buffer = buffer; this.preview = preview;
            buffer.style.visibility = "hidden"; buffer.style.position = "absolute";
            preview.style.position = ""; preview.style.visibility = "";
          },
          Update: function () {
            if (this.timeout) {clearTimeout(this.timeout)}
            this.timeout = setTimeout(this.callback,this.delay);
          },

          CreatePreview: function () {
            Preview.timeout = null;
            if (this.mjRunning) return;
            var text = document.getElementById("wmd-preview").innerHTML;
            if (text === this.oldtext) return;
            this.buffer.innerHTML = this.oldtext = text;
            this.mjRunning = true;
            MathJax.Hub.Queue(
              ["Typeset",MathJax.Hub,this.buffer],
              ["PreviewDone",this]
            );
          },
          PreviewDone: function () {
            this.mjRunning = false;
            this.SwapBuffers();
          }

        };

这里有一个问题的演示页面http://easytha.com/question/demoQuestion

4

0 回答 0