Files
atom/vendor/ace/mode/markdown_highlight_rules.js
2011-08-27 03:55:56 -07:00

194 lines
6.9 KiB
JavaScript

/* ***** 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;
});