aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/gfm
diff options
context:
space:
mode:
Diffstat (limited to 'imports/codemirror/mode/gfm')
-rw-r--r--imports/codemirror/mode/gfm/gfm.js42
1 files changed, 39 insertions, 3 deletions
diff --git a/imports/codemirror/mode/gfm/gfm.js b/imports/codemirror/mode/gfm/gfm.js
index 01afed7b..8f457c53 100644
--- a/imports/codemirror/mode/gfm/gfm.js
+++ b/imports/codemirror/mode/gfm/gfm.js
@@ -69,7 +69,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {
69 function handleText(stream, mdState) { 69 function handleText(stream, mdState) {
70 var match; 70 var match;
71 if (stream.match(/^\w+:\/\/\S+/)) { 71 if (stream.match(/^\w+:\/\/\S+/)) {
72 return 'linkhref'; 72 return 'link';
73 } 73 }
74 if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) { 74 if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) {
75 return mdMode.getType(mdState); 75 return mdMode.getType(mdState);
@@ -102,7 +102,43 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {
102 }, 102 },
103 103
104 token: function(stream, state) { 104 token: function(stream, state) {
105 return state.token(stream, state); 105 /* Parse GFM double bracket links */
106 if ((ch = stream.peek()) != undefined && ch == '[') {
107 stream.next(); // Advance the stream
108
109 /* Only handle double bracket links */
110 if ((ch = stream.peek()) == undefined || ch != '[') {
111 stream.backUp(1);
112 return state.token(stream, state);
113 }
114
115 while ((ch = stream.next()) != undefined && ch != ']') {}
116
117 if (ch == ']' && (ch = stream.next()) != undefined && ch == ']')
118 return 'link';
119
120 /* If we did not find the second ']' */
121 stream.backUp(1);
122 }
123
124 /* Match GFM latex formulas, as well as latex formulas within '$' */
125 if (stream.match(/^\$[^\$]+\$/)) {
126 return "string";
127 }
128
129 if (stream.match(/^\\\((.*?)\\\)/)) {
130 return "string";
131 }
132
133 if (stream.match(/^\$\$[^\$]+\$\$/)) {
134 return "string";
135 }
136
137 if (stream.match(/^\\\[(.*?)\\\]/)) {
138 return "string";
139 }
140
141 return state.token(stream, state);
106 } 142 }
107 } 143 }
108}); 144}, "markdown");