Created
November 4, 2011 20:17
-
-
Save jbpros/1340378 to your computer and use it in GitHub Desktop.
Paste this into a console when editing a feature on Github and see the light!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //// https://github.com/cucumber/ace/blob/gherkin-mode/lib/ace/mode/gherkin_highlight_rules.js //// | |
| define('ace/mode/gherkin_highlight_rules', function(require, exports, module) { | |
| var oop = require("pilot/oop"); | |
| var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules; | |
| var GherkinHighlightRules = function() | |
| { | |
| this.$rules = { | |
| "start" : [ | |
| { | |
| token : "comment", | |
| regex : "^\\s*#.*$" | |
| }, | |
| { | |
| token : "comment.doc.tag", | |
| regex : "@[^@\\\r\\\n\\\t ]+" | |
| }, | |
| { | |
| token : "keyword.with_children", | |
| regex : "^\\s*(?:Feature|Scenario|Scenario Outline|Examples):", | |
| }, | |
| { | |
| token : "keyword", | |
| regex : "^\\s*(?:Given |When |Then |And |But )" | |
| }, | |
| { | |
| token : "string", // multi line """ string start | |
| regex : '^\\s*"{3}.*$', | |
| next : "qqstring" | |
| }, | |
| ], | |
| "qqstring" : [ { | |
| token : "string", // multi line """ string end | |
| regex : '(?:[^\\\\]|\\\\.)*?"{3}', | |
| next : "start" | |
| }, { | |
| token : "string", | |
| regex : '.+' | |
| } | |
| ] | |
| }; | |
| }; | |
| oop.inherits(GherkinHighlightRules, TextHighlightRules); | |
| exports.GherkinHighlightRules = GherkinHighlightRules; | |
| }); | |
| //// https://github.com/cucumber/ace/blob/gherkin-mode/lib/ace/mode/gherkin.js //// | |
| define('ace/mode/gherkin', function(require, exports, module) { | |
| var oop = require("pilot/oop"); | |
| var TextMode = require("ace/mode/text").Mode; | |
| var Tokenizer = require("ace/tokenizer").Tokenizer; | |
| var GherkinHighlightRules = require("ace/mode/gherkin_highlight_rules").GherkinHighlightRules; | |
| var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent; | |
| var Range = require("ace/range").Range; | |
| var Mode = function() | |
| { | |
| this.$tokenizer = new Tokenizer(new GherkinHighlightRules().getRules()); | |
| this.$outdent = new MatchingBraceOutdent(); | |
| }; | |
| oop.inherits(Mode, TextMode); | |
| (function() | |
| { | |
| this.getNextLineIndent = function(state, line, tab) { | |
| var indent = this.$getIndent(line); | |
| var tokenizedLine = this.$tokenizer.getLineTokens(line, state); | |
| var tokens = tokenizedLine.tokens; | |
| if (tokens.length && tokens[0].type == "keyword.with_children") { | |
| indent += tab; | |
| } | |
| return indent; | |
| }; | |
| this.checkOutdent = function(state, line, input) { | |
| return this.$outdent.checkOutdent(line, input); | |
| }; | |
| this.autoOutdent = function(state, doc, row) { | |
| this.$outdent.autoOutdent(doc, row); | |
| }; | |
| }).call(Mode.prototype); | |
| exports.Mode = Mode; | |
| }); | |
| //// let's activate this awesome sauce //// | |
| var GherkinMode = require('ace/mode/gherkin').Mode; | |
| var editor = window.editor.ace; | |
| editor.getSession().setMode(new GherkinMode()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment