Skip to content

Instantly share code, notes, and snippets.

@JackuB
Created January 15, 2018 14:32
Show Gist options
  • Save JackuB/3d589bd64dc96c1b18486baaaf58d910 to your computer and use it in GitHub Desktop.
Save JackuB/3d589bd64dc96c1b18486baaaf58d910 to your computer and use it in GitHub Desktop.
// This only defines high-level behaviour of the Mode like folding etc.
ace.define('ace/mode/custom', ['require', 'exports', 'ace/lib/oop', 'ace/mode/text', 'ace/mode/custom_highlight_rules'], (acequire, exports) => {
const oop = acequire('ace/lib/oop');
const TextMode = acequire('ace/mode/text').Mode;
const CustomHighlightRules = acequire('ace/mode/custom_highlight_rules').CustomHighlightRules;
oop.inherits(Mode, TextMode); // ACE's way of doing inheritance
exports.Mode = Mode; // eslint-disable-line no-param-reassign
});
// This is where we really create the highlighting rules
ace.define('ace/mode/custom_highlight_rules', ['require', 'exports', 'ace/lib/oop', 'ace/mode/text_highlight_rules'], (acequire, exports) => {
const oop = acequire('ace/lib/oop');
const TextHighlightRules = acequire('ace/mode/text_highlight_rules').TextHighlightRules;
const CustomHighlightRules = function CustomHighlightRules() {
this.$rules = new TextHighlightRules().getRules(); // Use Text's rules as a base
};
oop.inherits(CustomHighlightRules, TextHighlightRules);
exports.CustomHighlightRules = CustomHighlightRules;
});
@komali2
Copy link

komali2 commented Apr 18, 2018

I wonder why you're not getting "acequire is not defined" errors, cause I certainly am.

@stanchovy
Copy link

Mode is not defined on line 7

@mukeshsoni
Copy link

There is a missing step where the CustomHighlighter has to be set for the Mode

let Mode = function() {
  // this ensures that all your highlight rules are set for your custom mode
  this.HighlightRules = CustomHighlightRules;
}

oop.inherits(Mode, TextMode); // ACE's way of doing inheritance

The custom mode will otherwise not have any highlight rules.

@JackuB
Copy link
Author

JackuB commented Jan 3, 2020

Worth pointing out, that is a part of an article on writing custom highlight rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment