From 075f789d6c089712a5eb1b97c685c55c7df46edc Mon Sep 17 00:00:00 2001 From: Kelley van Evert Date: Tue, 22 Feb 2011 23:20:00 +0100 Subject: [PATCH] Added very basic Textile mode implementation. --- index.html | 51 ++++++++++++++-- lib/ace/mode/textile.js | 44 ++++++++++++++ lib/ace/mode/textile_highlight_rules.js | 78 +++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 lib/ace/mode/textile.js create mode 100644 lib/ace/mode/textile_highlight_rules.js diff --git a/index.html b/index.html index ede48739..f9ce77e6 100644 --- a/index.html +++ b/index.html @@ -14,16 +14,18 @@ @@ -86,6 +88,8 @@ + + @@ -123,7 +127,10 @@
- + + + diff --git a/lib/ace/mode/textile.js b/lib/ace/mode/textile.js new file mode 100644 index 00000000..a8fe5259 --- /dev/null +++ b/lib/ace/mode/textile.js @@ -0,0 +1,44 @@ + +/* + TODO license etc +*/ + +define(function(require, exports, module) { + +var oop = require("pilot/oop"); +var TextMode = require("ace/mode/text").Mode; +var Tokenizer = require("ace/tokenizer").Tokenizer; +var TextileHighlightRules = require("ace/mode/textile_highlight_rules").TextileHighlightRules; +var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent; +var Range = require("ace/range").Range; + +var Mode = function() +{ + this.$tokenizer = new Tokenizer(new TextileHighlightRules().getRules()); + this.$outdent = new MatchingBraceOutdent(); +}; +oop.inherits(Mode, TextMode); + +(function() +{ + this.getNextLineIndent = function(state, line, tab) + { + if (state == "intag") + return tab; + + return ""; + }; + + 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; + +}); diff --git a/lib/ace/mode/textile_highlight_rules.js b/lib/ace/mode/textile_highlight_rules.js new file mode 100644 index 00000000..bde91e9b --- /dev/null +++ b/lib/ace/mode/textile_highlight_rules.js @@ -0,0 +1,78 @@ + +/* + TODO license etc +*/ + +define(function(require, exports, module) { + +var oop = require("pilot/oop"); +var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules; + +var TextileHighlightRules = function() +{ +/* + var phraseModifiers = lang.arrayToMap( + ("_|*|__|**|??|-|+|^|%|@").split("|") + ); + + var blockModifiers = lang.arrayToMap( + ("h1|h2|h3|h4|h5|h6|bq|p|bc|pre").split("|") + ); + */ + /* + var punctuation = lang.arrayToMap( + ("-|--|(tm)|(r)|(c)").split("|") + ); + */ + + this.$rules = { + "start" : [ + { + token : "keyword", // start of block + regex : "h1|h2|h3|h4|h5|h6|bq|p|bc|pre", + next : "blocktag" + }, + { + token : "keyword", + regex : "[\\*]+|[#]+" + }, + { + token : "text", + regex : ".+" + } + ], + "blocktag" : [ + { + token : "keyword", + regex : "\\. ", + next : "start", + }, + { + token : "keyword", + regex : "\\(", + next : "blocktagproperties" + }, + ], + "blocktagproperties" : [ + { + token : "keyword", + regex : "\\)", + next : "blocktag" + }, + { + token : "string", + regex : "[a-zA-Z0-9\\-_]+" + }, + { + token : "keyword", + regex : "#" + }, + ] + }; +}; + +oop.inherits(TextileHighlightRules, TextHighlightRules); + +exports.TextileHighlightRules = TextileHighlightRules; + +});