Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex tinyMCE简单语法高亮显示_Regex_Tinymce_Syntax Highlighting - Fatal编程技术网

Regex tinyMCE简单语法高亮显示

Regex tinyMCE简单语法高亮显示,regex,tinymce,syntax-highlighting,Regex,Tinymce,Syntax Highlighting,我想在tinyMce编辑器中实现简单的实时语法高亮显示。 我想为文本中的每个{keyword}和{more keywords}突出显示(更改文本的背景或颜色)。关键字只能包含字母、数字和点(.)。 我不知道我的想法是否好: 绑定到编辑器的onChange事件 删除所有出现的{keyword}(regex) 查找所有#{keyword}并将其替换为#{found keyword} (css类code将背景设置为某种颜色) 如何解决这个问题? 绑定到Onchange事件似乎是可以的,但是你也应该

我想在tinyMce编辑器中实现简单的实时语法高亮显示。 我想为文本中的每个
{keyword}
{more keywords}
突出显示(更改文本的背景或颜色)。关键字只能包含字母、数字和点(.)。 我不知道我的想法是否好:

  • 绑定到编辑器的onChange事件
  • 删除所有出现的
    {keyword}
    (regex)
  • 查找所有#{keyword}并将其替换为#{found keyword}
(css类
code
将背景设置为某种颜色)


如何解决这个问题?

绑定到Onchange事件似乎是可以的,但是你也应该考虑使用OnKEY事件。我希望以下代码片段将对您有所帮助:

css(在内容\u css中定义,即):

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;
}
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;
}