我希望在tinyMce编辑器中有一个简单的实时语法突出显示。我想为文本中的每个#{keyword}和#{more keywords}突出显示(更改文本的背景或颜色)。关键字只能包含字母、数字和点(.)。我不知道我的主意是否好:
<span class="code">#{keyword}</span> (Regex)(css类code的背景设置为某种颜色)
有什么办法解决这个问题吗?
发布于 2010-08-11 12:00:03
绑定到onChange事件似乎没问题,但是您应该考虑使用onKey--事件。我希望下面的代码片段将对您有所帮助:
css (在content_css中定义,即):
[current] {
background-color:yellow;
}
[changed] {
background-color:green;
}js的帮助功能:
var select_current = function(node){
unselect_current();
node.setAttribute('current','true');
};
var unselect_current = function(){
var n = ed.getBody().firstChild;
while (n){
if (n.nodeType == 1 && n.getAttribute('current'))
{
n.removeAttribute('current');
}
n = n.nextSibling;
}
};
p_of = function(node) // returns p-Element of node
{
while (node){
if (node.nodeName == 'BODY') { return null; }
if (node.nodeName == 'P') { return node; }
else { node = node.parentNode; }
}
return null;
}事件电话:
var _node_changing = false;
console.log('onNodeChange: ', arguments);
if (!_node_changing && element.getAttribute('_mce_type') != 'bookmark'){
_node_changing = true;
var p = p_of(element);
if (p){
if (!p.getAttribute('current')){
select_current(p);
}
}
_node_changing = false;
}https://stackoverflow.com/questions/3422255
复制相似问题