確定這聽起來像是發生了什麼事是,當你請求的內容你特克斯版本替換當前MATHML編輯器中啓動,所以當你更換可編輯區域中的內容是活導致編輯器和頁面不同步。
我不能很容易地爲你的確切情況嘗試這一點,但下面的代碼概述了我將採取的最初方法來解決你所描述的,如果你讓我知道你如何得到,如果需要修改我會很高興地更新它。
var editor = ContentTools.EditorApp.get();
// Add a flag to the editor that indicates when the tex version of the content
// has loaded.
editor.texLoaded = false;
// Capture the start event against the editor, the first time around we load
// the tex version of our content, the second time around we intialize the
// editor as normal.
editor.addEventListener('start', function(ev) {
// Has the Tex content been loaded, if so do nothing we're ready to start
// editing.
if (this.texLoaded) {
return;
}
// If the Tex content hasn't been loaded then cancel the start event
ev.preventDefault();
// Load the Tex content
$.ajax({
url: "/get-tex?..."
}).done(function (response) {
// From the response update the contents of the editable region
$('.contentArea')[0].innerHTML = response.data.content;
// Flag that the tex version of the content is now in place
this.texLoaded = true;
// Start the editor
editor.start();
});
});
幾個快速問題:當您嘗試替換區域的內容時,CT編輯器是否處於活動狀態(例如,您在編輯)?您插入的內容是否在插入之前或您嘗試重新初始化編輯器之前由MathJax格式化? –
@AnthonyBlackshaw當MathJax被渲染時,它將TeX轉換爲MathML。我不想編輯MathML標記,而是編輯TeX(例如元素的innerHTML中的$ x^2 + 7 $)。 我試圖執行以下操作:當編輯器啓動時,將頁面內容重新加載到頁面中(以去除MathML標記,將其返回到TeX標記),然後開始編輯該內容。因此,我試圖在編輯器啓動時替換內容(我將其綁定到editor._ignition的'start'事件)。我很感激幫助。 –
嗨@Grant桑德斯 - 我看到你是新來的SO。如果您覺得答案可以解決問題,請點擊綠色複選標記將其標記爲「已接受」。這有助於將注意力集中在仍然沒有答案的舊版SO上。 –