summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/gfm/gfm.js
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/mode/gfm/gfm.js
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/mode/gfm/gfm.js')
-rwxr-xr-xpublic/vendor/codemirror/mode/gfm/gfm.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/gfm/gfm.js b/public/vendor/codemirror/mode/gfm/gfm.js
new file mode 100755
index 00000000..80a8e2c8
--- /dev/null
+++ b/public/vendor/codemirror/mode/gfm/gfm.js
@@ -0,0 +1,123 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"), require("../markdown/markdown"), require("../../addon/mode/overlay"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.defineMode("gfm", function(config, modeConfig) {
+ var codeDepth = 0;
+ function blankLine(state) {
+ state.code = false;
+ return null;
+ }
+ var gfmOverlay = {
+ startState: function() {
+ return {
+ code: false,
+ codeBlock: false,
+ ateSpace: false
+ };
+ },
+ copyState: function(s) {
+ return {
+ code: s.code,
+ codeBlock: s.codeBlock,
+ ateSpace: s.ateSpace
+ };
+ },
+ token: function(stream, state) {
+ state.combineTokens = null;
+
+ // Hack to prevent formatting override inside code blocks (block and inline)
+ if (state.codeBlock) {
+ if (stream.match(/^```/)) {
+ state.codeBlock = false;
+ return null;
+ }
+ stream.skipToEnd();
+ return null;
+ }
+ if (stream.sol()) {
+ state.code = false;
+ }
+ if (stream.sol() && stream.match(/^```/)) {
+ stream.skipToEnd();
+ state.codeBlock = true;
+ return null;
+ }
+ // If this block is changed, it may need to be updated in Markdown mode
+ if (stream.peek() === '`') {
+ stream.next();
+ var before = stream.pos;
+ stream.eatWhile('`');
+ var difference = 1 + stream.pos - before;
+ if (!state.code) {
+ codeDepth = difference;
+ state.code = true;
+ } else {
+ if (difference === codeDepth) { // Must be exact
+ state.code = false;
+ }
+ }
+ return null;
+ } else if (state.code) {
+ stream.next();
+ return null;
+ }
+ // Check if space. If so, links can be formatted later on
+ if (stream.eatSpace()) {
+ state.ateSpace = true;
+ return null;
+ }
+ if (stream.sol() || state.ateSpace) {
+ state.ateSpace = false;
+ if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
+ // User/Project@SHA
+ // User@SHA
+ // SHA
+ state.combineTokens = true;
+ return "link";
+ } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
+ // User/Project#Num
+ // User#Num
+ // #Num
+ state.combineTokens = true;
+ return "link";
+ }
+ }
+ if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i) &&
+ stream.string.slice(stream.start - 2, stream.start) != "](") {
+ // URLs
+ // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
+ // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
+ state.combineTokens = true;
+ return "link";
+ }
+ stream.next();
+ return null;
+ },
+ blankLine: blankLine
+ };
+
+ var markdownConfig = {
+ underscoresBreakWords: false,
+ taskLists: true,
+ fencedCodeBlocks: true,
+ strikethrough: true
+ };
+ for (var attr in modeConfig) {
+ markdownConfig[attr] = modeConfig[attr];
+ }
+ markdownConfig.name = "markdown";
+ CodeMirror.defineMIME("gfmBase", markdownConfig);
+ return CodeMirror.overlayMode(CodeMirror.getMode(config, "gfmBase"), gfmOverlay);
+}, "markdown");
+
+});