").join(">").split('"').join(""").split("'").join("'")}});a.extend(a.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){b={}},afterManip:function(f,b,d){var e=b.nodeType===11?a.makeArray(b.childNodes):b.nodeType===1?[b]:[];d.call(f,b);m(e);c++}});function j(e,g,f){var b,c=f?a.map(f,function(a){return typeof a==="string"?e.key?a.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+d+'="'+e.key+'" $2'):a:j(a,e,a._ctnt)}):e;if(g)return c;c=c.join("");c.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(f,c,e,d){b=a(e).get();m(b);if(c)b=k(c).concat(b);if(d)b=b.concat(k(d))});return b?b:k(c)}function k(c){var b=document.createElement("div");b.innerHTML=c;return a.makeArray(b.childNodes)}function o(b){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+a.trim(b).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(m,l,k,g,b,c,d){var j=a.tmpl.tag[k],i,e,f;if(!j)throw"Unknown template tag: "+k;i=j._default||[];if(c&&!/\w$/.test(b)){b+=c;c=""}if(b){b=h(b);d=d?","+h(d)+")":c?")":"";e=c?b.indexOf(".")>-1?b+h(c):"("+b+").call($item"+d:b;f=c?e:"(typeof("+b+")==='function'?("+b+").call($item):("+b+"))"}else f=e=i.$1||"null";g=h(g);return"');"+j[l?"close":"open"].split("$notnull_1").join(b?"typeof("+b+")!=='undefined' && ("+b+")!=null":"true").split("$1a").join(f).split("$1").join(e).split("$2").join(g||i.$2||"")+"__.push('"})+"');}return __;")}function n(c,b){c._wrap=j(c,true,a.isArray(b)?b:[q.test(b)?b:a(b).html()]).join("")}function h(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function s(b){var a=document.createElement("div");a.appendChild(b.cloneNode(true));return a.innerHTML}function m(o){var n="_"+c,k,j,l={},e,p,h;for(e=0,p=o.length;e=0;h--)m(j[h]);m(k)}function m(j){var p,h=j,k,e,m;if(m=j.getAttribute(d)){while(h.parentNode&&(h=h.parentNode).nodeType===1&&!(p=h.getAttribute(d)));if(p!==m){h=h.parentNode?h.nodeType===11?0:h.getAttribute(d)||0:0;if(!(e=b[m])){e=f[m];e=g(e,b[h]||f[h]);e.key=++i;b[i]=e}c&&o(m)}j.removeAttribute(d)}else if(c&&(e=a.data(j,"tmplItem"))){o(e.key);b[e.key]=e;h=a.data(j.parentNode,"tmplItem");h=h?h.key:0}if(e){k=e;while(k&&k.key!=h){k.nodes.push(j);k=k.parent}delete e._ctnt;delete e._wrap;a.data(j,"tmplItem",e)}function o(a){a=a+n;e=l[a]=l[a]||g(e,b[e.parent.key+n]||e.parent)}}}function u(a,d,c,b){if(!a)return l.pop();l.push({_:a,tmpl:d,item:this,data:c,options:b})}function w(d,c,b){return a.tmpl(a.template(d),c,b,this)}function x(b,d){var c=b.options||{};c.wrapped=d;return a.tmpl(a.template(b.tmpl),b.data,c,b.item)}function v(d,c){var b=this._wrap;return a.map(a(a.isArray(b)?b.join(""):b).filter(d||"*"),function(a){return c?a.innerText||a.textContent:a.outerHTML||s(a)})}function t(){var b=this.nodes;a.tmpl(null,null,null,this).insertBefore(b[0]);a(b).remove()}})(jQuery);
11 |
--------------------------------------------------------------------------------
/lib/client/03.helpers.js:
--------------------------------------------------------------------------------
1 | // Helpers
2 | // -------
3 | // These prototype helpers affect ALL your client-side and shared code. They also exist server-side, so you can use them anywhere.
4 | // It is possible these helpers may conflict with an external third party library. Feel free to edit or delete this file if you don't want to use them.
5 | // You will always be able to obtain the latest version of this file by coping/merging it in from a new project.
6 | // Thanks to Addy Osmani for writing these and providing tests at https://github.com/addyosmani/socketstream-helpers
7 |
8 | /**
9 | .bind() support
10 | **/
11 |
12 | if ( !Function.prototype.bind ) {
13 | Function.prototype.bind = function( obj ) {
14 | var slice = [].slice,
15 | args = slice.call(arguments, 1),
16 | self = this,
17 | nop = function () {},
18 | bound = function () {
19 | return self.apply( this instanceof nop ? this : ( obj || {} ),
20 | args.concat( slice.call(arguments) ) );
21 | };
22 |
23 | nop.prototype = self.prototype;
24 | bound.prototype = new nop();
25 |
26 | return bound;
27 | };
28 | }
29 |
30 | /**
31 | Removes any duplicate entries from the current array
32 | **/
33 | if ( !String.prototype.unique ) {
34 | String.prototype.unique = function(b){
35 | var a = "", i, l = this.length,q="";
36 | for( i=0; i length) {
82 | return this.slice(0, length - 3) + "...";
83 | }else {
84 | return this;
85 | }
86 | };
87 | }
88 |
89 | /**
90 | Truncates the current array to the supplied length
91 | **/
92 | if ( !Array.prototype.truncate ) {
93 | Array.prototype.truncate = function(length){
94 | return this.slice(0, length);
95 | }
96 | }
97 |
98 | /**
99 | Returns a random character from the current string
100 | **/
101 | if ( !String.prototype.random ) {
102 | String.prototype.random = function( r ) {
103 | var i = 0, l = this.length;
104 | if( !r ) { r = this.length; }
105 | else if( r > 0 ) { r = r % l; }
106 | else { i = r; r = l + r % l; }
107 | return this[ Math.floor( r * Math.random() - i ) ];
108 | };
109 | }
110 |
111 | /**
112 | Returns a random element from the current array
113 | **/
114 | if ( !Array.prototype.random ) {
115 | Array.prototype.random = function( r ) {
116 | var i = 0, l = this.length;
117 | if( !r ) { r = this.length; }
118 | else if( r > 0 ) { r = r % l; }
119 | else { i = r; r = l + r % l; }
120 | return this[ Math.floor( r * Math.random() - i ) ];
121 | };
122 | }
123 |
124 | /**
125 | Boolean check to find out if a supplied character is in the current string
126 | **/
127 |
128 | if ( !String.prototype.include ) {
129 | String.prototype.include = function(value) {
130 | var i = this.length;
131 | while (i--) {
132 | if (this[i] === value) return true;
133 | }
134 | return false;
135 | };
136 | }
137 |
138 | /**
139 | Boolean check to find out if a supplied element/string is in the current array
140 | **/
141 | if ( !Array.prototype.include ) {
142 | Array.prototype.include = function(value) {
143 | var i = this.length;
144 | while (i--) {
145 | if (this[i] === value) return true;
146 | }
147 | return false;
148 | };
149 | }
150 |
151 | /**
152 | Boolean check to find out if a supplied character is in the current string
153 | **/
154 |
155 | if ( !String.prototype.contains ) {
156 | String.prototype.contains = String.prototype.include;
157 | }
158 |
159 | /**
160 | Boolean check to find out if a supplied character is in the current array
161 | **/
162 |
163 | if ( !Array.prototype.contains ) {
164 | Array.prototype.contains = Array.prototype.include;
165 | }
166 |
167 | /**
168 | Boolean check to find out if an array contains any elements
169 | **/
170 | if ( !Array.prototype.any ) {
171 | Array.prototype.any = function(){
172 | return !(this && this.constructor==Array && this.length==0);
173 | };
174 | }
175 |
176 | /**
177 | Sanitize content containing URLs or mailto/email references
178 | **/
179 | if ( !String.prototype.sanitize ) {
180 | String.prototype.sanitize = function(){
181 | return this.replace(/(([fh]+t+p+s?\:\/)+([^"'\s]+))/gi,"$1<\/a>").
182 | replace(/([a-z0-9\-\.]+\@[a-z0-9\-]+([^"'\s]+))/gi,"$1<\/a>");
183 | };
184 | }
--------------------------------------------------------------------------------
/lib/client/07.bootstrap-dropdown.js:
--------------------------------------------------------------------------------
1 | /* ============================================================
2 | * bootstrap-dropdown.js v1.4.0
3 | * http://twitter.github.com/bootstrap/javascript.html#dropdown
4 | * ============================================================
5 | * Copyright 2011 Twitter, Inc.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | * ============================================================ */
19 |
20 |
21 | !function( $ ){
22 |
23 | "use strict"
24 |
25 | /* DROPDOWN PLUGIN DEFINITION
26 | * ========================== */
27 |
28 | $.fn.dropdown = function ( selector ) {
29 | return this.each(function () {
30 | $(this).delegate(selector || d, 'click', function (e) {
31 | var li = $(this).parent('li')
32 | , isActive = li.hasClass('open')
33 |
34 | clearMenus()
35 | !isActive && li.toggleClass('open')
36 | return false
37 | })
38 | })
39 | }
40 |
41 | /* APPLY TO STANDARD DROPDOWN ELEMENTS
42 | * =================================== */
43 |
44 | var d = 'a.menu, .dropdown-toggle'
45 |
46 | function clearMenus() {
47 | $(d).parent('li').removeClass('open')
48 | }
49 |
50 | $(function () {
51 | $('html').bind("click", clearMenus)
52 | $('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
53 | })
54 |
55 | }( window.jQuery || window.ender );
56 |
--------------------------------------------------------------------------------
/lib/client/08.bootstrap-modal.js:
--------------------------------------------------------------------------------
1 | /* =========================================================
2 | * bootstrap-modal.js v1.4.0
3 | * http://twitter.github.com/bootstrap/javascript.html#modal
4 | * =========================================================
5 | * Copyright 2011 Twitter, Inc.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | * ========================================================= */
19 |
20 |
21 | !function( $ ){
22 |
23 | "use strict"
24 |
25 | /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
26 | * ======================================================= */
27 |
28 | var transitionEnd
29 |
30 | $(document).ready(function () {
31 |
32 | $.support.transition = (function () {
33 | var thisBody = document.body || document.documentElement
34 | , thisStyle = thisBody.style
35 | , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
36 | return support
37 | })()
38 |
39 | // set CSS transition event type
40 | if ( $.support.transition ) {
41 | transitionEnd = "TransitionEnd"
42 | if ( $.browser.webkit ) {
43 | transitionEnd = "webkitTransitionEnd"
44 | } else if ( $.browser.mozilla ) {
45 | transitionEnd = "transitionend"
46 | } else if ( $.browser.opera ) {
47 | transitionEnd = "oTransitionEnd"
48 | }
49 | }
50 |
51 | })
52 |
53 |
54 | /* MODAL PUBLIC CLASS DEFINITION
55 | * ============================= */
56 |
57 | var Modal = function ( content, options ) {
58 | this.settings = $.extend({}, $.fn.modal.defaults, options)
59 | this.$element = $(content)
60 | .delegate('.close', 'click.modal', $.proxy(this.hide, this))
61 |
62 | if ( this.settings.show ) {
63 | this.show()
64 | }
65 |
66 | return this
67 | }
68 |
69 | Modal.prototype = {
70 |
71 | toggle: function () {
72 | return this[!this.isShown ? 'show' : 'hide']()
73 | }
74 |
75 | , show: function () {
76 | var that = this
77 | this.isShown = true
78 | this.$element.trigger('show')
79 |
80 | escape.call(this)
81 | backdrop.call(this, function () {
82 | var transition = $.support.transition && that.$element.hasClass('fade')
83 |
84 | that.$element
85 | .appendTo(document.body)
86 | .show()
87 |
88 | if (transition) {
89 | that.$element[0].offsetWidth // force reflow
90 | }
91 |
92 | that.$element.addClass('in')
93 |
94 | transition ?
95 | that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) :
96 | that.$element.trigger('shown')
97 |
98 | })
99 |
100 | return this
101 | }
102 |
103 | , hide: function (e) {
104 | e && e.preventDefault()
105 |
106 | if ( !this.isShown ) {
107 | return this
108 | }
109 |
110 | var that = this
111 | this.isShown = false
112 |
113 | escape.call(this)
114 |
115 | this.$element
116 | .trigger('hide')
117 | .removeClass('in')
118 |
119 | $.support.transition && this.$element.hasClass('fade') ?
120 | hideWithTransition.call(this) :
121 | hideModal.call(this)
122 |
123 | return this
124 | }
125 |
126 | }
127 |
128 |
129 | /* MODAL PRIVATE METHODS
130 | * ===================== */
131 |
132 | function hideWithTransition() {
133 | // firefox drops transitionEnd events :{o
134 | var that = this
135 | , timeout = setTimeout(function () {
136 | that.$element.unbind(transitionEnd)
137 | hideModal.call(that)
138 | }, 500)
139 |
140 | this.$element.one(transitionEnd, function () {
141 | clearTimeout(timeout)
142 | hideModal.call(that)
143 | })
144 | }
145 |
146 | function hideModal (that) {
147 | this.$element
148 | .hide()
149 | .trigger('hidden')
150 |
151 | backdrop.call(this)
152 | }
153 |
154 | function backdrop ( callback ) {
155 | var that = this
156 | , animate = this.$element.hasClass('fade') ? 'fade' : ''
157 | if ( this.isShown && this.settings.backdrop ) {
158 | var doAnimate = $.support.transition && animate
159 |
160 | this.$backdrop = $('')
161 | .appendTo(document.body)
162 |
163 | if ( this.settings.backdrop != 'static' ) {
164 | this.$backdrop.click($.proxy(this.hide, this))
165 | }
166 |
167 | if ( doAnimate ) {
168 | this.$backdrop[0].offsetWidth // force reflow
169 | }
170 |
171 | this.$backdrop.addClass('in')
172 |
173 | doAnimate ?
174 | this.$backdrop.one(transitionEnd, callback) :
175 | callback()
176 |
177 | } else if ( !this.isShown && this.$backdrop ) {
178 | this.$backdrop.removeClass('in')
179 |
180 | $.support.transition && this.$element.hasClass('fade')?
181 | this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) :
182 | removeBackdrop.call(this)
183 |
184 | } else if ( callback ) {
185 | callback()
186 | }
187 | }
188 |
189 | function removeBackdrop() {
190 | this.$backdrop.remove()
191 | this.$backdrop = null
192 | }
193 |
194 | function escape() {
195 | var that = this
196 | if ( this.isShown && this.settings.keyboard ) {
197 | $(document).bind('keyup.modal', function ( e ) {
198 | if ( e.which == 27 ) {
199 | that.hide()
200 | }
201 | })
202 | } else if ( !this.isShown ) {
203 | $(document).unbind('keyup.modal')
204 | }
205 | }
206 |
207 |
208 | /* MODAL PLUGIN DEFINITION
209 | * ======================= */
210 |
211 | $.fn.modal = function ( options ) {
212 | var modal = this.data('modal')
213 |
214 | if (!modal) {
215 |
216 | if (typeof options == 'string') {
217 | options = {
218 | show: /show|toggle/.test(options)
219 | }
220 | }
221 |
222 | return this.each(function () {
223 | $(this).data('modal', new Modal(this, options))
224 | })
225 | }
226 |
227 | if ( options === true ) {
228 | return modal
229 | }
230 |
231 | if ( typeof options == 'string' ) {
232 | modal[options]()
233 | } else if ( modal ) {
234 | modal.toggle()
235 | }
236 |
237 | return this
238 | }
239 |
240 | $.fn.modal.Modal = Modal
241 |
242 | $.fn.modal.defaults = {
243 | backdrop: false
244 | , keyboard: false
245 | , show: false
246 | }
247 |
248 |
249 | /* MODAL DATA- IMPLEMENTATION
250 | * ========================== */
251 |
252 | $(document).ready(function () {
253 | $('body').delegate('[data-controls-modal]', 'click', function (e) {
254 | e.preventDefault()
255 | var $this = $(this).data('show', true)
256 | $('#' + $this.attr('data-controls-modal')).modal( $this.data() )
257 | })
258 | })
259 |
260 | }( window.jQuery || window.ender );
261 |
--------------------------------------------------------------------------------
/lib/client/09.bootstrap-alerts.js:
--------------------------------------------------------------------------------
1 | /* ==========================================================
2 | * bootstrap-alerts.js v1.4.0
3 | * http://twitter.github.com/bootstrap/javascript.html#alerts
4 | * ==========================================================
5 | * Copyright 2011 Twitter, Inc.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | * ========================================================== */
19 |
20 |
21 | !function( $ ){
22 |
23 | "use strict"
24 |
25 | /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
26 | * ======================================================= */
27 |
28 | var transitionEnd
29 |
30 | $(document).ready(function () {
31 |
32 | $.support.transition = (function () {
33 | var thisBody = document.body || document.documentElement
34 | , thisStyle = thisBody.style
35 | , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
36 | return support
37 | })()
38 |
39 | // set CSS transition event type
40 | if ( $.support.transition ) {
41 | transitionEnd = "TransitionEnd"
42 | if ( $.browser.webkit ) {
43 | transitionEnd = "webkitTransitionEnd"
44 | } else if ( $.browser.mozilla ) {
45 | transitionEnd = "transitionend"
46 | } else if ( $.browser.opera ) {
47 | transitionEnd = "oTransitionEnd"
48 | }
49 | }
50 |
51 | })
52 |
53 | /* ALERT CLASS DEFINITION
54 | * ====================== */
55 |
56 | var Alert = function ( content, options ) {
57 | if (options == 'close') return this.close.call(content)
58 | this.settings = $.extend({}, $.fn.alert.defaults, options)
59 | this.$element = $(content)
60 | .delegate(this.settings.selector, 'click', this.close)
61 | }
62 |
63 | Alert.prototype = {
64 |
65 | close: function (e) {
66 | var $element = $(this)
67 | , className = 'alert-message'
68 |
69 | $element = $element.hasClass(className) ? $element : $element.parent()
70 |
71 | e && e.preventDefault()
72 | $element.removeClass('in')
73 |
74 | function removeElement () {
75 | $element.remove()
76 | }
77 |
78 | $.support.transition && $element.hasClass('fade') ?
79 | $element.bind(transitionEnd, removeElement) :
80 | removeElement()
81 | }
82 |
83 | }
84 |
85 |
86 | /* ALERT PLUGIN DEFINITION
87 | * ======================= */
88 |
89 | $.fn.alert = function ( options ) {
90 |
91 | if ( options === true ) {
92 | return this.data('alert')
93 | }
94 |
95 | return this.each(function () {
96 | var $this = $(this)
97 | , data
98 |
99 | if ( typeof options == 'string' ) {
100 |
101 | data = $this.data('alert')
102 |
103 | if (typeof data == 'object') {
104 | return data[options].call( $this )
105 | }
106 |
107 | }
108 |
109 | $(this).data('alert', new Alert( this, options ))
110 |
111 | })
112 | }
113 |
114 | $.fn.alert.defaults = {
115 | selector: '.close'
116 | }
117 |
118 | $(document).ready(function () {
119 | new Alert($('body'), {
120 | selector: '.alert-message[data-alert] .close'
121 | })
122 | })
123 |
124 | }( window.jQuery || window.ender );
--------------------------------------------------------------------------------
/lib/client/10.bootstrap-buttons.js:
--------------------------------------------------------------------------------
1 | /* ============================================================
2 | * bootstrap-buttons.js v1.4.0
3 | * http://twitter.github.com/bootstrap/javascript.html#buttons
4 | * ============================================================
5 | * Copyright 2011 Twitter, Inc.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | * ============================================================ */
19 |
20 | !function( $ ){
21 |
22 | "use strict"
23 |
24 | function setState(el, state) {
25 | var d = 'disabled'
26 | , $el = $(el)
27 | , data = $el.data()
28 |
29 | state = state + 'Text'
30 | data.resetText || $el.data('resetText', $el.html())
31 |
32 | $el.html( data[state] || $.fn.button.defaults[state] )
33 |
34 | setTimeout(function () {
35 | state == 'loadingText' ?
36 | $el.addClass(d).attr(d, d) :
37 | $el.removeClass(d).removeAttr(d)
38 | }, 0)
39 | }
40 |
41 | function toggle(el) {
42 | $(el).toggleClass('active')
43 | }
44 |
45 | $.fn.button = function(options) {
46 | return this.each(function () {
47 | if (options == 'toggle') {
48 | return toggle(this)
49 | }
50 | options && setState(this, options)
51 | })
52 | }
53 |
54 | $.fn.button.defaults = {
55 | loadingText: 'loading...'
56 | }
57 |
58 | $(function () {
59 | $('body').delegate('.btn[data-toggle]', 'click', function () {
60 | $(this).button('toggle')
61 | })
62 | })
63 |
64 | }( window.jQuery || window.ender );
--------------------------------------------------------------------------------
/lib/client/12.css.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("css", function(config) {
2 | var indentUnit = config.indentUnit, type;
3 | function ret(style, tp) {type = tp; return style;}
4 |
5 | function tokenBase(stream, state) {
6 | var ch = stream.next();
7 | if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
8 | else if (ch == "/" && stream.eat("*")) {
9 | state.tokenize = tokenCComment;
10 | return tokenCComment(stream, state);
11 | }
12 | else if (ch == "<" && stream.eat("!")) {
13 | state.tokenize = tokenSGMLComment;
14 | return tokenSGMLComment(stream, state);
15 | }
16 | else if (ch == "=") ret(null, "compare");
17 | else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
18 | else if (ch == "\"" || ch == "'") {
19 | state.tokenize = tokenString(ch);
20 | return state.tokenize(stream, state);
21 | }
22 | else if (ch == "#") {
23 | stream.eatWhile(/[\w\\\-]/);
24 | return ret("atom", "hash");
25 | }
26 | else if (ch == "!") {
27 | stream.match(/^\s*\w*/);
28 | return ret("keyword", "important");
29 | }
30 | else if (/\d/.test(ch)) {
31 | stream.eatWhile(/[\w.%]/);
32 | return ret("number", "unit");
33 | }
34 | else if (/[,.+>*\/]/.test(ch)) {
35 | return ret(null, "select-op");
36 | }
37 | else if (/[;{}:\[\]]/.test(ch)) {
38 | return ret(null, ch);
39 | }
40 | else {
41 | stream.eatWhile(/[\w\\\-]/);
42 | return ret("variable", "variable");
43 | }
44 | }
45 |
46 | function tokenCComment(stream, state) {
47 | var maybeEnd = false, ch;
48 | while ((ch = stream.next()) != null) {
49 | if (maybeEnd && ch == "/") {
50 | state.tokenize = tokenBase;
51 | break;
52 | }
53 | maybeEnd = (ch == "*");
54 | }
55 | return ret("comment", "comment");
56 | }
57 |
58 | function tokenSGMLComment(stream, state) {
59 | var dashes = 0, ch;
60 | while ((ch = stream.next()) != null) {
61 | if (dashes >= 2 && ch == ">") {
62 | state.tokenize = tokenBase;
63 | break;
64 | }
65 | dashes = (ch == "-") ? dashes + 1 : 0;
66 | }
67 | return ret("comment", "comment");
68 | }
69 |
70 | function tokenString(quote) {
71 | return function(stream, state) {
72 | var escaped = false, ch;
73 | while ((ch = stream.next()) != null) {
74 | if (ch == quote && !escaped)
75 | break;
76 | escaped = !escaped && ch == "\\";
77 | }
78 | if (!escaped) state.tokenize = tokenBase;
79 | return ret("string", "string");
80 | };
81 | }
82 |
83 | return {
84 | startState: function(base) {
85 | return {tokenize: tokenBase,
86 | baseIndent: base || 0,
87 | stack: []};
88 | },
89 |
90 | token: function(stream, state) {
91 | if (stream.eatSpace()) return null;
92 | var style = state.tokenize(stream, state);
93 |
94 | var context = state.stack[state.stack.length-1];
95 | if (type == "hash" && context == "rule") style = "atom";
96 | else if (style == "variable") {
97 | if (context == "rule") style = "number";
98 | else if (!context || context == "@media{") style = "tag";
99 | }
100 |
101 | if (context == "rule" && /^[\{\};]$/.test(type))
102 | state.stack.pop();
103 | if (type == "{") {
104 | if (context == "@media") state.stack[state.stack.length-1] = "@media{";
105 | else state.stack.push("{");
106 | }
107 | else if (type == "}") state.stack.pop();
108 | else if (type == "@media") state.stack.push("@media");
109 | else if (context == "{" && type != "comment") state.stack.push("rule");
110 | return style;
111 | },
112 |
113 | indent: function(state, textAfter) {
114 | var n = state.stack.length;
115 | if (/^\}/.test(textAfter))
116 | n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
117 | return state.baseIndent + n * indentUnit;
118 | },
119 |
120 | electricChars: "}"
121 | };
122 | });
123 |
124 | CodeMirror.defineMIME("text/css", "css");
125 |
--------------------------------------------------------------------------------
/lib/client/12.diff.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("diff", function() {
2 | return {
3 | token: function(stream) {
4 | var ch = stream.next();
5 | stream.skipToEnd();
6 | if (ch == "+") return "plus";
7 | if (ch == "-") return "minus";
8 | if (ch == "@") return "rangeinfo";
9 | }
10 | };
11 | });
12 |
13 | CodeMirror.defineMIME("text/x-diff", "diff");
14 |
--------------------------------------------------------------------------------
/lib/client/12.gfm.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("gfm", function(config, parserConfig) {
2 | var mdMode = CodeMirror.getMode(config, "markdown");
3 | var aliases = {
4 | html: "htmlmixed",
5 | js: "javascript",
6 | json: "application/json",
7 | c: "text/x-csrc",
8 | "c++": "text/x-c++src",
9 | java: "text/x-java",
10 | csharp: "text/x-csharp",
11 | "c#": "text/x-csharp",
12 | };
13 |
14 | // make this lazy so that we don't need to load GFM last
15 | var getMode = (function () {
16 | var i, modes = {}, mimes = {}, mime;
17 |
18 | var list = CodeMirror.listModes();
19 | for (i = 0; i < list.length; i++) {
20 | modes[list[i]] = list[i];
21 | }
22 | var mimesList = CodeMirror.listMIMEs();
23 | for (i = 0; i < mimesList.length; i++) {
24 | mime = mimesList[i].mime;
25 | mimes[mime] = mimesList[i].mime;
26 | }
27 |
28 | for (var a in aliases) {
29 | if (aliases[a] in modes || aliases[a] in mimes)
30 | modes[a] = aliases[a];
31 | }
32 |
33 | return function (lang) {
34 | return modes[lang] ? CodeMirror.getMode(config, modes[lang]) : null;
35 | }
36 | }());
37 |
38 | function markdown(stream, state) {
39 | // intercept fenced code blocks
40 | if (stream.sol() && stream.match(/^```([\w+#]*)/)) {
41 | // try switching mode
42 | state.localMode = getMode(RegExp.$1)
43 | if (state.localMode)
44 | state.localState = state.localMode.startState();
45 |
46 | state.token = local;
47 | return 'code';
48 | }
49 |
50 | return mdMode.token(stream, state.mdState);
51 | }
52 |
53 | function local(stream, state) {
54 | if (stream.sol() && stream.match(/^```/)) {
55 | state.localMode = state.localState = null;
56 | state.token = markdown;
57 | return 'code';
58 | }
59 | else if (state.localMode) {
60 | return state.localMode.token(stream, state.localState);
61 | } else {
62 | stream.skipToEnd();
63 | return 'code';
64 | }
65 | }
66 |
67 | // custom handleText to prevent emphasis in the middle of a word
68 | // and add autolinking
69 | function handleText(stream, mdState) {
70 | var match;
71 | if (stream.match(/^\w+:\/\/\S+/)) {
72 | return 'linkhref';
73 | }
74 | if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) {
75 | return mdMode.getType(mdState);
76 | }
77 | if (match = stream.match(/^[^\[*\\<>` ]+/)) {
78 | var word = match[0];
79 | if (word[0] === '_' && word[word.length-1] === '_') {
80 | stream.backUp(word.length);
81 | return undefined;
82 | }
83 | return mdMode.getType(mdState);
84 | }
85 | if (stream.eatSpace()) {
86 | return null;
87 | }
88 | }
89 |
90 | return {
91 | startState: function() {
92 | var mdState = mdMode.startState();
93 | mdState.text = handleText;
94 | return {token: markdown, mode: "markdown", mdState: mdState,
95 | localMode: null, localState: null};
96 | },
97 |
98 | copyState: function(state) {
99 | return {token: state.token, mode: state.mode, mdState: CodeMirror.copyState(mdMode, state.mdState),
100 | localMode: state.localMode,
101 | localState: state.localMode ? CodeMirror.copyState(state.localMode, state.localState) : null};
102 | },
103 |
104 | token: function(stream, state) {
105 | return state.token(stream, state);
106 | }
107 | }
108 | });
109 |
--------------------------------------------------------------------------------
/lib/client/12.groovy.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("groovy", function(config, parserConfig) {
2 | function words(str) {
3 | var obj = {}, words = str.split(" ");
4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5 | return obj;
6 | }
7 | var keywords = words(
8 | "abstract as assert boolean break byte case catch char class const continue def default " +
9 | "do double else enum extends final finally float for goto if implements import in " +
10 | "instanceof int interface long native new package private protected public return " +
11 | "short static strictfp super switch synchronized threadsafe throw throws transient " +
12 | "try void volatile while");
13 | var blockKeywords = words("catch class do else finally for if switch try while enum interface def");
14 | var atoms = words("null true false this");
15 |
16 | var curPunc;
17 | function tokenBase(stream, state) {
18 | var ch = stream.next();
19 | if (ch == '"' || ch == "'") {
20 | return startString(ch, stream, state);
21 | }
22 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
23 | curPunc = ch;
24 | return null
25 | }
26 | if (/\d/.test(ch)) {
27 | stream.eatWhile(/[\w\.]/);
28 | if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); }
29 | return "number";
30 | }
31 | if (ch == "/") {
32 | if (stream.eat("*")) {
33 | state.tokenize.push(tokenComment);
34 | return tokenComment(stream, state);
35 | }
36 | if (stream.eat("/")) {
37 | stream.skipToEnd();
38 | return "comment";
39 | }
40 | if (expectExpression(state.lastToken)) {
41 | return startString(ch, stream, state);
42 | }
43 | }
44 | if (ch == "-" && stream.eat(">")) {
45 | curPunc = "->";
46 | return null;
47 | }
48 | if (/[+\-*&%=<>!?|\/~]/.test(ch)) {
49 | stream.eatWhile(/[+\-*&%=<>|~]/);
50 | return "operator";
51 | }
52 | stream.eatWhile(/[\w\$_]/);
53 | if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; }
54 | if (state.lastToken == ".") return "property";
55 | if (stream.eat(":")) { curPunc = "proplabel"; return "property"; }
56 | var cur = stream.current();
57 | if (atoms.propertyIsEnumerable(cur)) { return "atom"; }
58 | if (keywords.propertyIsEnumerable(cur)) {
59 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
60 | return "keyword";
61 | }
62 | return "word";
63 | }
64 | tokenBase.isBase = true;
65 |
66 | function startString(quote, stream, state) {
67 | var tripleQuoted = false;
68 | if (quote != "/" && stream.eat(quote)) {
69 | if (stream.eat(quote)) tripleQuoted = true;
70 | else return "string";
71 | }
72 | function t(stream, state) {
73 | var escaped = false, next, end = !tripleQuoted;
74 | while ((next = stream.next()) != null) {
75 | if (next == quote && !escaped) {
76 | if (!tripleQuoted) { break; }
77 | if (stream.match(quote + quote)) { end = true; break; }
78 | }
79 | if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
80 | state.tokenize.push(tokenBaseUntilBrace());
81 | return "string";
82 | }
83 | escaped = !escaped && next == "\\";
84 | }
85 | if (end) state.tokenize.pop();
86 | return "string";
87 | }
88 | state.tokenize.push(t);
89 | return t(stream, state);
90 | }
91 |
92 | function tokenBaseUntilBrace() {
93 | var depth = 1;
94 | function t(stream, state) {
95 | if (stream.peek() == "}") {
96 | depth--;
97 | if (depth == 0) {
98 | state.tokenize.pop();
99 | return state.tokenize[state.tokenize.length-1](stream, state);
100 | }
101 | } else if (stream.peek() == "{") {
102 | depth++;
103 | }
104 | return tokenBase(stream, state);
105 | }
106 | t.isBase = true;
107 | return t;
108 | }
109 |
110 | function tokenComment(stream, state) {
111 | var maybeEnd = false, ch;
112 | while (ch = stream.next()) {
113 | if (ch == "/" && maybeEnd) {
114 | state.tokenize.pop();
115 | break;
116 | }
117 | maybeEnd = (ch == "*");
118 | }
119 | return "comment";
120 | }
121 |
122 | function expectExpression(last) {
123 | return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
124 | last == "newstatement" || last == "keyword" || last == "proplabel";
125 | }
126 |
127 | function Context(indented, column, type, align, prev) {
128 | this.indented = indented;
129 | this.column = column;
130 | this.type = type;
131 | this.align = align;
132 | this.prev = prev;
133 | }
134 | function pushContext(state, col, type) {
135 | return state.context = new Context(state.indented, col, type, null, state.context);
136 | }
137 | function popContext(state) {
138 | var t = state.context.type;
139 | if (t == ")" || t == "]" || t == "}")
140 | state.indented = state.context.indented;
141 | return state.context = state.context.prev;
142 | }
143 |
144 | // Interface
145 |
146 | return {
147 | startState: function(basecolumn) {
148 | return {
149 | tokenize: [tokenBase],
150 | context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
151 | indented: 0,
152 | startOfLine: true,
153 | lastToken: null
154 | };
155 | },
156 |
157 | token: function(stream, state) {
158 | var ctx = state.context;
159 | if (stream.sol()) {
160 | if (ctx.align == null) ctx.align = false;
161 | state.indented = stream.indentation();
162 | state.startOfLine = true;
163 | // Automatic semicolon insertion
164 | if (ctx.type == "statement" && !expectExpression(state.lastToken)) {
165 | popContext(state); ctx = state.context;
166 | }
167 | }
168 | if (stream.eatSpace()) return null;
169 | curPunc = null;
170 | var style = state.tokenize[state.tokenize.length-1](stream, state);
171 | if (style == "comment") return style;
172 | if (ctx.align == null) ctx.align = true;
173 |
174 | if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
175 | // Handle indentation for {x -> \n ... }
176 | else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
177 | popContext(state);
178 | state.context.align = false;
179 | }
180 | else if (curPunc == "{") pushContext(state, stream.column(), "}");
181 | else if (curPunc == "[") pushContext(state, stream.column(), "]");
182 | else if (curPunc == "(") pushContext(state, stream.column(), ")");
183 | else if (curPunc == "}") {
184 | while (ctx.type == "statement") ctx = popContext(state);
185 | if (ctx.type == "}") ctx = popContext(state);
186 | while (ctx.type == "statement") ctx = popContext(state);
187 | }
188 | else if (curPunc == ctx.type) popContext(state);
189 | else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
190 | pushContext(state, stream.column(), "statement");
191 | state.startOfLine = false;
192 | state.lastToken = curPunc || style;
193 | return style;
194 | },
195 |
196 | indent: function(state, textAfter) {
197 | if (!state.tokenize[state.tokenize.length-1].isBase) return 0;
198 | var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
199 | if (ctx.type == "statement" && !expectExpression(state.lastToken)) ctx = ctx.prev;
200 | var closing = firstChar == ctx.type;
201 | if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
202 | else if (ctx.align) return ctx.column + (closing ? 0 : 1);
203 | else return ctx.indented + (closing ? 0 : config.indentUnit);
204 | },
205 |
206 | electricChars: "{}"
207 | };
208 | });
209 |
210 | CodeMirror.defineMIME("text/x-groovy", "groovy");
211 |
--------------------------------------------------------------------------------
/lib/client/12.haskell.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
2 |
3 | function switchState(source, setState, f) {
4 | setState(f);
5 | return f(source, setState);
6 | }
7 |
8 | // These should all be Unicode extended, as per the Haskell 2010 report
9 | var smallRE = /[a-z_]/;
10 | var largeRE = /[A-Z]/;
11 | var digitRE = /[0-9]/;
12 | var hexitRE = /[0-9A-Fa-f]/;
13 | var octitRE = /[0-7]/;
14 | var idRE = /[a-z_A-Z0-9']/;
15 | var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
16 | var specialRE = /[(),;[\]`{}]/;
17 | var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
18 |
19 | function normal(source, setState) {
20 | if (source.eatWhile(whiteCharRE)) {
21 | return null;
22 | }
23 |
24 | var ch = source.next();
25 | if (specialRE.test(ch)) {
26 | if (ch == '{' && source.eat('-')) {
27 | var t = "comment";
28 | if (source.eat('#')) {
29 | t = "meta";
30 | }
31 | return switchState(source, setState, ncomment(t, 1));
32 | }
33 | return null;
34 | }
35 |
36 | if (ch == '\'') {
37 | if (source.eat('\\')) {
38 | source.next(); // should handle other escapes here
39 | }
40 | else {
41 | source.next();
42 | }
43 | if (source.eat('\'')) {
44 | return "string";
45 | }
46 | return "error";
47 | }
48 |
49 | if (ch == '"') {
50 | return switchState(source, setState, stringLiteral);
51 | }
52 |
53 | if (largeRE.test(ch)) {
54 | source.eatWhile(idRE);
55 | if (source.eat('.')) {
56 | return "qualifier";
57 | }
58 | return "variable-2";
59 | }
60 |
61 | if (smallRE.test(ch)) {
62 | source.eatWhile(idRE);
63 | return "variable";
64 | }
65 |
66 | if (digitRE.test(ch)) {
67 | if (ch == '0') {
68 | if (source.eat(/[xX]/)) {
69 | source.eatWhile(hexitRE); // should require at least 1
70 | return "integer";
71 | }
72 | if (source.eat(/[oO]/)) {
73 | source.eatWhile(octitRE); // should require at least 1
74 | return "number";
75 | }
76 | }
77 | source.eatWhile(digitRE);
78 | var t = "number";
79 | if (source.eat('.')) {
80 | t = "number";
81 | source.eatWhile(digitRE); // should require at least 1
82 | }
83 | if (source.eat(/[eE]/)) {
84 | t = "number";
85 | source.eat(/[-+]/);
86 | source.eatWhile(digitRE); // should require at least 1
87 | }
88 | return t;
89 | }
90 |
91 | if (symbolRE.test(ch)) {
92 | if (ch == '-' && source.eat(/-/)) {
93 | source.eatWhile(/-/);
94 | if (!source.eat(symbolRE)) {
95 | source.skipToEnd();
96 | return "comment";
97 | }
98 | }
99 | var t = "variable";
100 | if (ch == ':') {
101 | t = "variable-2";
102 | }
103 | source.eatWhile(symbolRE);
104 | return t;
105 | }
106 |
107 | return "error";
108 | }
109 |
110 | function ncomment(type, nest) {
111 | if (nest == 0) {
112 | return normal;
113 | }
114 | return function(source, setState) {
115 | var currNest = nest;
116 | while (!source.eol()) {
117 | var ch = source.next();
118 | if (ch == '{' && source.eat('-')) {
119 | ++currNest;
120 | }
121 | else if (ch == '-' && source.eat('}')) {
122 | --currNest;
123 | if (currNest == 0) {
124 | setState(normal);
125 | return type;
126 | }
127 | }
128 | }
129 | setState(ncomment(type, currNest));
130 | return type;
131 | }
132 | }
133 |
134 | function stringLiteral(source, setState) {
135 | while (!source.eol()) {
136 | var ch = source.next();
137 | if (ch == '"') {
138 | setState(normal);
139 | return "string";
140 | }
141 | if (ch == '\\') {
142 | if (source.eol() || source.eat(whiteCharRE)) {
143 | setState(stringGap);
144 | return "string";
145 | }
146 | if (source.eat('&')) {
147 | }
148 | else {
149 | source.next(); // should handle other escapes here
150 | }
151 | }
152 | }
153 | setState(normal);
154 | return "error";
155 | }
156 |
157 | function stringGap(source, setState) {
158 | if (source.eat('\\')) {
159 | return switchState(source, setState, stringLiteral);
160 | }
161 | source.next();
162 | setState(normal);
163 | return "error";
164 | }
165 |
166 |
167 | var wellKnownWords = (function() {
168 | var wkw = {};
169 | function setType(t) {
170 | return function () {
171 | for (var i = 0; i < arguments.length; i++)
172 | wkw[arguments[i]] = t;
173 | }
174 | }
175 |
176 | setType("keyword")(
177 | "case", "class", "data", "default", "deriving", "do", "else", "foreign",
178 | "if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
179 | "module", "newtype", "of", "then", "type", "where", "_");
180 |
181 | setType("keyword")(
182 | "\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
183 |
184 | setType("builtin")(
185 | "!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
186 | "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
187 |
188 | setType("builtin")(
189 | "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
190 | "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
191 | "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
192 | "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
193 | "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
194 | "String", "True");
195 |
196 | setType("builtin")(
197 | "abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
198 | "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
199 | "compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
200 | "cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
201 | "elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
202 | "enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
203 | "flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
204 | "foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
205 | "fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
206 | "getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
207 | "isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
208 | "lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
209 | "mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
210 | "minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
211 | "otherwise", "pi", "pred", "print", "product", "properFraction",
212 | "putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
213 | "readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
214 | "realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
215 | "round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
216 | "sequence", "sequence_", "show", "showChar", "showList", "showParen",
217 | "showString", "shows", "showsPrec", "significand", "signum", "sin",
218 | "sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
219 | "tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
220 | "toRational", "truncate", "uncurry", "undefined", "unlines", "until",
221 | "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
222 | "zip3", "zipWith", "zipWith3");
223 |
224 | return wkw;
225 | })();
226 |
227 |
228 |
229 | return {
230 | startState: function () { return { f: normal }; },
231 | copyState: function (s) { return { f: s.f }; },
232 |
233 | token: function(stream, state) {
234 | var t = state.f(stream, function(s) { state.f = s; });
235 | var w = stream.current();
236 | return (w in wellKnownWords) ? wellKnownWords[w] : t;
237 | }
238 | };
239 |
240 | });
241 |
242 | CodeMirror.defineMIME("text/x-haskell", "haskell");
243 |
--------------------------------------------------------------------------------
/lib/client/12.htmlembedded.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
2 |
3 | //config settings
4 | var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
5 | scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
6 |
7 | //inner modes
8 | var scriptingMode, htmlMixedMode;
9 |
10 | //tokenizer when in html mode
11 | function htmlDispatch(stream, state) {
12 | if (stream.match(scriptStartRegex, false)) {
13 | state.token=scriptingDispatch;
14 | return scriptingMode.token(stream, state.scriptState);
15 | }
16 | else
17 | return htmlMixedMode.token(stream, state.htmlState);
18 | }
19 |
20 | //tokenizer when in scripting mode
21 | function scriptingDispatch(stream, state) {
22 | if (stream.match(scriptEndRegex, false)) {
23 | state.token=htmlDispatch;
24 | return htmlMixedMode.token(stream, state.htmlState);
25 | }
26 | else
27 | return scriptingMode.token(stream, state.scriptState);
28 | }
29 |
30 |
31 | return {
32 | startState: function() {
33 | scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
34 | htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
35 | return {
36 | token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
37 | htmlState : htmlMixedMode.startState(),
38 | scriptState : scriptingMode.startState()
39 | }
40 | },
41 |
42 | token: function(stream, state) {
43 | return state.token(stream, state);
44 | },
45 |
46 | indent: function(state, textAfter) {
47 | if (state.token == htmlDispatch)
48 | return htmlMixedMode.indent(state.htmlState, textAfter);
49 | else
50 | return scriptingMode.indent(state.scriptState, textAfter);
51 | },
52 |
53 | copyState: function(state) {
54 | return {
55 | token : state.token,
56 | htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
57 | scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
58 | }
59 | },
60 |
61 |
62 | electricChars: "/{}:"
63 | }
64 | });
65 |
66 | CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
67 | CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
68 | CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
69 |
--------------------------------------------------------------------------------
/lib/client/12.htmlmixed.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
2 | var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
3 | var jsMode = CodeMirror.getMode(config, "javascript");
4 | var cssMode = CodeMirror.getMode(config, "css");
5 |
6 | function html(stream, state) {
7 | var style = htmlMode.token(stream, state.htmlState);
8 | if (style == "tag" && stream.current() == ">" && state.htmlState.context) {
9 | if (/^script$/i.test(state.htmlState.context.tagName)) {
10 | state.token = javascript;
11 | state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12 | state.mode = "javascript";
13 | }
14 | else if (/^style$/i.test(state.htmlState.context.tagName)) {
15 | state.token = css;
16 | state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17 | state.mode = "css";
18 | }
19 | }
20 | return style;
21 | }
22 | function maybeBackup(stream, pat, style) {
23 | var cur = stream.current();
24 | var close = cur.search(pat);
25 | if (close > -1) stream.backUp(cur.length - close);
26 | return style;
27 | }
28 | function javascript(stream, state) {
29 | if (stream.match(/^<\/\s*script\s*>/i, false)) {
30 | state.token = html;
31 | state.curState = null;
32 | state.mode = "html";
33 | return html(stream, state);
34 | }
35 | return maybeBackup(stream, /<\/\s*script\s*>/,
36 | jsMode.token(stream, state.localState));
37 | }
38 | function css(stream, state) {
39 | if (stream.match(/^<\/\s*style\s*>/i, false)) {
40 | state.token = html;
41 | state.localState = null;
42 | state.mode = "html";
43 | return html(stream, state);
44 | }
45 | return maybeBackup(stream, /<\/\s*style\s*>/,
46 | cssMode.token(stream, state.localState));
47 | }
48 |
49 | return {
50 | startState: function() {
51 | var state = htmlMode.startState();
52 | return {token: html, localState: null, mode: "html", htmlState: state};
53 | },
54 |
55 | copyState: function(state) {
56 | if (state.localState)
57 | var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
58 | return {token: state.token, localState: local, mode: state.mode,
59 | htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
60 | },
61 |
62 | token: function(stream, state) {
63 | return state.token(stream, state);
64 | },
65 |
66 | indent: function(state, textAfter) {
67 | if (state.token == html || /^\s*<\//.test(textAfter))
68 | return htmlMode.indent(state.htmlState, textAfter);
69 | else if (state.token == javascript)
70 | return jsMode.indent(state.localState, textAfter);
71 | else
72 | return cssMode.indent(state.localState, textAfter);
73 | },
74 |
75 | compareStates: function(a, b) {
76 | return htmlMode.compareStates(a.htmlState, b.htmlState);
77 | },
78 |
79 | electricChars: "/{}:"
80 | }
81 | });
82 |
83 | CodeMirror.defineMIME("text/html", "htmlmixed");
84 |
--------------------------------------------------------------------------------
/lib/client/12.jinja2.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("jinja2", function(config, parserConf) {
2 | var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false",
3 | "loop", "none", "self", "super", "if", "as", "not", "and",
4 | "else", "import", "with", "without", "context"];
5 | keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
6 |
7 | function tokenBase (stream, state) {
8 | var ch = stream.next();
9 | if (ch == "{") {
10 | if (ch = stream.eat(/\{|%|#/)) {
11 | stream.eat("-");
12 | state.tokenize = inTag(ch);
13 | return "tag";
14 | }
15 | }
16 | }
17 | function inTag (close) {
18 | if (close == "{") {
19 | close = "}";
20 | }
21 | return function (stream, state) {
22 | var ch = stream.next();
23 | if ((ch == close || (ch == "-" && stream.eat(close)))
24 | && stream.eat("}")) {
25 | state.tokenize = tokenBase;
26 | return "tag";
27 | }
28 | if (stream.match(keywords)) {
29 | return "keyword";
30 | }
31 | return close == "#" ? "comment" : "string";
32 | };
33 | }
34 | return {
35 | startState: function () {
36 | return {tokenize: tokenBase};
37 | },
38 | token: function (stream, state) {
39 | return state.tokenize(stream, state);
40 | }
41 | };
42 | });
43 |
--------------------------------------------------------------------------------
/lib/client/12.less.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("less", function(config) {
2 | var indentUnit = config.indentUnit, type;
3 | function ret(style, tp) {type = tp; return style;}
4 | //html5 tags
5 | var tags = ["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"];
6 |
7 | function inTagsArray(val){
8 | for(var i=0; i*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/]
51 | return ret(null, "select-op");
52 | }
53 | else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]]
54 | if(ch == ":"){
55 | stream.eatWhile(/[active|hover|link|visited]/);
56 | if( stream.current().match(/[active|hover|link|visited]/)){
57 | return ret("tag", "tag");
58 | }else{
59 | return ret(null, ch);
60 | }
61 | }else{
62 | return ret(null, ch);
63 | }
64 | }
65 | else if (ch == ".") { // lesscss
66 | stream.eatWhile(/[\a-zA-Z0-9\-_]/);
67 | return ret("tag", "tag");
68 | }
69 | else if (ch == "#") { // lesscss
70 | stream.match(/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/);
71 | if(stream.current().length >1){
72 | if(stream.current().match(/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/) != null){
73 | return ret("number", "unit");
74 | }else{
75 | stream.eatWhile(/[\w\-]/);
76 | return ret("atom", "tag");
77 | }
78 | }else{
79 | stream.eatWhile(/[\w\-]/);
80 | return ret("atom", "tag");
81 | }
82 | }
83 | else if (ch == "&") {
84 | stream.eatWhile(/[\w\-]/);
85 | return ret(null, ch);
86 | }
87 | else {
88 | stream.eatWhile(/[\w\\\-_.%{]/);
89 | if( stream.eat("(") ){ // lesscss
90 | return ret(null, ch);
91 | }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc...
92 | return ret("number", "unit");
93 | }else if( inTagsArray(stream.current()) ){ // lesscss match html tags
94 | return ret("tag", "tag");
95 | }else{
96 | return ret("variable", "variable");
97 | }
98 | }
99 |
100 | }
101 |
102 | function tokenSComment(stream, state) {// SComment = Slash comment
103 | stream.skipToEnd();
104 | state.tokenize = tokenBase;
105 | return ret("comment", "comment");
106 | }
107 |
108 | function tokenCComment(stream, state) {
109 | var maybeEnd = false, ch;
110 | while ((ch = stream.next()) != null) {
111 | if (maybeEnd && ch == "/") {
112 | state.tokenize = tokenBase;
113 | break;
114 | }
115 | maybeEnd = (ch == "*");
116 | }
117 | return ret("comment", "comment");
118 | }
119 |
120 | function tokenSGMLComment(stream, state) {
121 | var dashes = 0, ch;
122 | while ((ch = stream.next()) != null) {
123 | if (dashes >= 2 && ch == ">") {
124 | state.tokenize = tokenBase;
125 | break;
126 | }
127 | dashes = (ch == "-") ? dashes + 1 : 0;
128 | }
129 | return ret("comment", "comment");
130 | }
131 |
132 | function tokenString(quote) {
133 | return function(stream, state) {
134 | var escaped = false, ch;
135 | while ((ch = stream.next()) != null) {
136 | if (ch == quote && !escaped)
137 | break;
138 | escaped = !escaped && ch == "\\";
139 | }
140 | if (!escaped) state.tokenize = tokenBase;
141 | return ret("string", "string");
142 | };
143 | }
144 |
145 | return {
146 | startState: function(base) {
147 | return {tokenize: tokenBase,
148 | baseIndent: base || 0,
149 | stack: []};
150 | },
151 |
152 | token: function(stream, state) {
153 | if (stream.eatSpace()) return null;
154 | var style = state.tokenize(stream, state);
155 |
156 | var context = state.stack[state.stack.length-1];
157 | if (type == "hash" && context == "rule") style = "atom";
158 | else if (style == "variable") {
159 | if (context == "rule") style = null; //"tag"
160 | else if (!context || context == "@media{") style = "tag";
161 | }
162 |
163 | if (context == "rule" && /^[\{\};]$/.test(type))
164 | state.stack.pop();
165 | if (type == "{") {
166 | if (context == "@media") state.stack[state.stack.length-1] = "@media{";
167 | else state.stack.push("{");
168 | }
169 | else if (type == "}") state.stack.pop();
170 | else if (type == "@media") state.stack.push("@media");
171 | else if (context == "{" && type != "comment") state.stack.push("rule");
172 | return style;
173 | },
174 |
175 | indent: function(state, textAfter) {
176 | var n = state.stack.length;
177 | if (/^\}/.test(textAfter))
178 | n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
179 | return state.baseIndent + n * indentUnit;
180 | },
181 |
182 | electricChars: "}"
183 | };
184 | });
185 |
186 | CodeMirror.defineMIME("text/less", "less");
187 |
--------------------------------------------------------------------------------
/lib/client/12.lua.js:
--------------------------------------------------------------------------------
1 | // LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
2 | // CodeMirror 1 mode.
3 | // highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
4 |
5 | CodeMirror.defineMode("lua", function(config, parserConfig) {
6 | var indentUnit = config.indentUnit;
7 |
8 | function prefixRE(words) {
9 | return new RegExp("^(?:" + words.join("|") + ")", "i");
10 | }
11 | function wordRE(words) {
12 | return new RegExp("^(?:" + words.join("|") + ")$", "i");
13 | }
14 | var specials = wordRE(parserConfig.specials || []);
15 |
16 | // long list of standard functions from lua manual
17 | var builtins = wordRE([
18 | "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
19 | "loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require",
20 | "select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
21 |
22 | "coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
23 |
24 | "debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable",
25 | "debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable",
26 | "debug.setupvalue","debug.traceback",
27 |
28 | "close","flush","lines","read","seek","setvbuf","write",
29 |
30 | "io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin",
31 | "io.stdout","io.tmpfile","io.type","io.write",
32 |
33 | "math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg",
34 | "math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max",
35 | "math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh",
36 | "math.sqrt","math.tan","math.tanh",
37 |
38 | "os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale",
39 | "os.time","os.tmpname",
40 |
41 | "package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload",
42 | "package.seeall",
43 |
44 | "string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub",
45 | "string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
46 |
47 | "table.concat","table.insert","table.maxn","table.remove","table.sort"
48 | ]);
49 | var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
50 | "true","function", "end", "if", "then", "else", "do",
51 | "while", "repeat", "until", "for", "in", "local" ]);
52 |
53 | var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
54 | var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
55 | var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]);
56 |
57 | function readBracket(stream) {
58 | var level = 0;
59 | while (stream.eat("=")) ++level;
60 | stream.eat("[");
61 | return level;
62 | }
63 |
64 | function normal(stream, state) {
65 | var ch = stream.next();
66 | if (ch == "-" && stream.eat("-")) {
67 | if (stream.eat("["))
68 | return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
69 | stream.skipToEnd();
70 | return "comment";
71 | }
72 | if (ch == "\"" || ch == "'")
73 | return (state.cur = string(ch))(stream, state);
74 | if (ch == "[" && /[\[=]/.test(stream.peek()))
75 | return (state.cur = bracketed(readBracket(stream), "string"))(stream, state);
76 | if (/\d/.test(ch)) {
77 | stream.eatWhile(/[\w.%]/);
78 | return "number";
79 | }
80 | if (/[\w_]/.test(ch)) {
81 | stream.eatWhile(/[\w\\\-_.]/);
82 | return "variable";
83 | }
84 | return null;
85 | }
86 |
87 | function bracketed(level, style) {
88 | return function(stream, state) {
89 | var curlev = null, ch;
90 | while ((ch = stream.next()) != null) {
91 | if (curlev == null) {if (ch == "]") curlev = 0;}
92 | else if (ch == "=") ++curlev;
93 | else if (ch == "]" && curlev == level) { state.cur = normal; break; }
94 | else curlev = null;
95 | }
96 | return style;
97 | };
98 | }
99 |
100 | function string(quote) {
101 | return function(stream, state) {
102 | var escaped = false, ch;
103 | while ((ch = stream.next()) != null) {
104 | if (ch == quote && !escaped) break;
105 | escaped = !escaped && ch == "\\";
106 | }
107 | if (!escaped) state.cur = normal;
108 | return "string";
109 | };
110 | }
111 |
112 | return {
113 | startState: function(basecol) {
114 | return {basecol: basecol || 0, indentDepth: 0, cur: normal};
115 | },
116 |
117 | token: function(stream, state) {
118 | if (stream.eatSpace()) return null;
119 | var style = state.cur(stream, state);
120 | var word = stream.current();
121 | if (style == "variable") {
122 | if (keywords.test(word)) style = "keyword";
123 | else if (builtins.test(word)) style = "builtin";
124 | else if (specials.test(word)) style = "variable-2";
125 | }
126 | if ((style != "comment") && (style != "string")){
127 | if (indentTokens.test(word)) ++state.indentDepth;
128 | else if (dedentTokens.test(word)) --state.indentDepth;
129 | }
130 | return style;
131 | },
132 |
133 | indent: function(state, textAfter) {
134 | var closing = dedentPartial.test(textAfter);
135 | return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0));
136 | }
137 | };
138 | });
139 |
140 | CodeMirror.defineMIME("text/x-lua", "lua");
141 |
--------------------------------------------------------------------------------
/lib/client/12.markdown.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
2 |
3 | var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true });
4 |
5 | var header = 'header'
6 | , code = 'comment'
7 | , quote = 'quote'
8 | , list = 'string'
9 | , hr = 'hr'
10 | , linktext = 'link'
11 | , linkhref = 'string'
12 | , em = 'em'
13 | , strong = 'strong'
14 | , emstrong = 'emstrong';
15 |
16 | var hrRE = /^[*-=_]/
17 | , ulRE = /^[*-+]\s+/
18 | , olRE = /^[0-9]\.\s+/
19 | , headerRE = /^(?:\={3,}|-{3,})$/
20 | , codeRE = /^(k:\t|\s{4,})/
21 | , textRE = /^[^\[*_\\<>`]+/;
22 |
23 | function switchInline(stream, state, f) {
24 | state.f = state.inline = f;
25 | return f(stream, state);
26 | }
27 |
28 | function switchBlock(stream, state, f) {
29 | state.f = state.block = f;
30 | return f(stream, state);
31 | }
32 |
33 |
34 | // Blocks
35 |
36 | function blockNormal(stream, state) {
37 | if (stream.match(codeRE)) {
38 | stream.skipToEnd();
39 | return code;
40 | }
41 |
42 | if (stream.eatSpace()) {
43 | return null;
44 | }
45 |
46 | if (stream.peek() === '#' || stream.match(headerRE)) {
47 | stream.skipToEnd();
48 | return header;
49 | }
50 | if (stream.eat('>')) {
51 | state.indentation++;
52 | return quote;
53 | }
54 | if (stream.peek() === '[') {
55 | return switchInline(stream, state, footnoteLink);
56 | }
57 | if (hrRE.test(stream.peek())) {
58 | var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$');
59 | if (stream.match(re, true)) {
60 | return hr;
61 | }
62 | }
63 |
64 | var match;
65 | if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
66 | state.indentation += match[0].length;
67 | return list;
68 | }
69 |
70 | return switchInline(stream, state, state.inline);
71 | }
72 |
73 | function htmlBlock(stream, state) {
74 | var style = htmlMode.token(stream, state.htmlState);
75 | if (style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) {
76 | state.f = inlineNormal;
77 | state.block = blockNormal;
78 | }
79 | return style;
80 | }
81 |
82 |
83 | // Inline
84 | function getType(state) {
85 | return state.strong ? (state.em ? emstrong : strong)
86 | : (state.em ? em : null);
87 | }
88 |
89 | function handleText(stream, state) {
90 | if (stream.match(textRE, true)) {
91 | return getType(state);
92 | }
93 | return undefined;
94 | }
95 |
96 | function inlineNormal(stream, state) {
97 | var style = state.text(stream, state)
98 | if (typeof style !== 'undefined')
99 | return style;
100 |
101 | var ch = stream.next();
102 |
103 | if (ch === '\\') {
104 | stream.next();
105 | return getType(state);
106 | }
107 | if (ch === '`') {
108 | return switchInline(stream, state, inlineElement(code, '`'));
109 | }
110 | if (ch === '[') {
111 | return switchInline(stream, state, linkText);
112 | }
113 | if (ch === '<' && stream.match(/^\w/, false)) {
114 | stream.backUp(1);
115 | return switchBlock(stream, state, htmlBlock);
116 | }
117 |
118 | var t = getType(state);
119 | if (ch === '*' || ch === '_') {
120 | if (stream.eat(ch)) {
121 | return (state.strong = !state.strong) ? getType(state) : t;
122 | }
123 | return (state.em = !state.em) ? getType(state) : t;
124 | }
125 |
126 | return getType(state);
127 | }
128 |
129 | function linkText(stream, state) {
130 | while (!stream.eol()) {
131 | var ch = stream.next();
132 | if (ch === '\\') stream.next();
133 | if (ch === ']') {
134 | state.inline = state.f = linkHref;
135 | return linktext;
136 | }
137 | }
138 | return linktext;
139 | }
140 |
141 | function linkHref(stream, state) {
142 | stream.eatSpace();
143 | var ch = stream.next();
144 | if (ch === '(' || ch === '[') {
145 | return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']'));
146 | }
147 | return 'error';
148 | }
149 |
150 | function footnoteLink(stream, state) {
151 | if (stream.match(/^[^\]]*\]:/, true)) {
152 | state.f = footnoteUrl;
153 | return linktext;
154 | }
155 | return switchInline(stream, state, inlineNormal);
156 | }
157 |
158 | function footnoteUrl(stream, state) {
159 | stream.eatSpace();
160 | stream.match(/^[^\s]+/, true);
161 | state.f = state.inline = inlineNormal;
162 | return linkhref;
163 | }
164 |
165 | function inlineRE(endChar) {
166 | if (!inlineRE[endChar]) {
167 | // match any not-escaped-non-endChar and any escaped char
168 | // then match endChar or eol
169 | inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)');
170 | }
171 | return inlineRE[endChar];
172 | }
173 |
174 | function inlineElement(type, endChar, next) {
175 | next = next || inlineNormal;
176 | return function(stream, state) {
177 | stream.match(inlineRE(endChar));
178 | state.inline = state.f = next;
179 | return type;
180 | };
181 | }
182 |
183 | return {
184 | startState: function() {
185 | return {
186 | f: blockNormal,
187 |
188 | block: blockNormal,
189 | htmlState: htmlMode.startState(),
190 | indentation: 0,
191 |
192 | inline: inlineNormal,
193 | text: handleText,
194 | em: false,
195 | strong: false
196 | };
197 | },
198 |
199 | copyState: function(s) {
200 | return {
201 | f: s.f,
202 |
203 | block: s.block,
204 | htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
205 | indentation: s.indentation,
206 |
207 | inline: s.inline,
208 | text: s.text,
209 | em: s.em,
210 | strong: s.strong
211 | };
212 | },
213 |
214 | token: function(stream, state) {
215 | if (stream.sol()) {
216 | state.f = state.block;
217 | var previousIndentation = state.indentation
218 | , currentIndentation = 0;
219 | while (previousIndentation > 0) {
220 | if (stream.eat(' ')) {
221 | previousIndentation--;
222 | currentIndentation++;
223 | } else if (previousIndentation >= 4 && stream.eat('\t')) {
224 | previousIndentation -= 4;
225 | currentIndentation += 4;
226 | } else {
227 | break;
228 | }
229 | }
230 | state.indentation = currentIndentation;
231 |
232 | if (currentIndentation > 0) return null;
233 | }
234 | return state.f(stream, state);
235 | },
236 |
237 | getType: getType
238 | };
239 |
240 | });
241 |
242 | CodeMirror.defineMIME("text/x-markdown", "markdown");
243 |
--------------------------------------------------------------------------------
/lib/client/12.mysql.js:
--------------------------------------------------------------------------------
1 | /*
2 | * MySQL Mode for CodeMirror 2 by MySQL-Tools
3 | * @author James Thorne (partydroid)
4 | * @link http://github.com/partydroid/MySQL-Tools
5 | * @link http://mysqltools.org
6 | * @version 02/Jan/2012
7 | */
8 | CodeMirror.defineMode("mysql", function(config) {
9 | var indentUnit = config.indentUnit;
10 | var curPunc;
11 |
12 | function wordRegexp(words) {
13 | return new RegExp("^(?:" + words.join("|") + ")$", "i");
14 | }
15 | var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
16 | "isblank", "isliteral", "union", "a"]);
17 | var keywords = wordRegexp([
18 | ('ACCESSIBLE'),('ALTER'),('AS'),('BEFORE'),('BINARY'),('BY'),('CASE'),('CHARACTER'),('COLUMN'),('CONTINUE'),('CROSS'),('CURRENT_TIMESTAMP'),('DATABASE'),('DAY_MICROSECOND'),('DEC'),('DEFAULT'),
19 | ('DESC'),('DISTINCT'),('DOUBLE'),('EACH'),('ENCLOSED'),('EXIT'),('FETCH'),('FLOAT8'),('FOREIGN'),('GRANT'),('HIGH_PRIORITY'),('HOUR_SECOND'),('IN'),('INNER'),('INSERT'),('INT2'),('INT8'),
20 | ('INTO'),('JOIN'),('KILL'),('LEFT'),('LINEAR'),('LOCALTIME'),('LONG'),('LOOP'),('MATCH'),('MEDIUMTEXT'),('MINUTE_SECOND'),('NATURAL'),('NULL'),('OPTIMIZE'),('OR'),('OUTER'),('PRIMARY'),
21 | ('RANGE'),('READ_WRITE'),('REGEXP'),('REPEAT'),('RESTRICT'),('RIGHT'),('SCHEMAS'),('SENSITIVE'),('SHOW'),('SPECIFIC'),('SQLSTATE'),('SQL_CALC_FOUND_ROWS'),('STARTING'),('TERMINATED'),
22 | ('TINYINT'),('TRAILING'),('UNDO'),('UNLOCK'),('USAGE'),('UTC_DATE'),('VALUES'),('VARCHARACTER'),('WHERE'),('WRITE'),('ZEROFILL'),('ALL'),('AND'),('ASENSITIVE'),('BIGINT'),('BOTH'),('CASCADE'),
23 | ('CHAR'),('COLLATE'),('CONSTRAINT'),('CREATE'),('CURRENT_TIME'),('CURSOR'),('DAY_HOUR'),('DAY_SECOND'),('DECLARE'),('DELETE'),('DETERMINISTIC'),('DIV'),('DUAL'),('ELSEIF'),('EXISTS'),('FALSE'),
24 | ('FLOAT4'),('FORCE'),('FULLTEXT'),('HAVING'),('HOUR_MINUTE'),('IGNORE'),('INFILE'),('INSENSITIVE'),('INT1'),('INT4'),('INTERVAL'),('ITERATE'),('KEYS'),('LEAVE'),('LIMIT'),('LOAD'),('LOCK'),
25 | ('LONGTEXT'),('MASTER_SSL_VERIFY_SERVER_CERT'),('MEDIUMINT'),('MINUTE_MICROSECOND'),('MODIFIES'),('NO_WRITE_TO_BINLOG'),('ON'),('OPTIONALLY'),('OUT'),('PRECISION'),('PURGE'),('READS'),
26 | ('REFERENCES'),('RENAME'),('REQUIRE'),('REVOKE'),('SCHEMA'),('SELECT'),('SET'),('SPATIAL'),('SQLEXCEPTION'),('SQL_BIG_RESULT'),('SSL'),('TABLE'),('TINYBLOB'),('TO'),('TRUE'),('UNIQUE'),
27 | ('UPDATE'),('USING'),('UTC_TIMESTAMP'),('VARCHAR'),('WHEN'),('WITH'),('YEAR_MONTH'),('ADD'),('ANALYZE'),('ASC'),('BETWEEN'),('BLOB'),('CALL'),('CHANGE'),('CHECK'),('CONDITION'),('CONVERT'),
28 | ('CURRENT_DATE'),('CURRENT_USER'),('DATABASES'),('DAY_MINUTE'),('DECIMAL'),('DELAYED'),('DESCRIBE'),('DISTINCTROW'),('DROP'),('ELSE'),('ESCAPED'),('EXPLAIN'),('FLOAT'),('FOR'),('FROM'),
29 | ('GROUP'),('HOUR_MICROSECOND'),('IF'),('INDEX'),('INOUT'),('INT'),('INT3'),('INTEGER'),('IS'),('KEY'),('LEADING'),('LIKE'),('LINES'),('LOCALTIMESTAMP'),('LONGBLOB'),('LOW_PRIORITY'),
30 | ('MEDIUMBLOB'),('MIDDLEINT'),('MOD'),('NOT'),('NUMERIC'),('OPTION'),('ORDER'),('OUTFILE'),('PROCEDURE'),('READ'),('REAL'),('RELEASE'),('REPLACE'),('RETURN'),('RLIKE'),('SECOND_MICROSECOND'),
31 | ('SEPARATOR'),('SMALLINT'),('SQL'),('SQLWARNING'),('SQL_SMALL_RESULT'),('STRAIGHT_JOIN'),('THEN'),('TINYTEXT'),('TRIGGER'),('UNION'),('UNSIGNED'),('USE'),('UTC_TIME'),('VARBINARY'),('VARYING'),
32 | ('WHILE'),('XOR'),('FULL'),('COLUMNS'),('MIN'),('MAX'),('STDEV'),('COUNT')
33 | ]);
34 | var operatorChars = /[*+\-<>=&|]/;
35 |
36 | function tokenBase(stream, state) {
37 | var ch = stream.next();
38 | curPunc = null;
39 | if (ch == "$" || ch == "?") {
40 | stream.match(/^[\w\d]*/);
41 | return "variable-2";
42 | }
43 | else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
44 | stream.match(/^[^\s\u00a0>]*>?/);
45 | return "atom";
46 | }
47 | else if (ch == "\"" || ch == "'") {
48 | state.tokenize = tokenLiteral(ch);
49 | return state.tokenize(stream, state);
50 | }
51 | else if (ch == "`") {
52 | state.tokenize = tokenOpLiteral(ch);
53 | return state.tokenize(stream, state);
54 | }
55 | else if (/[{}\(\),\.;\[\]]/.test(ch)) {
56 | curPunc = ch;
57 | return null;
58 | }
59 | else if (ch == "-") {
60 | ch2 = stream.next();
61 | if(ch2=="-")
62 | {
63 | stream.skipToEnd();
64 | return "comment";
65 | }
66 |
67 | }
68 | else if (operatorChars.test(ch)) {
69 | stream.eatWhile(operatorChars);
70 | return null;
71 | }
72 | else if (ch == ":") {
73 | stream.eatWhile(/[\w\d\._\-]/);
74 | return "atom";
75 | }
76 | else {
77 | stream.eatWhile(/[_\w\d]/);
78 | if (stream.eat(":")) {
79 | stream.eatWhile(/[\w\d_\-]/);
80 | return "atom";
81 | }
82 | var word = stream.current(), type;
83 | if (ops.test(word))
84 | return null;
85 | else if (keywords.test(word))
86 | return "keyword";
87 | else
88 | return "variable";
89 | }
90 | }
91 |
92 | function tokenLiteral(quote) {
93 | return function(stream, state) {
94 | var escaped = false, ch;
95 | while ((ch = stream.next()) != null) {
96 | if (ch == quote && !escaped) {
97 | state.tokenize = tokenBase;
98 | break;
99 | }
100 | escaped = !escaped && ch == "\\";
101 | }
102 | return "string";
103 | };
104 | }
105 |
106 | function tokenOpLiteral(quote) {
107 | return function(stream, state) {
108 | var escaped = false, ch;
109 | while ((ch = stream.next()) != null) {
110 | if (ch == quote && !escaped) {
111 | state.tokenize = tokenBase;
112 | break;
113 | }
114 | escaped = !escaped && ch == "\\";
115 | }
116 | return "variable-2";
117 | };
118 | }
119 |
120 |
121 | function pushContext(state, type, col) {
122 | state.context = {prev: state.context, indent: state.indent, col: col, type: type};
123 | }
124 | function popContext(state) {
125 | state.indent = state.context.indent;
126 | state.context = state.context.prev;
127 | }
128 |
129 | return {
130 | startState: function(base) {
131 | return {tokenize: tokenBase,
132 | context: null,
133 | indent: 0,
134 | col: 0};
135 | },
136 |
137 | token: function(stream, state) {
138 | if (stream.sol()) {
139 | if (state.context && state.context.align == null) state.context.align = false;
140 | state.indent = stream.indentation();
141 | }
142 | if (stream.eatSpace()) return null;
143 | var style = state.tokenize(stream, state);
144 |
145 | if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
146 | state.context.align = true;
147 | }
148 |
149 | if (curPunc == "(") pushContext(state, ")", stream.column());
150 | else if (curPunc == "[") pushContext(state, "]", stream.column());
151 | else if (curPunc == "{") pushContext(state, "}", stream.column());
152 | else if (/[\]\}\)]/.test(curPunc)) {
153 | while (state.context && state.context.type == "pattern") popContext(state);
154 | if (state.context && curPunc == state.context.type) popContext(state);
155 | }
156 | else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
157 | else if (/atom|string|variable/.test(style) && state.context) {
158 | if (/[\}\]]/.test(state.context.type))
159 | pushContext(state, "pattern", stream.column());
160 | else if (state.context.type == "pattern" && !state.context.align) {
161 | state.context.align = true;
162 | state.context.col = stream.column();
163 | }
164 | }
165 |
166 | return style;
167 | },
168 |
169 | indent: function(state, textAfter) {
170 | var firstChar = textAfter && textAfter.charAt(0);
171 | var context = state.context;
172 | if (/[\]\}]/.test(firstChar))
173 | while (context && context.type == "pattern") context = context.prev;
174 |
175 | var closing = context && firstChar == context.type;
176 | if (!context)
177 | return 0;
178 | else if (context.type == "pattern")
179 | return context.col;
180 | else if (context.align)
181 | return context.col + (closing ? 0 : 1);
182 | else
183 | return context.indent + (closing ? 0 : indentUnit);
184 | }
185 | };
186 | });
187 |
188 | CodeMirror.defineMIME("text/x-mysql", "mysql");
189 |
--------------------------------------------------------------------------------
/lib/client/12.ntriples.js:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * This script provides syntax highlighting support for
3 | * the Ntriples format.
4 | * Ntriples format specification:
5 | * http://www.w3.org/TR/rdf-testcases/#ntriples
6 | ***********************************************************/
7 |
8 | /*
9 | The following expression defines the defined ASF grammar transitions.
10 |
11 | pre_subject ->
12 | {
13 | ( writing_subject_uri | writing_bnode_uri )
14 | -> pre_predicate
15 | -> writing_predicate_uri
16 | -> pre_object
17 | -> writing_object_uri | writing_object_bnode |
18 | (
19 | writing_object_literal
20 | -> writing_literal_lang | writing_literal_type
21 | )
22 | -> post_object
23 | -> BEGIN
24 | } otherwise {
25 | -> ERROR
26 | }
27 | */
28 | CodeMirror.defineMode("ntriples", function() {
29 |
30 | Location = {
31 | PRE_SUBJECT : 0,
32 | WRITING_SUB_URI : 1,
33 | WRITING_BNODE_URI : 2,
34 | PRE_PRED : 3,
35 | WRITING_PRED_URI : 4,
36 | PRE_OBJ : 5,
37 | WRITING_OBJ_URI : 6,
38 | WRITING_OBJ_BNODE : 7,
39 | WRITING_OBJ_LITERAL : 8,
40 | WRITING_LIT_LANG : 9,
41 | WRITING_LIT_TYPE : 10,
42 | POST_OBJ : 11,
43 | ERROR : 12
44 | };
45 | function transitState(currState, c) {
46 | var currLocation = currState.location;
47 | var ret;
48 |
49 | // Opening.
50 | if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI;
51 | else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI;
52 | else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI;
53 | else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI;
54 | else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE;
55 | else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL;
56 |
57 | // Closing.
58 | else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED;
59 | else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED;
60 | else if(currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ;
61 | else if(currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ;
62 | else if(currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ;
63 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ;
64 | else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ;
65 | else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ;
66 |
67 | // Closing typed and language literal.
68 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG;
69 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE;
70 |
71 | // Spaces.
72 | else if( c == ' ' &&
73 | (
74 | currLocation == Location.PRE_SUBJECT ||
75 | currLocation == Location.PRE_PRED ||
76 | currLocation == Location.PRE_OBJ ||
77 | currLocation == Location.POST_OBJ
78 | )
79 | ) ret = currLocation;
80 |
81 | // Reset.
82 | else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;
83 |
84 | // Error
85 | else ret = Location.ERROR;
86 |
87 | currState.location=ret;
88 | }
89 |
90 | untilSpace = function(c) { return c != ' '; };
91 | untilEndURI = function(c) { return c != '>'; };
92 | return {
93 | startState: function() {
94 | return {
95 | location : Location.PRE_SUBJECT,
96 | uris : [],
97 | anchors : [],
98 | bnodes : [],
99 | langs : [],
100 | types : []
101 | };
102 | },
103 | token: function(stream, state) {
104 | var ch = stream.next();
105 | if(ch == '<') {
106 | transitState(state, ch);
107 | var parsedURI = '';
108 | stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} );
109 | state.uris.push(parsedURI);
110 | if( stream.match('#', false) ) return 'variable';
111 | stream.next();
112 | transitState(state, '>');
113 | return 'variable';
114 | }
115 | if(ch == '#') {
116 | var parsedAnchor = '';
117 | stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false});
118 | state.anchors.push(parsedAnchor);
119 | return 'variable-2';
120 | }
121 | if(ch == '>') {
122 | transitState(state, '>');
123 | return 'variable';
124 | }
125 | if(ch == '_') {
126 | transitState(state, ch);
127 | var parsedBNode = '';
128 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;});
129 | state.bnodes.push(parsedBNode);
130 | stream.next();
131 | transitState(state, ' ');
132 | return 'builtin';
133 | }
134 | if(ch == '"') {
135 | transitState(state, ch);
136 | stream.eatWhile( function(c) { return c != '"'; } );
137 | stream.next();
138 | if( stream.peek() != '@' && stream.peek() != '^' ) {
139 | transitState(state, '"');
140 | }
141 | return 'string';
142 | }
143 | if( ch == '@' ) {
144 | transitState(state, '@');
145 | var parsedLang = '';
146 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;});
147 | state.langs.push(parsedLang);
148 | stream.next();
149 | transitState(state, ' ');
150 | return 'string-2';
151 | }
152 | if( ch == '^' ) {
153 | stream.next();
154 | transitState(state, '^');
155 | var parsedType = '';
156 | stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} );
157 | state.types.push(parsedType);
158 | stream.next();
159 | transitState(state, '>');
160 | return 'variable';
161 | }
162 | if( ch == ' ' ) {
163 | transitState(state, ch);
164 | }
165 | if( ch == '.' ) {
166 | transitState(state, ch);
167 | }
168 | }
169 | };
170 | });
171 |
172 | CodeMirror.defineMIME("text/n-triples", "ntriples");
173 |
--------------------------------------------------------------------------------
/lib/client/12.pascal.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("pascal", function(config) {
2 | function words(str) {
3 | var obj = {}, words = str.split(" ");
4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5 | return obj;
6 | }
7 | var keywords = words("and array begin case const div do downto else end file for forward integer " +
8 | "boolean char function goto if in label mod nil not of or packed procedure " +
9 | "program record repeat set string then to type until var while with");
10 | var blockKeywords = words("case do else for if switch while struct then of");
11 | var atoms = {"null": true};
12 |
13 | var isOperatorChar = /[+\-*&%=<>!?|\/]/;
14 | var curPunc;
15 |
16 | function tokenBase(stream, state) {
17 | var ch = stream.next();
18 | if (ch == "#" && state.startOfLine) {
19 | stream.skipToEnd();
20 | return "meta";
21 | }
22 | if (ch == '"' || ch == "'") {
23 | state.tokenize = tokenString(ch);
24 | return state.tokenize(stream, state);
25 | }
26 | if (ch == "(" && stream.eat("*")) {
27 | state.tokenize = tokenComment;
28 | return tokenComment(stream, state);
29 | }
30 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
31 | curPunc = ch;
32 | return null
33 | }
34 | if (/\d/.test(ch)) {
35 | stream.eatWhile(/[\w\.]/);
36 | return "number";
37 | }
38 | if (ch == "/") {
39 | if (stream.eat("/")) {
40 | stream.skipToEnd();
41 | return "comment";
42 | }
43 | }
44 | if (isOperatorChar.test(ch)) {
45 | stream.eatWhile(isOperatorChar);
46 | return "operator";
47 | }
48 | stream.eatWhile(/[\w\$_]/);
49 | var cur = stream.current();
50 | if (keywords.propertyIsEnumerable(cur)) {
51 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
52 | return "keyword";
53 | }
54 | if (atoms.propertyIsEnumerable(cur)) return "atom";
55 | return "word";
56 | }
57 |
58 | function tokenString(quote) {
59 | return function(stream, state) {
60 | var escaped = false, next, end = false;
61 | while ((next = stream.next()) != null) {
62 | if (next == quote && !escaped) {end = true; break;}
63 | escaped = !escaped && next == "\\";
64 | }
65 | if (end || !escaped) state.tokenize = null;
66 | return "string";
67 | };
68 | }
69 |
70 | function tokenComment(stream, state) {
71 | var maybeEnd = false, ch;
72 | while (ch = stream.next()) {
73 | if (ch == ")" && maybeEnd) {
74 | state.tokenize = null;
75 | break;
76 | }
77 | maybeEnd = (ch == "*");
78 | }
79 | return "comment";
80 | }
81 |
82 | function Context(indented, column, type, align, prev) {
83 | this.indented = indented;
84 | this.column = column;
85 | this.type = type;
86 | this.align = align;
87 | this.prev = prev;
88 | }
89 | function pushContext(state, col, type) {
90 | return state.context = new Context(state.indented, col, type, null, state.context);
91 | }
92 | function popContext(state) {
93 | var t = state.context.type;
94 | if (t == ")" || t == "]" )
95 | state.indented = state.context.indented;
96 | return state.context = state.context.prev;
97 | }
98 |
99 | // Interface
100 |
101 | return {
102 | startState: function(basecolumn) {
103 | return {
104 | tokenize: null,
105 | context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
106 | indented: 0,
107 | startOfLine: true
108 | };
109 | },
110 |
111 | token: function(stream, state) {
112 | var ctx = state.context;
113 | if (stream.sol()) {
114 | if (ctx.align == null) ctx.align = false;
115 | state.indented = stream.indentation();
116 | state.startOfLine = true;
117 | }
118 | if (stream.eatSpace()) return null;
119 | curPunc = null;
120 | var style = (state.tokenize || tokenBase)(stream, state);
121 | if (style == "comment" || style == "meta") return style;
122 | if (ctx.align == null) ctx.align = true;
123 |
124 | if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
125 | else if (curPunc == "[") pushContext(state, stream.column(), "]");
126 | else if (curPunc == "(") pushContext(state, stream.column(), ")");
127 | else if (curPunc == ctx.type) popContext(state);
128 | else if ( ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
129 | pushContext(state, stream.column(), "statement");
130 | state.startOfLine = false;
131 | return style;
132 | },
133 |
134 | electricChars: "{}"
135 | };
136 | });
137 |
138 | CodeMirror.defineMIME("text/x-pascal", "pascal");
139 |
--------------------------------------------------------------------------------
/lib/client/12.php.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | function keywords(str) {
3 | var obj = {}, words = str.split(" ");
4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5 | return obj;
6 | }
7 | function heredoc(delim) {
8 | return function(stream, state) {
9 | if (stream.match(delim)) state.tokenize = null;
10 | else stream.skipToEnd();
11 | return "string";
12 | }
13 | }
14 | var phpConfig = {
15 | name: "clike",
16 | keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
17 | "default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " +
18 | "final for foreach function global goto if implements interface instanceof namespace " +
19 | "new or private protected public static switch throw try use var while xor return" +
20 | "die echo empty exit eval include include_once isset list require require_once print unset"),
21 | blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
22 | atoms: keywords("true false null TRUE FALSE NULL"),
23 | multiLineStrings: true,
24 | hooks: {
25 | "$": function(stream, state) {
26 | stream.eatWhile(/[\w\$_]/);
27 | return "variable-2";
28 | },
29 | "<": function(stream, state) {
30 | if (stream.match(/<)) {
31 | stream.eatWhile(/[\w\.]/);
32 | state.tokenize = heredoc(stream.current().slice(3));
33 | return state.tokenize(stream, state);
34 | }
35 | return false;
36 | },
37 | "#": function(stream, state) {
38 | stream.skipToEnd();
39 | return "comment";
40 | }
41 | }
42 | };
43 |
44 | CodeMirror.defineMode("php", function(config, parserConfig) {
45 | var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
46 | var jsMode = CodeMirror.getMode(config, "javascript");
47 | var cssMode = CodeMirror.getMode(config, "css");
48 | var phpMode = CodeMirror.getMode(config, phpConfig);
49 |
50 | function dispatch(stream, state) { // TODO open PHP inside text/css
51 | if (state.curMode == htmlMode) {
52 | var style = htmlMode.token(stream, state.curState);
53 | if (style == "meta" && /^<\?/.test(stream.current())) {
54 | state.curMode = phpMode;
55 | state.curState = state.php;
56 | state.curClose = /^\?>/;
57 | state.mode = 'php';
58 | }
59 | else if (style == "tag" && stream.current() == ">" && state.curState.context) {
60 | if (/^script$/i.test(state.curState.context.tagName)) {
61 | state.curMode = jsMode;
62 | state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
63 | state.curClose = /^<\/\s*script\s*>/i;
64 | state.mode = 'javascript';
65 | }
66 | else if (/^style$/i.test(state.curState.context.tagName)) {
67 | state.curMode = cssMode;
68 | state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
69 | state.curClose = /^<\/\s*style\s*>/i;
70 | state.mode = 'css';
71 | }
72 | }
73 | return style;
74 | }
75 | else if (stream.match(state.curClose, false)) {
76 | state.curMode = htmlMode;
77 | state.curState = state.html;
78 | state.curClose = null;
79 | state.mode = 'html';
80 | return dispatch(stream, state);
81 | }
82 | else return state.curMode.token(stream, state.curState);
83 | }
84 |
85 | return {
86 | startState: function() {
87 | var html = htmlMode.startState();
88 | return {html: html,
89 | php: phpMode.startState(),
90 | curMode: parserConfig.startOpen ? phpMode : htmlMode,
91 | curState: parserConfig.startOpen ? phpMode.startState() : html,
92 | curClose: parserConfig.startOpen ? /^\?>/ : null,
93 | mode: parserConfig.startOpen ? 'php' : 'html'}
94 | },
95 |
96 | copyState: function(state) {
97 | var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
98 | php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
99 | if (state.curState == html) cur = htmlNew;
100 | else if (state.curState == php) cur = phpNew;
101 | else cur = CodeMirror.copyState(state.curMode, state.curState);
102 | return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
103 | curClose: state.curClose, mode: state.mode};
104 | },
105 |
106 | token: dispatch,
107 |
108 | indent: function(state, textAfter) {
109 | if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
110 | (state.curMode == phpMode && /^\?>/.test(textAfter)))
111 | return htmlMode.indent(state.html, textAfter);
112 | return state.curMode.indent(state.curState, textAfter);
113 | },
114 |
115 | electricChars: "/{}:"
116 | }
117 | });
118 | CodeMirror.defineMIME("application/x-httpd-php", "php");
119 | CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
120 | CodeMirror.defineMIME("text/x-php", phpConfig);
121 | })();
122 |
--------------------------------------------------------------------------------
/lib/client/12.r.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("r", function(config) {
2 | function wordObj(str) {
3 | var words = str.split(" "), res = {};
4 | for (var i = 0; i < words.length; ++i) res[words[i]] = true;
5 | return res;
6 | }
7 | var atoms = wordObj("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_");
8 | var builtins = wordObj("list quote bquote eval return call parse deparse");
9 | var keywords = wordObj("if else repeat while function for in next break");
10 | var blockkeywords = wordObj("if else repeat while function for");
11 | var opChars = /[+\-*\/^<>=!&|~$:]/;
12 | var curPunc;
13 |
14 | function tokenBase(stream, state) {
15 | curPunc = null;
16 | var ch = stream.next();
17 | if (ch == "#") {
18 | stream.skipToEnd();
19 | return "comment";
20 | } else if (ch == "0" && stream.eat("x")) {
21 | stream.eatWhile(/[\da-f]/i);
22 | return "number";
23 | } else if (ch == "." && stream.eat(/\d/)) {
24 | stream.match(/\d*(?:e[+\-]?\d+)?/);
25 | return "number";
26 | } else if (/\d/.test(ch)) {
27 | stream.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/);
28 | return "number";
29 | } else if (ch == "'" || ch == '"') {
30 | state.tokenize = tokenString(ch);
31 | return "string";
32 | } else if (ch == "." && stream.match(/.[.\d]+/)) {
33 | return "keyword";
34 | } else if (/[\w\.]/.test(ch) && ch != "_") {
35 | stream.eatWhile(/[\w\.]/);
36 | var word = stream.current();
37 | if (atoms.propertyIsEnumerable(word)) return "atom";
38 | if (keywords.propertyIsEnumerable(word)) {
39 | if (blockkeywords.propertyIsEnumerable(word)) curPunc = "block";
40 | return "keyword";
41 | }
42 | if (builtins.propertyIsEnumerable(word)) return "builtin";
43 | return "variable";
44 | } else if (ch == "%") {
45 | if (stream.skipTo("%")) stream.next();
46 | return "variable-2";
47 | } else if (ch == "<" && stream.eat("-")) {
48 | return "arrow";
49 | } else if (ch == "=" && state.ctx.argList) {
50 | return "arg-is";
51 | } else if (opChars.test(ch)) {
52 | if (ch == "$") return "dollar";
53 | stream.eatWhile(opChars);
54 | return "operator";
55 | } else if (/[\(\){}\[\];]/.test(ch)) {
56 | curPunc = ch;
57 | if (ch == ";") return "semi";
58 | return null;
59 | } else {
60 | return null;
61 | }
62 | }
63 |
64 | function tokenString(quote) {
65 | return function(stream, state) {
66 | if (stream.eat("\\")) {
67 | var ch = stream.next();
68 | if (ch == "x") stream.match(/^[a-f0-9]{2}/i);
69 | else if ((ch == "u" || ch == "U") && stream.eat("{") && stream.skipTo("}")) stream.next();
70 | else if (ch == "u") stream.match(/^[a-f0-9]{4}/i);
71 | else if (ch == "U") stream.match(/^[a-f0-9]{8}/i);
72 | else if (/[0-7]/.test(ch)) stream.match(/^[0-7]{1,2}/);
73 | return "string-2";
74 | } else {
75 | var next;
76 | while ((next = stream.next()) != null) {
77 | if (next == quote) { state.tokenize = tokenBase; break; }
78 | if (next == "\\") { stream.backUp(1); break; }
79 | }
80 | return "string";
81 | }
82 | };
83 | }
84 |
85 | function push(state, type, stream) {
86 | state.ctx = {type: type,
87 | indent: state.indent,
88 | align: null,
89 | column: stream.column(),
90 | prev: state.ctx};
91 | }
92 | function pop(state) {
93 | state.indent = state.ctx.indent;
94 | state.ctx = state.ctx.prev;
95 | }
96 |
97 | return {
98 | startState: function(base) {
99 | return {tokenize: tokenBase,
100 | ctx: {type: "top",
101 | indent: -config.indentUnit,
102 | align: false},
103 | indent: 0,
104 | afterIdent: false};
105 | },
106 |
107 | token: function(stream, state) {
108 | if (stream.sol()) {
109 | if (state.ctx.align == null) state.ctx.align = false;
110 | state.indent = stream.indentation();
111 | }
112 | if (stream.eatSpace()) return null;
113 | var style = state.tokenize(stream, state);
114 | if (style != "comment" && state.ctx.align == null) state.ctx.align = true;
115 |
116 | var ctype = state.ctx.type;
117 | if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && ctype == "block") pop(state);
118 | if (curPunc == "{") push(state, "}", stream);
119 | else if (curPunc == "(") {
120 | push(state, ")", stream);
121 | if (state.afterIdent) state.ctx.argList = true;
122 | }
123 | else if (curPunc == "[") push(state, "]", stream);
124 | else if (curPunc == "block") push(state, "block", stream);
125 | else if (curPunc == ctype) pop(state);
126 | state.afterIdent = style == "variable" || style == "keyword";
127 | return style;
128 | },
129 |
130 | indent: function(state, textAfter) {
131 | if (state.tokenize != tokenBase) return 0;
132 | var firstChar = textAfter && textAfter.charAt(0), ctx = state.ctx,
133 | closing = firstChar == ctx.type;
134 | if (ctx.type == "block") return ctx.indent + (firstChar == "{" ? 0 : config.indentUnit);
135 | else if (ctx.align) return ctx.column + (closing ? 0 : 1);
136 | else return ctx.indent + (closing ? 0 : config.indentUnit);
137 | }
138 | };
139 | });
140 |
141 | CodeMirror.defineMIME("text/x-rsrc", "r");
142 |
--------------------------------------------------------------------------------
/lib/client/12.ruby.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("ruby", function(config, parserConfig) {
2 | function wordObj(words) {
3 | var o = {};
4 | for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true;
5 | return o;
6 | }
7 | var keywords = wordObj([
8 | "alias", "and", "BEGIN", "begin", "break", "case", "class", "def", "defined?", "do", "else",
9 | "elsif", "END", "end", "ensure", "false", "for", "if", "in", "module", "next", "not", "or",
10 | "redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless",
11 | "until", "when", "while", "yield", "nil", "raise", "throw", "catch", "fail", "loop", "callcc",
12 | "caller", "lambda", "proc", "public", "protected", "private", "require", "load",
13 | "require_relative", "extend", "autoload"
14 | ]);
15 | var indentWords = wordObj(["def", "class", "case", "for", "while", "do", "module", "then",
16 | "catch", "loop", "proc", "begin"]);
17 | var dedentWords = wordObj(["end", "until"]);
18 | var matching = {"[": "]", "{": "}", "(": ")"};
19 | var curPunc;
20 |
21 | function chain(newtok, stream, state) {
22 | state.tokenize.push(newtok);
23 | return newtok(stream, state);
24 | }
25 |
26 | function tokenBase(stream, state) {
27 | curPunc = null;
28 | if (stream.sol() && stream.match("=begin") && stream.eol()) {
29 | state.tokenize.push(readBlockComment);
30 | return "comment";
31 | }
32 | if (stream.eatSpace()) return null;
33 | var ch = stream.next();
34 | if (ch == "`" || ch == "'" || ch == '"' ||
35 | (ch == "/" && !stream.eol() && stream.peek() != " ")) {
36 | return chain(readQuoted(ch, "string", ch == '"'), stream, state);
37 | } else if (ch == "%") {
38 | var style, embed = false;
39 | if (stream.eat("s")) style = "atom";
40 | else if (stream.eat(/[WQ]/)) { style = "string"; embed = true; }
41 | else if (stream.eat(/[wxqr]/)) style = "string";
42 | var delim = stream.eat(/[^\w\s]/);
43 | if (!delim) return "operator";
44 | if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
45 | return chain(readQuoted(delim, style, embed, true), stream, state);
46 | } else if (ch == "#") {
47 | stream.skipToEnd();
48 | return "comment";
49 | } else if (ch == "<" && stream.eat("<")) {
50 | stream.eat("-");
51 | stream.eat(/[\'\"\`]/);
52 | var match = stream.match(/^\w+/);
53 | stream.eat(/[\'\"\`]/);
54 | if (match) return chain(readHereDoc(match[0]), stream, state);
55 | return null;
56 | } else if (ch == "0") {
57 | if (stream.eat("x")) stream.eatWhile(/[\da-fA-F]/);
58 | else if (stream.eat("b")) stream.eatWhile(/[01]/);
59 | else stream.eatWhile(/[0-7]/);
60 | return "number";
61 | } else if (/\d/.test(ch)) {
62 | stream.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/);
63 | return "number";
64 | } else if (ch == "?") {
65 | while (stream.match(/^\\[CM]-/)) {}
66 | if (stream.eat("\\")) stream.eatWhile(/\w/);
67 | else stream.next();
68 | return "string";
69 | } else if (ch == ":") {
70 | if (stream.eat("'")) return chain(readQuoted("'", "atom", false), stream, state);
71 | if (stream.eat('"')) return chain(readQuoted('"', "atom", true), stream, state);
72 | stream.eatWhile(/[\w\?]/);
73 | return "atom";
74 | } else if (ch == "@") {
75 | stream.eat("@");
76 | stream.eatWhile(/[\w\?]/);
77 | return "variable-2";
78 | } else if (ch == "$") {
79 | stream.next();
80 | stream.eatWhile(/[\w\?]/);
81 | return "variable-3";
82 | } else if (/\w/.test(ch)) {
83 | stream.eatWhile(/[\w\?]/);
84 | if (stream.eat(":")) return "atom";
85 | return "ident";
86 | } else if (ch == "|" && (state.varList || state.lastTok == "{" || state.lastTok == "do")) {
87 | curPunc = "|";
88 | return null;
89 | } else if (/[\(\)\[\]{}\\;]/.test(ch)) {
90 | curPunc = ch;
91 | return null;
92 | } else if (ch == "-" && stream.eat(">")) {
93 | return "arrow";
94 | } else if (/[=+\-\/*:\.^%<>~|]/.test(ch)) {
95 | stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
96 | return "operator";
97 | } else {
98 | return null;
99 | }
100 | }
101 |
102 | function tokenBaseUntilBrace() {
103 | var depth = 1;
104 | return function(stream, state) {
105 | if (stream.peek() == "}") {
106 | depth--;
107 | if (depth == 0) {
108 | state.tokenize.pop();
109 | return state.tokenize[state.tokenize.length-1](stream, state);
110 | }
111 | } else if (stream.peek() == "{") {
112 | depth++;
113 | }
114 | return tokenBase(stream, state);
115 | };
116 | }
117 | function readQuoted(quote, style, embed, unescaped) {
118 | return function(stream, state) {
119 | var escaped = false, ch;
120 | while ((ch = stream.next()) != null) {
121 | if (ch == quote && (unescaped || !escaped)) {
122 | state.tokenize.pop();
123 | break;
124 | }
125 | if (embed && ch == "#" && !escaped && stream.eat("{")) {
126 | state.tokenize.push(tokenBaseUntilBrace(arguments.callee));
127 | break;
128 | }
129 | escaped = !escaped && ch == "\\";
130 | }
131 | return style;
132 | };
133 | }
134 | function readHereDoc(phrase) {
135 | return function(stream, state) {
136 | if (stream.match(phrase)) state.tokenize.pop();
137 | else stream.skipToEnd();
138 | return "string";
139 | };
140 | }
141 | function readBlockComment(stream, state) {
142 | if (stream.sol() && stream.match("=end") && stream.eol())
143 | state.tokenize.pop();
144 | stream.skipToEnd();
145 | return "comment";
146 | }
147 |
148 | return {
149 | startState: function() {
150 | return {tokenize: [tokenBase],
151 | indented: 0,
152 | context: {type: "top", indented: -config.indentUnit},
153 | continuedLine: false,
154 | lastTok: null,
155 | varList: false};
156 | },
157 |
158 | token: function(stream, state) {
159 | if (stream.sol()) state.indented = stream.indentation();
160 | var style = state.tokenize[state.tokenize.length-1](stream, state), kwtype;
161 | if (style == "ident") {
162 | var word = stream.current();
163 | style = keywords.propertyIsEnumerable(stream.current()) ? "keyword"
164 | : /^[A-Z]/.test(word) ? "tag"
165 | : (state.lastTok == "def" || state.lastTok == "class" || state.varList) ? "def"
166 | : "variable";
167 | if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
168 | else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
169 | else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
170 | kwtype = "indent";
171 | }
172 | if (curPunc || (style && style != "comment")) state.lastTok = word || curPunc || style;
173 | if (curPunc == "|") state.varList = !state.varList;
174 |
175 | if (kwtype == "indent" || /[\(\[\{]/.test(curPunc))
176 | state.context = {prev: state.context, type: curPunc || style, indented: state.indented};
177 | else if ((kwtype == "dedent" || /[\)\]\}]/.test(curPunc)) && state.context.prev)
178 | state.context = state.context.prev;
179 |
180 | if (stream.eol())
181 | state.continuedLine = (curPunc == "\\" || style == "operator");
182 | return style;
183 | },
184 |
185 | indent: function(state, textAfter) {
186 | if (state.tokenize[state.tokenize.length-1] != tokenBase) return 0;
187 | var firstChar = textAfter && textAfter.charAt(0);
188 | var ct = state.context;
189 | var closing = ct.type == matching[firstChar] ||
190 | ct.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(textAfter);
191 | return ct.indented + (closing ? 0 : config.indentUnit) +
192 | (state.continuedLine ? config.indentUnit : 0);
193 | },
194 | electricChars: "}de" // enD and rescuE
195 |
196 | };
197 | });
198 |
199 | CodeMirror.defineMIME("text/x-ruby", "ruby");
200 |
201 |
--------------------------------------------------------------------------------
/lib/client/12.smalltalk.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
2 |
3 | var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
4 | var keywords = /true|false|nil|self|super|thisContext/;
5 |
6 | var Context = function(tokenizer, parent) {
7 | this.next = tokenizer;
8 | this.parent = parent;
9 | };
10 |
11 | var Token = function(name, context, eos) {
12 | this.name = name;
13 | this.context = context;
14 | this.eos = eos;
15 | };
16 |
17 | var State = function() {
18 | this.context = new Context(next, null);
19 | this.expectVariable = true;
20 | this.indentation = 0;
21 | this.userIndentationDelta = 0;
22 | };
23 |
24 | State.prototype.userIndent = function(indentation) {
25 | this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
26 | };
27 |
28 | var next = function(stream, context, state) {
29 | var token = new Token(null, context, false);
30 | var char = stream.next();
31 |
32 | if (char === '"') {
33 | token = nextComment(stream, new Context(nextComment, context));
34 |
35 | } else if (char === '\'') {
36 | token = nextString(stream, new Context(nextString, context));
37 |
38 | } else if (char === '#') {
39 | stream.eatWhile(/[^ .]/);
40 | token.name = 'string-2';
41 |
42 | } else if (char === '$') {
43 | stream.eatWhile(/[^ ]/);
44 | token.name = 'string-2';
45 |
46 | } else if (char === '|' && state.expectVariable) {
47 | token.context = new Context(nextTemporaries, context);
48 |
49 | } else if (/[\[\]{}()]/.test(char)) {
50 | token.name = 'bracket';
51 | token.eos = /[\[{(]/.test(char);
52 |
53 | if (char === '[') {
54 | state.indentation++;
55 | } else if (char === ']') {
56 | state.indentation = Math.max(0, state.indentation - 1);
57 | }
58 |
59 | } else if (specialChars.test(char)) {
60 | stream.eatWhile(specialChars);
61 | token.name = 'operator';
62 | token.eos = char !== ';'; // ; cascaded message expression
63 |
64 | } else if (/\d/.test(char)) {
65 | stream.eatWhile(/[\w\d]/);
66 | token.name = 'number'
67 |
68 | } else if (/[\w_]/.test(char)) {
69 | stream.eatWhile(/[\w\d_]/);
70 | token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
71 |
72 | } else {
73 | token.eos = state.expectVariable;
74 | }
75 |
76 | return token;
77 | };
78 |
79 | var nextComment = function(stream, context) {
80 | stream.eatWhile(/[^"]/);
81 | return new Token('comment', stream.eat('"') ? context.parent : context, true);
82 | };
83 |
84 | var nextString = function(stream, context) {
85 | stream.eatWhile(/[^']/);
86 | return new Token('string', stream.eat('\'') ? context.parent : context, false);
87 | };
88 |
89 | var nextTemporaries = function(stream, context, state) {
90 | var token = new Token(null, context, false);
91 | var char = stream.next();
92 |
93 | if (char === '|') {
94 | token.context = context.parent;
95 | token.eos = true;
96 |
97 | } else {
98 | stream.eatWhile(/[^|]/);
99 | token.name = 'variable';
100 | }
101 |
102 | return token;
103 | }
104 |
105 | return {
106 | startState: function() {
107 | return new State;
108 | },
109 |
110 | token: function(stream, state) {
111 | state.userIndent(stream.indentation());
112 |
113 | if (stream.eatSpace()) {
114 | return null;
115 | }
116 |
117 | var token = state.context.next(stream, state.context, state);
118 | state.context = token.context;
119 | state.expectVariable = token.eos;
120 |
121 | state.lastToken = token;
122 | return token.name;
123 | },
124 |
125 | blankLine: function(state) {
126 | state.userIndent(0);
127 | },
128 |
129 | indent: function(state, textAfter) {
130 | var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
131 | return (state.indentation + i) * config.indentUnit;
132 | },
133 |
134 | electricChars: ']'
135 | };
136 |
137 | });
138 |
139 | CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
--------------------------------------------------------------------------------
/lib/client/12.sparql.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("sparql", function(config) {
2 | var indentUnit = config.indentUnit;
3 | var curPunc;
4 |
5 | function wordRegexp(words) {
6 | return new RegExp("^(?:" + words.join("|") + ")$", "i");
7 | }
8 | var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
9 | "isblank", "isliteral", "union", "a"]);
10 | var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
11 | "ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
12 | "graph", "by", "asc", "desc"]);
13 | var operatorChars = /[*+\-<>=&|]/;
14 |
15 | function tokenBase(stream, state) {
16 | var ch = stream.next();
17 | curPunc = null;
18 | if (ch == "$" || ch == "?") {
19 | stream.match(/^[\w\d]*/);
20 | return "variable-2";
21 | }
22 | else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
23 | stream.match(/^[^\s\u00a0>]*>?/);
24 | return "atom";
25 | }
26 | else if (ch == "\"" || ch == "'") {
27 | state.tokenize = tokenLiteral(ch);
28 | return state.tokenize(stream, state);
29 | }
30 | else if (/[{}\(\),\.;\[\]]/.test(ch)) {
31 | curPunc = ch;
32 | return null;
33 | }
34 | else if (ch == "#") {
35 | stream.skipToEnd();
36 | return "comment";
37 | }
38 | else if (operatorChars.test(ch)) {
39 | stream.eatWhile(operatorChars);
40 | return null;
41 | }
42 | else if (ch == ":") {
43 | stream.eatWhile(/[\w\d\._\-]/);
44 | return "atom";
45 | }
46 | else {
47 | stream.eatWhile(/[_\w\d]/);
48 | if (stream.eat(":")) {
49 | stream.eatWhile(/[\w\d_\-]/);
50 | return "atom";
51 | }
52 | var word = stream.current(), type;
53 | if (ops.test(word))
54 | return null;
55 | else if (keywords.test(word))
56 | return "keyword";
57 | else
58 | return "variable";
59 | }
60 | }
61 |
62 | function tokenLiteral(quote) {
63 | return function(stream, state) {
64 | var escaped = false, ch;
65 | while ((ch = stream.next()) != null) {
66 | if (ch == quote && !escaped) {
67 | state.tokenize = tokenBase;
68 | break;
69 | }
70 | escaped = !escaped && ch == "\\";
71 | }
72 | return "string";
73 | };
74 | }
75 |
76 | function pushContext(state, type, col) {
77 | state.context = {prev: state.context, indent: state.indent, col: col, type: type};
78 | }
79 | function popContext(state) {
80 | state.indent = state.context.indent;
81 | state.context = state.context.prev;
82 | }
83 |
84 | return {
85 | startState: function(base) {
86 | return {tokenize: tokenBase,
87 | context: null,
88 | indent: 0,
89 | col: 0};
90 | },
91 |
92 | token: function(stream, state) {
93 | if (stream.sol()) {
94 | if (state.context && state.context.align == null) state.context.align = false;
95 | state.indent = stream.indentation();
96 | }
97 | if (stream.eatSpace()) return null;
98 | var style = state.tokenize(stream, state);
99 |
100 | if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
101 | state.context.align = true;
102 | }
103 |
104 | if (curPunc == "(") pushContext(state, ")", stream.column());
105 | else if (curPunc == "[") pushContext(state, "]", stream.column());
106 | else if (curPunc == "{") pushContext(state, "}", stream.column());
107 | else if (/[\]\}\)]/.test(curPunc)) {
108 | while (state.context && state.context.type == "pattern") popContext(state);
109 | if (state.context && curPunc == state.context.type) popContext(state);
110 | }
111 | else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
112 | else if (/atom|string|variable/.test(style) && state.context) {
113 | if (/[\}\]]/.test(state.context.type))
114 | pushContext(state, "pattern", stream.column());
115 | else if (state.context.type == "pattern" && !state.context.align) {
116 | state.context.align = true;
117 | state.context.col = stream.column();
118 | }
119 | }
120 |
121 | return style;
122 | },
123 |
124 | indent: function(state, textAfter) {
125 | var firstChar = textAfter && textAfter.charAt(0);
126 | var context = state.context;
127 | if (/[\]\}]/.test(firstChar))
128 | while (context && context.type == "pattern") context = context.prev;
129 |
130 | var closing = context && firstChar == context.type;
131 | if (!context)
132 | return 0;
133 | else if (context.type == "pattern")
134 | return context.col;
135 | else if (context.align)
136 | return context.col + (closing ? 0 : 1);
137 | else
138 | return context.indent + (closing ? 0 : indentUnit);
139 | }
140 | };
141 | });
142 |
143 | CodeMirror.defineMIME("application/x-sparql-query", "sparql");
144 |
--------------------------------------------------------------------------------
/lib/client/12.stex.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
3 | * Licence: MIT
4 | */
5 |
6 | CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
7 | {
8 | function pushCommand(state, command) {
9 | state.cmdState.push(command);
10 | }
11 |
12 | function peekCommand(state) {
13 | if (state.cmdState.length>0)
14 | return state.cmdState[state.cmdState.length-1];
15 | else
16 | return null;
17 | }
18 |
19 | function popCommand(state) {
20 | if (state.cmdState.length>0) {
21 | var plug = state.cmdState.pop();
22 | plug.closeBracket();
23 | }
24 | }
25 |
26 | function applyMostPowerful(state) {
27 | var context = state.cmdState;
28 | for (var i = context.length - 1; i >= 0; i--) {
29 | var plug = context[i];
30 | if (plug.name=="DEFAULT")
31 | continue;
32 | return plug.styleIdentifier();
33 | }
34 | return null;
35 | }
36 |
37 | function addPluginPattern(pluginName, cmdStyle, brackets, styles) {
38 | return function () {
39 | this.name=pluginName;
40 | this.bracketNo = 0;
41 | this.style=cmdStyle;
42 | this.styles = styles;
43 | this.brackets = brackets;
44 |
45 | this.styleIdentifier = function(content) {
46 | if (this.bracketNo<=this.styles.length)
47 | return this.styles[this.bracketNo-1];
48 | else
49 | return null;
50 | };
51 | this.openBracket = function(content) {
52 | this.bracketNo++;
53 | return "bracket";
54 | };
55 | this.closeBracket = function(content) {
56 | };
57 | }
58 | }
59 |
60 | var plugins = new Array();
61 |
62 | plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
63 | plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
64 | plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
65 | plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
66 | plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
67 |
68 | plugins["DEFAULT"] = function () {
69 | this.name="DEFAULT";
70 | this.style="tag";
71 |
72 | this.styleIdentifier = function(content) {
73 | };
74 | this.openBracket = function(content) {
75 | };
76 | this.closeBracket = function(content) {
77 | };
78 | };
79 |
80 | function setState(state, f) {
81 | state.f = f;
82 | }
83 |
84 | function normal(source, state) {
85 | if (source.match(/^\\[a-z]+/)) {
86 | var cmdName = source.current();
87 | cmdName = cmdName.substr(1, cmdName.length-1);
88 | var plug = plugins[cmdName];
89 | if (typeof(plug) == 'undefined') {
90 | plug = plugins["DEFAULT"];
91 | }
92 | plug = new plug();
93 | pushCommand(state, plug);
94 | setState(state, beginParams);
95 | return plug.style;
96 | }
97 |
98 | var ch = source.next();
99 | if (ch == "%") {
100 | setState(state, inCComment);
101 | return "comment";
102 | }
103 | else if (ch=='}' || ch==']') {
104 | plug = peekCommand(state);
105 | if (plug) {
106 | plug.closeBracket(ch);
107 | setState(state, beginParams);
108 | } else
109 | return "error";
110 | return "bracket";
111 | } else if (ch=='{' || ch=='[') {
112 | plug = plugins["DEFAULT"];
113 | plug = new plug();
114 | pushCommand(state, plug);
115 | return "bracket";
116 | }
117 | else if (/\d/.test(ch)) {
118 | source.eatWhile(/[\w.%]/);
119 | return "atom";
120 | }
121 | else {
122 | source.eatWhile(/[\w-_]/);
123 | return applyMostPowerful(state);
124 | }
125 | }
126 |
127 | function inCComment(source, state) {
128 | source.skipToEnd();
129 | setState(state, normal);
130 | return "comment";
131 | }
132 |
133 | function beginParams(source, state) {
134 | var ch = source.peek();
135 | if (ch == '{' || ch == '[') {
136 | var lastPlug = peekCommand(state);
137 | var style = lastPlug.openBracket(ch);
138 | source.eat(ch);
139 | setState(state, normal);
140 | return "bracket";
141 | }
142 | if (/[ \t\r]/.test(ch)) {
143 | source.eat(ch);
144 | return null;
145 | }
146 | setState(state, normal);
147 | lastPlug = peekCommand(state);
148 | if (lastPlug) {
149 | popCommand(state);
150 | }
151 | return normal(source, state);
152 | }
153 |
154 | return {
155 | startState: function() { return { f:normal, cmdState:[] }; },
156 | copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; },
157 |
158 | token: function(stream, state) {
159 | var t = state.f(stream, state);
160 | var w = stream.current();
161 | return t;
162 | }
163 | };
164 | });
165 |
166 |
167 | CodeMirror.defineMIME("text/x-stex", "stex");
168 |
--------------------------------------------------------------------------------
/lib/client/12.velocity.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("velocity", function(config) {
2 | function parseWords(str) {
3 | var obj = {}, words = str.split(" ");
4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5 | return obj;
6 | }
7 |
8 | var indentUnit = config.indentUnit
9 | var keywords = parseWords("#end #else #break #stop #[[ #]] " +
10 | "#{end} #{else} #{break} #{stop}");
11 | var functions = parseWords("#if #elseif #foreach #set #include #parse #macro #define #evaluate " +
12 | "#{if} #{elseif} #{foreach} #{set} #{include} #{parse} #{macro} #{define} #{evaluate}");
13 | var specials = parseWords("$foreach.count $foreach.hasNext $foreach.first $foreach.last $foreach.topmost $foreach.parent $velocityCount");
14 | var isOperatorChar = /[+\-*&%=<>!?:\/|]/;
15 | var multiLineStrings =true;
16 |
17 | function chain(stream, state, f) {
18 | state.tokenize = f;
19 | return f(stream, state);
20 | }
21 | function tokenBase(stream, state) {
22 | var beforeParams = state.beforeParams;
23 | state.beforeParams = false;
24 | var ch = stream.next();
25 | // start of string?
26 | if ((ch == '"' || ch == "'") && state.inParams)
27 | return chain(stream, state, tokenString(ch));
28 | // is it one of the special signs []{}().,;? Seperator?
29 | else if (/[\[\]{}\(\),;\.]/.test(ch)) {
30 | if (ch == "(" && beforeParams) state.inParams = true;
31 | else if (ch == ")") state.inParams = false;
32 | return null;
33 | }
34 | // start of a number value?
35 | else if (/\d/.test(ch)) {
36 | stream.eatWhile(/[\w\.]/);
37 | return "number";
38 | }
39 | // multi line comment?
40 | else if (ch == "#" && stream.eat("*")) {
41 | return chain(stream, state, tokenComment);
42 | }
43 | // unparsed content?
44 | else if (ch == "#" && stream.match(/ *\[ *\[/)) {
45 | return chain(stream, state, tokenUnparsed);
46 | }
47 | // single line comment?
48 | else if (ch == "#" && stream.eat("#")) {
49 | stream.skipToEnd();
50 | return "comment";
51 | }
52 | // variable?
53 | else if (ch == "$") {
54 | stream.eatWhile(/[\w\d\$_\.{}]/);
55 | // is it one of the specials?
56 | if (specials && specials.propertyIsEnumerable(stream.current().toLowerCase())) {
57 | return "keyword";
58 | }
59 | else {
60 | state.beforeParams = true;
61 | return "builtin";
62 | }
63 | }
64 | // is it a operator?
65 | else if (isOperatorChar.test(ch)) {
66 | stream.eatWhile(isOperatorChar);
67 | return "operator";
68 | }
69 | else {
70 | // get the whole word
71 | stream.eatWhile(/[\w\$_{}]/);
72 | var word = stream.current().toLowerCase();
73 | // is it one of the listed keywords?
74 | if (keywords && keywords.propertyIsEnumerable(word))
75 | return "keyword";
76 | // is it one of the listed functions?
77 | if (functions && functions.propertyIsEnumerable(word) ||
78 | stream.current().match(/^#[a-z0-9_]+ *$/i) && stream.peek()=="(") {
79 | state.beforeParams = true;
80 | return "keyword";
81 | }
82 | // default: just a "word"
83 | return null;
84 | }
85 | }
86 |
87 | function tokenString(quote) {
88 | return function(stream, state) {
89 | var escaped = false, next, end = false;
90 | while ((next = stream.next()) != null) {
91 | if (next == quote && !escaped) {
92 | end = true;
93 | break;
94 | }
95 | escaped = !escaped && next == "\\";
96 | }
97 | if (end) state.tokenize = tokenBase;
98 | return "string";
99 | };
100 | }
101 |
102 | function tokenComment(stream, state) {
103 | var maybeEnd = false, ch;
104 | while (ch = stream.next()) {
105 | if (ch == "#" && maybeEnd) {
106 | state.tokenize = tokenBase;
107 | break;
108 | }
109 | maybeEnd = (ch == "*");
110 | }
111 | return "comment";
112 | }
113 |
114 | function tokenUnparsed(stream, state) {
115 | var maybeEnd = 0, ch;
116 | while (ch = stream.next()) {
117 | if (ch == "#" && maybeEnd == 2) {
118 | state.tokenize = tokenBase;
119 | break;
120 | }
121 | if (ch == "]")
122 | maybeEnd++;
123 | else if (ch != " ")
124 | maybeEnd = 0;
125 | }
126 | return "meta";
127 | }
128 | // Interface
129 |
130 | return {
131 | startState: function(basecolumn) {
132 | return {
133 | tokenize: tokenBase,
134 | beforeParams: false,
135 | inParams: false
136 | };
137 | },
138 |
139 | token: function(stream, state) {
140 | if (stream.eatSpace()) return null;
141 | return state.tokenize(stream, state);
142 | }
143 | };
144 | });
145 |
146 | CodeMirror.defineMIME("text/velocity", "velocity");
147 |
--------------------------------------------------------------------------------
/lib/client/12.verilog.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("verilog", function(config, parserConfig) {
2 | var indentUnit = config.indentUnit,
3 | keywords = parserConfig.keywords || {},
4 | blockKeywords = parserConfig.blockKeywords || {},
5 | atoms = parserConfig.atoms || {},
6 | hooks = parserConfig.hooks || {},
7 | multiLineStrings = parserConfig.multiLineStrings;
8 | var isOperatorChar = /[&|~>"));
25 | else return null;
26 | }
27 | else if (stream.match("--")) return chain(inBlock("comment", "-->"));
28 | else if (stream.match("DOCTYPE", true, true)) {
29 | stream.eatWhile(/[\w\._\-]/);
30 | return chain(doctype(1));
31 | }
32 | else return null;
33 | }
34 | else if (stream.eat("?")) {
35 | stream.eatWhile(/[\w\._\-]/);
36 | state.tokenize = inBlock("meta", "?>");
37 | return "meta";
38 | }
39 | else {
40 | type = stream.eat("/") ? "closeTag" : "openTag";
41 | stream.eatSpace();
42 | tagName = "";
43 | var c;
44 | while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
45 | state.tokenize = inTag;
46 | return "tag";
47 | }
48 | }
49 | else if (ch == "&") {
50 | var ok;
51 | if (stream.eat("#")) {
52 | if (stream.eat("x")) {
53 | ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
54 | } else {
55 | ok = stream.eatWhile(/[\d]/) && stream.eat(";");
56 | }
57 | } else {
58 | ok = stream.eatWhile(/[\w]/) && stream.eat(";");
59 | }
60 | return ok ? "atom" : "error";
61 | }
62 | else {
63 | stream.eatWhile(/[^&<]/);
64 | return null;
65 | }
66 | }
67 |
68 | function inTag(stream, state) {
69 | var ch = stream.next();
70 | if (ch == ">" || (ch == "/" && stream.eat(">"))) {
71 | state.tokenize = inText;
72 | type = ch == ">" ? "endTag" : "selfcloseTag";
73 | return "tag";
74 | }
75 | else if (ch == "=") {
76 | type = "equals";
77 | return null;
78 | }
79 | else if (/[\'\"]/.test(ch)) {
80 | state.tokenize = inAttribute(ch);
81 | return state.tokenize(stream, state);
82 | }
83 | else {
84 | stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
85 | return "word";
86 | }
87 | }
88 |
89 | function inAttribute(quote) {
90 | return function(stream, state) {
91 | while (!stream.eol()) {
92 | if (stream.next() == quote) {
93 | state.tokenize = inTag;
94 | break;
95 | }
96 | }
97 | return "string";
98 | };
99 | }
100 |
101 | function inBlock(style, terminator) {
102 | return function(stream, state) {
103 | while (!stream.eol()) {
104 | if (stream.match(terminator)) {
105 | state.tokenize = inText;
106 | break;
107 | }
108 | stream.next();
109 | }
110 | return style;
111 | };
112 | }
113 | function doctype(depth) {
114 | return function(stream, state) {
115 | var ch;
116 | while ((ch = stream.next()) != null) {
117 | if (ch == "<") {
118 | state.tokenize = doctype(depth + 1);
119 | return state.tokenize(stream, state);
120 | } else if (ch == ">") {
121 | if (depth == 1) {
122 | state.tokenize = inText;
123 | break;
124 | } else {
125 | state.tokenize = doctype(depth - 1);
126 | return state.tokenize(stream, state);
127 | }
128 | }
129 | }
130 | return "meta";
131 | };
132 | }
133 |
134 | var curState, setStyle;
135 | function pass() {
136 | for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
137 | }
138 | function cont() {
139 | pass.apply(null, arguments);
140 | return true;
141 | }
142 |
143 | function pushContext(tagName, startOfLine) {
144 | var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
145 | curState.context = {
146 | prev: curState.context,
147 | tagName: tagName,
148 | indent: curState.indented,
149 | startOfLine: startOfLine,
150 | noIndent: noIndent
151 | };
152 | }
153 | function popContext() {
154 | if (curState.context) curState.context = curState.context.prev;
155 | }
156 |
157 | function element(type) {
158 | if (type == "openTag") {
159 | curState.tagName = tagName;
160 | return cont(attributes, endtag(curState.startOfLine));
161 | } else if (type == "closeTag") {
162 | var err = false;
163 | if (curState.context) {
164 | err = curState.context.tagName != tagName;
165 | } else {
166 | err = true;
167 | }
168 | if (err) setStyle = "error";
169 | return cont(endclosetag(err));
170 | }
171 | return cont();
172 | }
173 | function endtag(startOfLine) {
174 | return function(type) {
175 | if (type == "selfcloseTag" ||
176 | (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
177 | return cont();
178 | if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
179 | return cont();
180 | };
181 | }
182 | function endclosetag(err) {
183 | return function(type) {
184 | if (err) setStyle = "error";
185 | if (type == "endTag") { popContext(); return cont(); }
186 | setStyle = "error";
187 | return cont(arguments.callee);
188 | }
189 | }
190 |
191 | function attributes(type) {
192 | if (type == "word") {setStyle = "attribute"; return cont(attributes);}
193 | if (type == "equals") return cont(attvalue, attributes);
194 | if (type == "string") {setStyle = "error"; return cont(attributes);}
195 | return pass();
196 | }
197 | function attvalue(type) {
198 | if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
199 | if (type == "string") return cont(attvaluemaybe);
200 | return pass();
201 | }
202 | function attvaluemaybe(type) {
203 | if (type == "string") return cont(attvaluemaybe);
204 | else return pass();
205 | }
206 |
207 | return {
208 | startState: function() {
209 | return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
210 | },
211 |
212 | token: function(stream, state) {
213 | if (stream.sol()) {
214 | state.startOfLine = true;
215 | state.indented = stream.indentation();
216 | }
217 | if (stream.eatSpace()) return null;
218 |
219 | setStyle = type = tagName = null;
220 | var style = state.tokenize(stream, state);
221 | state.type = type;
222 | if ((style || type) && style != "comment") {
223 | curState = state;
224 | while (true) {
225 | var comb = state.cc.pop() || element;
226 | if (comb(type || style)) break;
227 | }
228 | }
229 | state.startOfLine = false;
230 | return setStyle || style;
231 | },
232 |
233 | indent: function(state, textAfter, fullLine) {
234 | var context = state.context;
235 | if ((state.tokenize != inTag && state.tokenize != inText) ||
236 | context && context.noIndent)
237 | return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
238 | if (alignCDATA && / state.keyCol) {
14 | stream.skipToEnd(); return "string";
15 | } else if (state.literal) { state.literal = false; }
16 | if (stream.sol()) {
17 | state.keyCol = 0;
18 | state.pair = false;
19 | state.pairStart = false;
20 | /* document start */
21 | if(stream.match(/---/)) { return "def"; }
22 | /* document end */
23 | if (stream.match(/\.\.\./)) { return "def"; }
24 | /* array list item */
25 | if (stream.match(/\s*-\s+/)) { return 'meta'; }
26 | }
27 | /* pairs (associative arrays) -> key */
28 | if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
29 | state.pair = true;
30 | state.keyCol = stream.indentation();
31 | return "atom";
32 | }
33 | if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
34 |
35 | /* inline pairs/lists */
36 | if (stream.match(/^(\{|\}|\[|\])/)) {
37 | if (ch == '{')
38 | state.inlinePairs++;
39 | else if (ch == '}')
40 | state.inlinePairs--;
41 | else if (ch == '[')
42 | state.inlineList++;
43 | else
44 | state.inlineList--;
45 | return 'meta';
46 | }
47 |
48 | /* list seperator */
49 | if (state.inlineList > 0 && !esc && ch == ',') {
50 | stream.next();
51 | return 'meta';
52 | }
53 | /* pairs seperator */
54 | if (state.inlinePairs > 0 && !esc && ch == ',') {
55 | state.keyCol = 0;
56 | state.pair = false;
57 | state.pairStart = false;
58 | stream.next();
59 | return 'meta';
60 | }
61 |
62 | /* start of value of a pair */
63 | if (state.pairStart) {
64 | /* block literals */
65 | if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
66 | /* references */
67 | if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
68 | /* numbers */
69 | if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
70 | if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
71 | /* keywords */
72 | if (stream.match(keywordRegex)) { return 'keyword'; }
73 | }
74 |
75 | /* nothing found, continue */
76 | state.pairStart = false;
77 | state.escaped = (ch == '\\');
78 | stream.next();
79 | return null;
80 | },
81 | startState: function() {
82 | return {
83 | pair: false,
84 | pairStart: false,
85 | keyCol: 0,
86 | inlinePairs: 0,
87 | inlineList: 0,
88 | literal: false,
89 | escaped: false
90 | };
91 | }
92 | };
93 | });
94 |
95 | CodeMirror.defineMIME("text/x-yaml", "yaml");
96 |
--------------------------------------------------------------------------------
/lib/client/13.overlay.js:
--------------------------------------------------------------------------------
1 | // Utility function that allows modes to be combined. The mode given
2 | // as the base argument takes care of most of the normal mode
3 | // functionality, but a second (typically simple) mode is used, which
4 | // can override the style of text. Both modes get to parse all of the
5 | // text, but when both assign a non-null style to a piece of code, the
6 | // overlay wins, unless the combine argument was true, in which case
7 | // the styles are combined.
8 |
9 | CodeMirror.overlayParser = function(base, overlay, combine) {
10 | return {
11 | startState: function() {
12 | return {
13 | base: CodeMirror.startState(base),
14 | overlay: CodeMirror.startState(overlay),
15 | basePos: 0, baseCur: null,
16 | overlayPos: 0, overlayCur: null
17 | };
18 | },
19 | copyState: function(state) {
20 | return {
21 | base: CodeMirror.copyState(base, state.base),
22 | overlay: CodeMirror.copyState(overlay, state.overlay),
23 | basePos: state.basePos, baseCur: null,
24 | overlayPos: state.overlayPos, overlayCur: null
25 | };
26 | },
27 |
28 | token: function(stream, state) {
29 | if (stream.start == state.basePos) {
30 | state.baseCur = base.token(stream, state.base);
31 | state.basePos = stream.pos;
32 | }
33 | if (stream.start == state.overlayPos) {
34 | stream.pos = stream.start;
35 | state.overlayCur = overlay.token(stream, state.overlay);
36 | state.overlayPos = stream.pos;
37 | }
38 | stream.pos = Math.min(state.basePos, state.overlayPos);
39 | if (stream.eol()) state.basePos = state.overlayPos = 0;
40 |
41 | if (state.overlayCur == null) return state.baseCur;
42 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
43 | else return state.overlayCur;
44 | },
45 |
46 | //indent: function(state, textAfter) {
47 | // return base.indent(state.base, textAfter);
48 | //},
49 | electricChars: base.electricChars
50 | };
51 | };
52 |
--------------------------------------------------------------------------------
/lib/client/15.downloadify.min.js:
--------------------------------------------------------------------------------
1 | /* Downloadify 0.2 (c) 2009 by Douglas Neiner. Licensed under the MIT license */
2 | /* See http://github.com/dcneiner/Downloadify for license and more info */
3 | (function(){Downloadify=window.Downloadify={queue:{},uid:new Date().getTime(),getTextForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getData();return""},getFileNameForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getFilename();return""},getDataTypeForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getDataType();return""},saveComplete:function(a){var b=Downloadify.queue[a];if(b)b.complete();return true},saveCancel:function(a){var b=Downloadify.queue[a];if(b)b.cancel();return true},saveError:function(a){var b=Downloadify.queue[a];if(b)b.error();return true},addToQueue:function(a){Downloadify.queue[a.queue_name]=a},getUID:function(a){if(a.id=="")a.id='downloadify_'+Downloadify.uid++;return a.id}};Downloadify.create=function(a,b){var c=(typeof(a)=="string"?document.getElementById(a):a);return new Downloadify.Container(c,b)};Downloadify.Container=function(d,e){var f=this;f.el=d;f.enabled=true;f.dataCallback=null;f.filenameCallback=null;f.data=null;f.filename=null;var g=function(){f.options=e;if(!f.options.append)f.el.innerHTML="";f.flashContainer=document.createElement('span');f.el.appendChild(f.flashContainer);f.queue_name=Downloadify.getUID(f.flashContainer);if(typeof(f.options.filename)==="function")f.filenameCallback=f.options.filename;else if(f.options.filename)f.filename=f.options.filename;if(typeof(f.options.data)==="function")f.dataCallback=f.options.data;else if(f.options.data)f.data=f.options.data;var a={queue_name:f.queue_name,width:f.options.width,height:f.options.height};var b={allowScriptAccess:'always'};var c={id:f.flashContainer.id,name:f.flashContainer.id};if(f.options.enabled===false)f.enabled=false;if(f.options.transparent===true)b.wmode="transparent";if(f.options.downloadImage)a.downloadImage=f.options.downloadImage;swfobject.embedSWF(f.options.swf,f.flashContainer.id,f.options.width,f.options.height,"10",null,a,b,c);Downloadify.addToQueue(f)};f.enable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(true);f.enabled=true};f.disable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(false);f.enabled=false};f.getData=function(){if(!f.enabled)return"";if(f.dataCallback)return f.dataCallback();else if(f.data)return f.data;else return""};f.getFilename=function(){if(f.filenameCallback)return f.filenameCallback();else if(f.filename)return f.filename;else return""};f.getDataType=function(){if(f.options.dataType)return f.options.dataType;return"string"};f.complete=function(){if(typeof(f.options.onComplete)==="function")f.options.onComplete()};f.cancel=function(){if(typeof(f.options.onCancel)==="function")f.options.onCancel()};f.error=function(){if(typeof(f.options.onError)==="function")f.options.onError()};g()};Downloadify.defaultOptions={swf:'media/downloadify.swf',downloadImage:'images/download.png',width:100,height:30,transparent:true,append:false,dataType:"string"}})();if(typeof(jQuery)!="undefined"){(function($){$.fn.downloadify=function(b){return this.each(function(){b=$.extend({},Downloadify.defaultOptions,b);var a=Downloadify.create(this,b);$(this).data('Downloadify',a)})}})(jQuery)};if(typeof(MooTools)!='undefined'){Element.implement({downloadify:function(a){a=$merge(Downloadify.defaultOptions,a);return this.store('Downloadify',Downloadify.create(this,a))}})};
--------------------------------------------------------------------------------
/lib/css/cobalt.css:
--------------------------------------------------------------------------------
1 | .cm-s-cobalt { background: #002240; color: white; }
2 | .cm-s-cobalt div.CodeMirror-selected { background: #b36539 !important; }
3 | .cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; }
4 | .cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; }
5 | .cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; }
6 |
7 | .cm-s-cobalt span.cm-comment { color: #08f; }
8 | .cm-s-cobalt span.cm-atom { color: #845dc4; }
9 | .cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; }
10 | .cm-s-cobalt span.cm-keyword { color: #ffee80; }
11 | .cm-s-cobalt span.cm-string { color: #3ad900; }
12 | .cm-s-cobalt span.cm-meta { color: #ff9d00; }
13 | .cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
14 | .cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
15 | .cm-s-cobalt span.cm-error { color: #9d1e15; }
16 | .cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
17 | .cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
18 | .cm-s-cobalt span.cm-link { color: #845dc4; }
19 |
--------------------------------------------------------------------------------
/lib/css/codemirror.css:
--------------------------------------------------------------------------------
1 | .CodeMirror {
2 | line-height: 1em;
3 | font-family: monospace;
4 | }
5 |
6 | .CodeMirror-scroll {
7 | overflow: auto;
8 | height: auto;
9 | /* This is needed to prevent an IE[67] bug where the scrolled content
10 | is visible outside of the scrolling box. */
11 | position: relative;
12 | }
13 |
14 | .CodeMirror-gutter {
15 | position: absolute; left: 0; top: 0;
16 | z-index: 10;
17 | background-color: #f7f7f7;
18 | border-right: 1px solid #eee;
19 | min-width: 2em;
20 | height: 100%;
21 | }
22 | .CodeMirror-gutter-text {
23 | color: #aaa;
24 | text-align: right;
25 | padding: .4em .2em .4em .4em;
26 | white-space: pre !important;
27 | }
28 | .CodeMirror-lines {
29 | padding: .4em;
30 | }
31 |
32 | .CodeMirror pre {
33 | -moz-border-radius: 0;
34 | -webkit-border-radius: 0;
35 | -o-border-radius: 0;
36 | border-radius: 0;
37 | border-width: 0; margin: 0; padding: 0; background: transparent;
38 | font-family: inherit;
39 | font-size: inherit;
40 | padding: 0; margin: 0;
41 | white-space: pre;
42 | word-wrap: normal;
43 | }
44 |
45 | .CodeMirror-wrap pre {
46 | word-wrap: break-word;
47 | white-space: pre-wrap;
48 | }
49 | .CodeMirror-wrap .CodeMirror-scroll {
50 | overflow-x: hidden;
51 | }
52 |
53 | .CodeMirror textarea {
54 | outline: none !important;
55 | }
56 |
57 | .CodeMirror pre.CodeMirror-cursor {
58 | z-index: 10;
59 | position: absolute;
60 | visibility: hidden;
61 | border-left: 1px solid black;
62 | }
63 | .CodeMirror-focused pre.CodeMirror-cursor {
64 | visibility: visible;
65 | }
66 |
67 | div.CodeMirror-selected { background: #d9d9d9; }
68 | .CodeMirror-focused div.CodeMirror-selected { background: #d7d4f0; }
69 |
70 | .CodeMirror-searching {background: #ffa;}
71 |
72 | /* Default theme */
73 |
74 | .cm-s-default span.cm-keyword {color: #d04;}
75 | .cm-s-default span.cm-atom {color: #21d;}
76 | .cm-s-default span.cm-number {color: #1d2;}
77 | .cm-s-default span.cm-def {color: #00f;}
78 | .cm-s-default span.cm-variable {color: black;}
79 | .cm-s-default span.cm-variable-2 {color: #03d;}
80 | .cm-s-default span.cm-variable-3 {color: #0d2;}
81 | .cm-s-default span.cm-property {color: #400;}
82 | .cm-s-default span.cm-operator {color: #20d;}
83 | .cm-s-default span.cm-comment {color: #d20;}
84 | .cm-s-default span.cm-string {color: #d10;}
85 | .cm-s-default span.cm-string-2 {color: #f50;}
86 | .cm-s-default span.cm-meta {color: #555;}
87 | .cm-s-default span.cm-error {color: #f00;}
88 | .cm-s-default span.cm-qualifier {color: #555;}
89 | .cm-s-default span.cm-builtin {color: #20d;}
90 | .cm-s-default span.cm-bracket {color: #d40;}
91 | .cm-s-default span.cm-tag {color: #0d0;}
92 | .cm-s-default span.cm-attribute {color: #00d;}
93 | .cm-s-default span.cm-header {color: #50d;}
94 | .cm-s-default span.cm-quote {color: #0d0;}
95 | .cm-s-default span.cm-hr {color: #ddd;}
96 | .cm-s-default span.cm-link {color: #00d;}
97 |
98 | span.cm-header, span.cm-strong {font-weight: bold;}
99 | span.cm-em {font-style: italic;}
100 | span.cm-emstrong {font-style: italic; font-weight: bold;}
101 | span.cm-link {text-decoration: underline;}
102 |
103 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
104 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
105 |
--------------------------------------------------------------------------------
/lib/css/eclipse.css:
--------------------------------------------------------------------------------
1 | .cm-s-eclipse span.cm-meta {color: #FF1717;}
2 | .cm-s-eclipse span.cm-keyword { font-weight: bold; color: #7F0055; }
3 | .cm-s-eclipse span.cm-atom {color: #219;}
4 | .cm-s-eclipse span.cm-number {color: #164;}
5 | .cm-s-eclipse span.cm-def {color: #00f;}
6 | .cm-s-eclipse span.cm-variable {color: black;}
7 | .cm-s-eclipse span.cm-variable-2 {color: #0000C0;}
8 | .cm-s-eclipse span.cm-variable-3 {color: #0000C0;}
9 | .cm-s-eclipse span.cm-property {color: black;}
10 | .cm-s-eclipse span.cm-operator {color: black;}
11 | .cm-s-eclipse span.cm-comment {color: #3F7F5F;}
12 | .cm-s-eclipse span.cm-string {color: #2A00FF;}
13 | .cm-s-eclipse span.cm-string-2 {color: #f50;}
14 | .cm-s-eclipse span.cm-error {color: #f00;}
15 | .cm-s-eclipse span.cm-qualifier {color: #555;}
16 | .cm-s-eclipse span.cm-builtin {color: #30a;}
17 | .cm-s-eclipse span.cm-bracket {color: #cc7;}
18 | .cm-s-eclipse span.cm-tag {color: #170;}
19 | .cm-s-eclipse span.cm-attribute {color: #00c;}
20 | .cm-s-eclipse span.cm-link {color: #219;}
21 |
22 | .cm-s-eclipse .CodeMirror-matchingbracket {
23 | border:1px solid grey;
24 | color:black !important;;
25 | }
26 |
--------------------------------------------------------------------------------
/lib/css/elegant.css:
--------------------------------------------------------------------------------
1 | .cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
2 | .cm-s-elegant span.cm-comment {color: #262;font-style: italic;}
3 | .cm-s-elegant span.cm-meta {color: #555;font-style: italic;}
4 | .cm-s-elegant span.cm-variable {color: black;}
5 | .cm-s-elegant span.cm-variable-2 {color: #b11;}
6 | .cm-s-elegant span.cm-qualifier {color: #555;}
7 | .cm-s-elegant span.cm-keyword {color: #730;}
8 | .cm-s-elegant span.cm-builtin {color: #30a;}
9 | .cm-s-elegant span.cm-error {background-color: #fdd;}
10 | .cm-s-elegant span.cm-link {color: #762;}
11 |
--------------------------------------------------------------------------------
/lib/css/monokai.css:
--------------------------------------------------------------------------------
1 | /* Based on Sublime Text's Monokai theme */
2 |
3 | .cm-s-monokai {background: #272822; color: #f8f8f2;}
4 | .cm-s-monokai div.CodeMirror-selected {background: #ffe792 !important;}
5 | .cm-s-monokai .CodeMirror-gutter {background: #272822; border-right: 0px;}
6 | .cm-s-monokai .CodeMirror-gutter-text {color: #d0d0d0;}
7 | .cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;}
8 |
9 | .cm-s-monokai span.cm-comment {color: #75715e;}
10 | .cm-s-monokai span.cm-atom {color: #ae81ff;}
11 | .cm-s-monokai span.cm-number {color: #ae81ff;}
12 |
13 | .cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;}
14 | .cm-s-monokai span.cm-keyword {color: #f92672;}
15 | .cm-s-monokai span.cm-string {color: #e6db74;}
16 | .cm-s-monokai span.cm-bracket {color: #dd0;}
17 |
18 | .cm-s-monokai span.cm-variable {color: #a6e22e;}
19 | .cm-s-monokai span.cm-variable-2 {color: #9effff;}
20 | .cm-s-monokai span.cm-def {color: #fd971f;}
21 | .cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;}
22 | .cm-s-monokai span.cm-bracket {color: #f8f8f2;}
23 | .cm-s-monokai span.cm-tag {color: #f92672;}
24 | .cm-s-monokai span.cm-link {color: #ae81ff;}
25 |
26 | .cm-s-monokai .CodeMirror-matchingbracket {
27 | text-decoration: underline;
28 | color: white !important;
29 | }
30 |
--------------------------------------------------------------------------------
/lib/css/neat.css:
--------------------------------------------------------------------------------
1 | .cm-s-neat span.cm-comment { color: #a86; }
2 | .cm-s-neat span.cm-keyword { font-weight: bold; color: blue; }
3 | .cm-s-neat span.cm-string { color: #a22; }
4 | .cm-s-neat span.cm-builtin { font-weight: bold; color: #077; }
5 | .cm-s-neat span.cm-special { font-weight: bold; color: #0aa; }
6 | .cm-s-neat span.cm-variable { color: black; }
7 | .cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
8 | .cm-s-neat span.cm-meta {color: #555;}
9 | .cm-s-neat span.cm-link { color: #3a3; }
10 |
--------------------------------------------------------------------------------
/lib/css/night.css:
--------------------------------------------------------------------------------
1 | /* Loosely based on the Midnight Textmate theme */
2 |
3 | .cm-s-night { background: #0a001f; color: #f8f8f8; }
4 | .cm-s-night div.CodeMirror-selected { background: #a8f !important; }
5 | .cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
6 | .cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
7 | .cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
8 |
9 | .cm-s-night span.cm-comment { color: #6900a1; }
10 | .cm-s-night span.cm-atom { color: #845dc4; }
11 | .cm-s-night span.cm-number, .cm-s-night span.cm-attribute { color: #ffd500; }
12 | .cm-s-night span.cm-keyword { color: #599eff; }
13 | .cm-s-night span.cm-string { color: #37f14a; }
14 | .cm-s-night span.cm-meta { color: #7678e2; }
15 | .cm-s-night span.cm-variable-2, .cm-s-night span.cm-tag { color: #99b2ff; }
16 | .cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { color: white; }
17 | .cm-s-night span.cm-error { color: #9d1e15; }
18 | .cm-s-night span.cm-bracket { color: #8da6ce; }
19 | .cm-s-night span.cm-comment { color: #6900a1; }
20 | .cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
21 | .cm-s-night span.cm-link { color: #845dc4; }
22 |
--------------------------------------------------------------------------------
/lib/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/
2 | v2.0 | 20110126
3 | License: none (public domain)
4 | */
5 |
6 | html, body, div, span, applet, object, iframe,
7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
8 | a, abbr, acronym, address, big, cite, code,
9 | del, dfn, em, img, ins, kbd, q, s, samp,
10 | small, strike, strong, sub, sup, tt, var,
11 | b, u, i, center,
12 | dl, dt, dd, ol, ul, li,
13 | fieldset, form, label, legend,
14 | table, caption, tbody, tfoot, thead, tr, th, td,
15 | article, aside, canvas, details, embed,
16 | figure, figcaption, footer, header, hgroup,
17 | menu, nav, output, ruby, section, summary,
18 | time, mark, audio, video {
19 | margin: 0;
20 | padding: 0;
21 | border: 0;
22 | font-size: 100%;
23 | font: inherit;
24 | vertical-align: baseline;
25 | }
26 | /* HTML5 display-role reset for older browsers */
27 | article, aside, details, figcaption, figure,
28 | footer, header, hgroup, menu, nav, section {
29 | display: block;
30 | }
31 | body {
32 | line-height: 1;
33 | }
34 | ol, ul {
35 | list-style: none;
36 | }
37 | blockquote, q {
38 | quotes: none;
39 | }
40 | blockquote:before, blockquote:after,
41 | q:before, q:after {
42 | content: '';
43 | content: none;
44 | }
45 | table {
46 | border-collapse: collapse;
47 | border-spacing: 0;
48 | }
49 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "My new SocketStream app",
3 | "description": "An awesome real time application",
4 | "version": "0.1.0",
5 | "author": "Me ",
6 | "private": true,
7 | "engines": { "node": ">= 0.4.0 < 0.5.0" },
8 | "dependencies": {
9 | "socketstream": "~>0.2.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/werg/snucode/171b4055681088ec1a4ec6256c0f27db37381be1/public/favicon.ico
--------------------------------------------------------------------------------
/public/images/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/werg/snucode/171b4055681088ec1a4ec6256c0f27db37381be1/public/images/download.png
--------------------------------------------------------------------------------
/public/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/werg/snucode/171b4055681088ec1a4ec6256c0f27db37381be1/public/images/logo.png
--------------------------------------------------------------------------------
/public/media/downloadify.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/werg/snucode/171b4055681088ec1a4ec6256c0f27db37381be1/public/media/downloadify.swf
--------------------------------------------------------------------------------