简体   繁体   English

CodeMirror 突出显示特定的正则表达式匹配

[英]CodeMirror Highlight specific Regex-Match

I'm trying to highlight all %()% substrings in the htmlmixed mode.我试图在htmlmixed模式下突出显示所有%()%子字符串。 The matching RegExp is ([%(](.*)[)%]) .匹配的正则表达式是([%(](.*)[)%])

Here's the code i'm using for CodeMirror:这是我用于 CodeMirror 的代码:

const code = CodeMirror.fromTextArea(document.querySelector("#id"), {
     theme: "dracula",
     mode: "text/html",
     lineNumbers: true,
     firstLineNumber: 1,
     spellcheck: false,
     autocorrect: true,
     extraKeys: { "Ctrl-Space": "autocomplete" },
     styleActiveLine: true,
     highlightSelectionMatches: { showToken: /\w/, annotateScrollbar: true }
});

Thanks谢谢

You have to add a style property in highlightSelectionMatches.您必须在 highlightSelectionMatches 中添加样式属性。

const code = CodeMirror.fromTextArea(document.querySelector("#id"), {
     theme: "dracula",
     mode: "text/html",
     lineNumbers: true,
     firstLineNumber: 1,
     spellcheck: false,
     autocorrect: true,
     extraKeys: { "Ctrl-Space": "autocomplete" },
     styleActiveLine: true,
     highlightSelectionMatches: { 
          minChars: 2,
          showToken: /\w/,
          style:'matchhighlight',
          annotateScrollbar: true
    }
});

Add below in css:在 css 中添加以下内容:

.cm-matchhighlight {
  background: red !important
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM