0
下面的代碼(從stackedit - 減價編輯器)將取代如何替換數組?
\begin{thm}
blabla...
\end{thm}
與
<div class="latex_thm">
blabla...
</div>
的代碼是:
userCustom.onEditorConfigure = function(editor) {
var converter = editor.getConverter();
converter.hooks.chain("preConversion", function(text) {
return text.replace(/\\begin{thm}([\s\S]*?)\\end{thm}/g, function(wholeMatch, m1) {
return '<thm>' + m1 + '</thm>';
});
});
converter.hooks.chain("preBlockGamut", function(text, blockGamutHookCallback) {
return text.replace(/<thm>([\s\S]*?)<\/thm>/g, function(wholeMatch, m1) {
return '<div class="latex_thm">' + blockGamutHookCallback(m1) + '</div>';
});
});
};
但是如果我想不僅可以取代thm
與latex_thm
,但lem
與latex_lem
,如何做到這一點?我想也許用array
解決吧?但它同樣不適合我:
userCustom.onEditorConfigure = function(editor) {
var converter = editor.getConverter();
converter.hooks.chain("preConversion", function(text) {
var array = {
"thm": "thm",
"lem": "lem"
};
for (var val in array) {
return text.replace(/\\begin{array[val]}([\s\S]*?)\\end{array[val]}/g, function(wholeMatch, m1) {
return '<div class="latex_"' + array[val] + '>' + m1 + '</div>';
});
};
});
};
};
你能幫我嗎?
僅供參考'preg_replace'是一個PHP函數。 – HamZa