如何在 Angular 的 Ace Editor 中突出显示自定义关键字?

问题描述 投票:0回答:1

我试图突出显示 this.$rules 中存在的几个关键字。但是我无法获得最终输出。你能告诉我我在这里缺少什么吗?

这是我在 Angular 组件中尝试过的

` 导出类 AceBuildsEditorComponent 实现 OnInit、AfterViewInit { @ViewChild("editor") 私有编辑器:ElementRef;

ngAfterViewInit(): void {
    ace.config.set("fontSize", "14px");
    const editor = ace.edit(this.editor.nativeElement);
    const oop = ace.require('ace/lib/oop');
    const TextMode = ace.require('ace/mode/text').Mode;
    const TextHighlightRules = 
    ace.require('ace/mode/text_highlight_rules').TextHighlightRules;
    const customHighlightRules = function() {
    this.$rules = {
         start: [
            {
              regex: /\b(sometext|othertext)\b/,
              token: 'keyword',
            },
         ],
    };
  };

  oop.inherits(customHighlightRules, TextHighlightRules);
  const Mode = function() {
    this.HighlightRules = customHighlightRules;
  };
  oop.inherits(Mode,TextMode);

  (function() {
      this.$id = "ace/mode/custom";
   }).call(Mode.prototype);
 }

} `

javascript angular typescript ace-editor
1个回答
0
投票

将此行添加到 ngAfterViewInit 方法中的 Mode 和 customHighlightRules 定义之后。

editor.getSession().setMode(new (ace.require("ace/mode/custom").Mode)());
© www.soinside.com 2019 - 2024. All rights reserved.