以下代码(来自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>';
});
};
});
};
};
你能帮帮我吗?