1

我试图突出显示模式%()%中的所有子字符串htmlmixed。匹配的正则表达式是([%(](.*)[)%]).

这是我用于 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 }
});

谢谢

4

1 回答 1

1

您必须在 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
    }
});

在css中添加以下内容:

.cm-matchhighlight {
  background: red !important
}
于 2020-07-25T14:38:41.043 回答