add markdown mode by Chris Spencer
This commit is contained in:
parent
0bc16ea45d
commit
6c3894d851
6 changed files with 480 additions and 0 deletions
81
lib/ace/mode/markdown.js
Normal file
81
lib/ace/mode/markdown.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* vim:ts=4:sts=4:sw=4:
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
* Mihai Sucan <mihai DOT sucan AT gmail DOT com>
|
||||
* Chris Spencer <chris.ag.spencer AT googlemail DOT com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
var XmlMode = require("ace/mode/xml").Mode;
|
||||
var HtmlMode = require("ace/mode/html").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var MarkdownHighlightRules = require("ace/mode/markdown_highlight_rules").MarkdownHighlightRules;
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var Mode = function() {
|
||||
var highlighter = new MarkdownHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$embeds = highlighter.getEmbeds();
|
||||
this.createModeDelegates({
|
||||
"js-": JavaScriptMode,
|
||||
"xml-": XmlMode,
|
||||
"html-": HtmlMode
|
||||
});
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
if (state == "listblock") {
|
||||
var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
|
||||
if (match) {
|
||||
return new Array(match[1].length + 1).join(" ") + match[2];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return this.$getIndent(line);
|
||||
}
|
||||
};
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
194
lib/ace/mode/markdown_highlight_rules.js
Normal file
194
lib/ace/mode/markdown_highlight_rules.js
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
* Chris Spencer <chris.ag.spencer AT googlemail DOT com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop");
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
|
||||
var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules;
|
||||
var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules;
|
||||
var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
|
||||
|
||||
function github_embed(tag, prefix) {
|
||||
return { // Github style block
|
||||
token : "support.function",
|
||||
regex : "^```" + tag + "\\s*$",
|
||||
next : prefix + "start"
|
||||
}
|
||||
}
|
||||
|
||||
var MarkdownHighlightRules = function() {
|
||||
|
||||
// regexp must not have capturing parentheses
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
this.$rules = {
|
||||
"start" : [ {
|
||||
token : "empty_line",
|
||||
regex : '^$'
|
||||
}, { // code span `
|
||||
token : "support.function",
|
||||
regex : "(`+)([^\\r]*?[^`])(\\1)"
|
||||
}, { // code block
|
||||
token : "support.function",
|
||||
regex : "^[ ]{4}.+"
|
||||
}, { // h1
|
||||
token: "markup.heading.1",
|
||||
regex: "^=+(?=\\s*$)"
|
||||
}, { // h2
|
||||
token: "markup.heading.1",
|
||||
regex: "^\\-+(?=\\s*$)"
|
||||
}, { // header
|
||||
token : function(value) {
|
||||
return "markup.heading." + value.length;
|
||||
},
|
||||
regex : "^#{1,6}"
|
||||
}, github_embed("javascript", "js-"),
|
||||
github_embed("xml", "xml-"),
|
||||
github_embed("html", "html-"),
|
||||
github_embed("css", "css-"),
|
||||
{ // Github style block
|
||||
token : "support.function",
|
||||
regex : "^```[a-zA-Z]+\\s*$",
|
||||
next : "githubblock"
|
||||
}, { // block quote
|
||||
token : "string",
|
||||
regex : "^>[ ].+$",
|
||||
next : "blockquote"
|
||||
}, { // reference
|
||||
token : ["text", "constant", "text", "url", "string", "text"],
|
||||
regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?\\s*)$"
|
||||
}, { // link by reference
|
||||
token : ["text", "string", "text", "constant", "text"],
|
||||
regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])"
|
||||
}, { // link by url
|
||||
token : ["text", "string", "text", "markup.underline", "string", "text"],
|
||||
regex : "(\\[)"+
|
||||
"(\\[[^\\]]*\\]|[^\\[\\]]*)"+
|
||||
"(\\]\\([ \\t]*)"+
|
||||
"(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)"+
|
||||
"((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+
|
||||
"(\\))"
|
||||
}, { // HR *
|
||||
token : "constant",
|
||||
regex : "^[ ]{0,2}(?:[ ]?\\*[ ]?){3,}\\s*$"
|
||||
}, { // HR -
|
||||
token : "constant",
|
||||
regex : "^[ ]{0,2}(?:[ ]?\\-[ ]?){3,}\\s*$"
|
||||
}, { // HR _
|
||||
token : "constant",
|
||||
regex : "^[ ]{0,2}(?:[ ]?\\_[ ]?){3,}\\s*$"
|
||||
}, { // list
|
||||
token : "markup.list",
|
||||
regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",
|
||||
next : "listblock"
|
||||
}, { // strong ** __
|
||||
token : "string",
|
||||
regex : "([*]{2}|[_]{2}(?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
|
||||
}, { // emphasis * _
|
||||
token : "string",
|
||||
regex : "([*]|[_](?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
|
||||
}, { //
|
||||
token : ["text", "url", "text"],
|
||||
regex : "(<)("+
|
||||
"(?:https?|ftp|dict):[^'\">\\s]+"+
|
||||
"|"+
|
||||
"(?:mailto:)?[-.\\w]+\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.[a-z]+"+
|
||||
")(>)"
|
||||
}, {
|
||||
token : "text",
|
||||
regex : "[^\\*_%$`\\[#<>]+"
|
||||
} ],
|
||||
|
||||
"listblock" : [ { // Lists only escape on completely blank lines.
|
||||
token : "empty_line",
|
||||
regex : "^$",
|
||||
next : "start"
|
||||
}, {
|
||||
token : "markup.list",
|
||||
regex : ".+"
|
||||
} ],
|
||||
|
||||
"blockquote" : [ { // BLockquotes only escape on blank lines.
|
||||
token : "empty_line",
|
||||
regex : "^\\s*$",
|
||||
next : "start"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : ".+"
|
||||
} ],
|
||||
|
||||
"githubblock" : [ {
|
||||
token : "support.function",
|
||||
regex : "^```",
|
||||
next : "start"
|
||||
}, {
|
||||
token : "support.function",
|
||||
regex : ".+"
|
||||
} ]
|
||||
};
|
||||
|
||||
this.embedRules(JavaScriptHighlightRules, "js-", [{
|
||||
token : "support.function",
|
||||
regex : "^```",
|
||||
next : "start"
|
||||
}]);
|
||||
|
||||
this.embedRules(HtmlHighlightRules, "html-", [{
|
||||
token : "support.function",
|
||||
regex : "^```",
|
||||
next : "start"
|
||||
}]);
|
||||
|
||||
this.embedRules(CssHighlightRules, "css-", [{
|
||||
token : "support.function",
|
||||
regex : "^```",
|
||||
next : "start"
|
||||
}]);
|
||||
|
||||
this.embedRules(XmlHighlightRules, "xml-", [{
|
||||
token : "support.function",
|
||||
regex : "^```",
|
||||
next : "start"
|
||||
}]);
|
||||
};
|
||||
oop.inherits(MarkdownHighlightRules, TextHighlightRules);
|
||||
|
||||
exports.MarkdownHighlightRules = MarkdownHighlightRules;
|
||||
});
|
||||
|
|
@ -45,6 +45,12 @@ var TextileHighlightRules = function() {
|
|||
"start" : [
|
||||
{
|
||||
token : "keyword", // start of block
|
||||
token : function(value) {
|
||||
if (value.match(/^h\d$/))
|
||||
return "markup.heading." + value.charAt(1);
|
||||
else
|
||||
return "markup.heading";
|
||||
},
|
||||
regex : "h1|h2|h3|h4|h5|h6|bq|p|bc|pre",
|
||||
next : "blocktag"
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue