├── .gitignore ├── CONTRIBUTING ├── LICENSE ├── README.md ├── index.html ├── jsonnet-screenshot.png ├── jsonnet.js ├── package.json └── third_party └── CodeMirror ├── LICENSE ├── README.md ├── addon └── edit │ └── matchbrackets.js └── lib ├── codemirror.css └── codemirror.js /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Before we can merge your pull request, we need you to sign either the Google individual or corporate 2 | contributor license agreement (CLA), unless you are a Google employee, intern, or contractor. 3 | 4 | Please see http://google.github.io/jsonnet/doc/contributing.html for more information. 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # codemirror-mode-jsonnet 2 | 3 | [Jsonnet](http://jsonnet.org) integration for codemirror. Try it out [here](https://google.github.io/codemirror-mode-jsonnet/). 4 | 5 | ## Features 6 | 7 | Token colorization for the full language, including correct handling of `|||` and the various string 8 | escaping. 9 | 10 | ## Usage instructions 11 | 12 | See index.html in this repo. Also available via `npm install codemirror-mode-jsonnet`. 13 | 14 | ## More Info 15 | 16 | For more info on Jsonnet: 17 | * Jsonnet Website: http://jsonnet.org 18 | * Jsonnet Repository: https://github.com/google/jsonnet 19 | 20 | ## Screenshot 21 | 22 | ![A screenshot of Jsonnet syntax highlighting](https://raw.githubusercontent.com/google/codemirror-mode-jsonnet/master/jsonnet-screenshot.png) 23 | 24 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CodeMirror: Jsonnet mode 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 19 |
20 |

Jsonnet mode

21 | 22 |
132 | 133 | 141 | 142 |

MIME types defined: text/jsonnet, text/x-jsonnet.

143 |
144 | -------------------------------------------------------------------------------- /jsonnet-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/codemirror-mode-jsonnet/89ce682312a6678c0153d785fc97eaf1914daf94/jsonnet-screenshot.png -------------------------------------------------------------------------------- /jsonnet.js: -------------------------------------------------------------------------------- 1 | /** @license 2 | * 3 | * Copyright 2017 Google Inc. All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | (function(mod) { 20 | if (typeof exports == "object" && typeof module == "object") // CommonJS 21 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); 22 | else if (typeof define == "function" && define.amd) // AMD 23 | define(["../../lib/codemirror", "../../addon/mode/simple"], mod); 24 | else // Plain browser env 25 | mod(CodeMirror); 26 | })(function(CodeMirror) { 27 | "use strict"; 28 | 29 | let keywords = { 30 | "local": "keyword", 31 | "self": "keyword", 32 | "super": "keyword", 33 | "assert": "keyword", 34 | "function": "keyword", 35 | "if": "keyword", 36 | "then": "keyword", 37 | "else": "keyword", 38 | "for": "keyword", 39 | "in": "keyword", 40 | "tailstrict": "keyword", 41 | "error": "keyword", 42 | "true": "atom", 43 | "false": "atom", 44 | "null": "atom", 45 | }; 46 | 47 | CodeMirror.defineMode("jsonnet", function() { 48 | return { 49 | token: function(stream, state) { 50 | // Handle special states: 51 | 52 | // In a C-style comment 53 | if (state.cComment) { 54 | if (stream.match(/\*\//)) { 55 | state.cComment = false; 56 | return "comment"; 57 | } 58 | stream.next(); 59 | return "comment"; 60 | } 61 | 62 | // In a text block (|||) 63 | if (state.textBlock) { 64 | if (stream.match(/$/)) { 65 | stream.next(); 66 | return "string"; 67 | } 68 | if (state.textBlockIndent == null) { 69 | if (stream.match(/\s*\|\|\|/)) { 70 | state.textBlock = false; 71 | return "string"; 72 | } 73 | state.textBlockIndent = stream.indentation(); 74 | } 75 | if (state.textBlockIndent != null 76 | && stream.indentation() >= state.textBlockIndent) { 77 | stream.skipToEnd(); 78 | return "string"; 79 | } 80 | if (stream.match(/\s*\|\|\|/)) { 81 | state.textBlock = false; 82 | return "string"; 83 | } 84 | stream.next(); 85 | return "error"; 86 | } 87 | 88 | // In a string (all 4 variants) 89 | if (state.string || state.importString) { 90 | let mode = state.string ? "string" : "meta"; 91 | if (state.stringRaw) { 92 | if (stream.match(state.stringSingle ? /''/ : /""/)) { 93 | return "string-2"; 94 | } 95 | } else { 96 | if (stream.match(/\\[\\"'\/bfnrt0]/)) { 97 | return "string-2"; 98 | } 99 | if (stream.match(/\\u[0-9a-fA-F]{4}/)) { 100 | return "string-2"; 101 | } 102 | if (stream.match(/\\/)) { 103 | return "error"; 104 | } 105 | } 106 | if (stream.match(state.stringSingle ? /'/ : /"/)) { 107 | state.string = false; 108 | state.importString = false; 109 | state.stringRaw = false; 110 | state.stringDouble = false; 111 | return mode; 112 | } 113 | stream.next(); 114 | return mode; 115 | } 116 | 117 | // Regular (whole token at a time) processing: 118 | 119 | // Comments. 120 | if (stream.match(/\/\//) || stream.match(/#/)) { 121 | stream.skipToEnd(); 122 | return "comment"; 123 | } 124 | if (stream.match(/\/\*/)) { 125 | state.cComment = true; 126 | return "comment"; 127 | } 128 | 129 | // Imports (including the strings after them). 130 | if (stream.match(/import(?:str)?\s*"/)) { 131 | state.importString = true; 132 | state.stringSingle = false; 133 | state.stringRaw = false; 134 | return "meta"; 135 | } 136 | 137 | if (stream.match(/import(?:str)?\s*'/)) { 138 | state.importString = true; 139 | state.stringSingle = true; 140 | state.stringRaw = false; 141 | return "meta"; 142 | } 143 | 144 | if (stream.match(/import(?:str)?\s*@"/)) { 145 | state.importString = true; 146 | state.stringSingle = false; 147 | state.stringRaw = true; 148 | return "meta"; 149 | } 150 | 151 | if (stream.match(/import(?:str)?\s*@'/)) { 152 | state.importString = true; 153 | state.stringSingle = true; 154 | state.stringRaw = true; 155 | return "meta"; 156 | } 157 | 158 | // Strings (without imports) 159 | if (stream.match(/"/)) { 160 | state.string = true; 161 | state.stringSingle = false; 162 | state.stringRaw = false; 163 | return "string"; 164 | } 165 | 166 | if (stream.match(/'/)) { 167 | state.string = true; 168 | state.stringSingle = true; 169 | state.stringRaw = false; 170 | return "string"; 171 | } 172 | 173 | if (stream.match(/@"/)) { 174 | state.string = true; 175 | state.stringSingle = false; 176 | state.stringRaw = true; 177 | return "string"; 178 | } 179 | 180 | if (stream.match(/@'/)) { 181 | state.string = true; 182 | state.stringSingle = true; 183 | state.stringRaw = true; 184 | return "string"; 185 | } 186 | 187 | // Enter text block. 188 | if (stream.match(/\|\|\|/)) { 189 | state.textBlock = true; 190 | state.textBlockIndent = null; 191 | return "string"; 192 | } 193 | 194 | if (stream.match(/\$/)) return "keyword"; 195 | if (stream.match(/(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i)) return "number"; 196 | if (stream.match(/[-+\/*=<>!&~^|$%]+/)) return "operator"; 197 | 198 | // Identifiers and keywords that look like identifiers. 199 | let identifier = stream.match(/[a-zA-Z_][a-zA-Z0-9_]*/); 200 | if (identifier) { 201 | identifier = identifier[0]; 202 | // If it's not in the dict, we return null to indicate no special 203 | // syntax highlighting. 204 | return keywords.hasOwnProperty(identifier) ? keywords[identifier] : undefined; 205 | } 206 | 207 | stream.next(); 208 | 209 | return null; 210 | }, 211 | startState: function() { 212 | return { 213 | cComment: false, 214 | textBlock: false, 215 | importString: false, 216 | string: false, 217 | stringSingle: false, 218 | stringRaw: false, 219 | }; 220 | }, 221 | }; 222 | }); 223 | }); 224 | 225 | CodeMirror.defineMIME("text/x-jsonnet", "jsonnet"); 226 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codemirror-mode-jsonnet", 3 | "version": "1.0.0", 4 | "description": "codemirror mode for Jsonnet", 5 | "main": "jsonnet.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/google/codemirror-mode-jsonnet.git" 12 | }, 13 | "keywords": [ 14 | "jsonnet", 15 | "codemirror", 16 | "lexer", 17 | "syntax", 18 | "highlight", 19 | "javascript" 20 | ], 21 | "author": "Dave Cunningham ", 22 | "license": "Apache-2.0", 23 | "bugs": { 24 | "url": "https://github.com/google/codemirror-mode-jsonnet/issues" 25 | }, 26 | "homepage": "https://github.com/google/codemirror-mode-jsonnet#readme" 27 | } 28 | -------------------------------------------------------------------------------- /third_party/CodeMirror/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2017 by Marijn Haverbeke and others 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /third_party/CodeMirror/README.md: -------------------------------------------------------------------------------- 1 | # CodeMirror 2 | [![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror) 3 | [![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror) 4 | [![Join the chat at https://gitter.im/codemirror/CodeMirror](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codemirror/CodeMirror) 5 | [Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?again)](https://marijnhaverbeke.nl/fund/) 6 | 7 | CodeMirror is a versatile text editor implemented in JavaScript for 8 | the browser. It is specialized for editing code, and comes with over 9 | 100 language modes and various addons that implement more advanced 10 | editing functionality. Every language comes with fully-featured code 11 | and syntax highlighting to help with reading and editing complex code. 12 | 13 | A rich programming API and a CSS theming system are available for 14 | customizing CodeMirror to fit your application, and extending it with 15 | new functionality. 16 | 17 | You can find more information (and the 18 | [manual](http://codemirror.net/doc/manual.html)) on the [project 19 | page](http://codemirror.net). For questions and discussion, use the 20 | [discussion forum](https://discuss.codemirror.net/). 21 | 22 | See 23 | [CONTRIBUTING.md](https://github.com/codemirror/CodeMirror/blob/master/CONTRIBUTING.md) 24 | for contributing guidelines. 25 | 26 | The CodeMirror community aims to be welcoming to everybody. We use the 27 | [Contributor Covenant 28 | (1.1)](http://contributor-covenant.org/version/1/1/0/) as our code of 29 | conduct. 30 | 31 | ### Quickstart 32 | 33 | To build the project, make sure you have Node.js installed (at least version 6) 34 | and then `npm install`. To run, just open `index.html` in your 35 | browser (you don't need to run a webserver). Run the tests with `npm test`. 36 | -------------------------------------------------------------------------------- /third_party/CodeMirror/addon/edit/matchbrackets.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | var ie_lt8 = /MSIE \d/.test(navigator.userAgent) && 13 | (document.documentMode == null || document.documentMode < 8); 14 | 15 | var Pos = CodeMirror.Pos; 16 | 17 | var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; 18 | 19 | function findMatchingBracket(cm, where, config) { 20 | var line = cm.getLineHandle(where.line), pos = where.ch - 1; 21 | var afterCursor = config && config.afterCursor 22 | if (afterCursor == null) 23 | afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className) 24 | 25 | // A cursor is defined as between two characters, but in in vim command mode 26 | // (i.e. not insert mode), the cursor is visually represented as a 27 | // highlighted box on top of the 2nd character. Otherwise, we allow matches 28 | // from before or after the cursor. 29 | var match = (!afterCursor && pos >= 0 && matching[line.text.charAt(pos)]) || 30 | matching[line.text.charAt(++pos)]; 31 | if (!match) return null; 32 | var dir = match.charAt(1) == ">" ? 1 : -1; 33 | if (config && config.strict && (dir > 0) != (pos == where.ch)) return null; 34 | var style = cm.getTokenTypeAt(Pos(where.line, pos + 1)); 35 | 36 | var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config); 37 | if (found == null) return null; 38 | return {from: Pos(where.line, pos), to: found && found.pos, 39 | match: found && found.ch == match.charAt(0), forward: dir > 0}; 40 | } 41 | 42 | // bracketRegex is used to specify which type of bracket to scan 43 | // should be a regexp, e.g. /[[\]]/ 44 | // 45 | // Note: If "where" is on an open bracket, then this bracket is ignored. 46 | // 47 | // Returns false when no bracket was found, null when it reached 48 | // maxScanLines and gave up 49 | function scanForBracket(cm, where, dir, style, config) { 50 | var maxScanLen = (config && config.maxScanLineLength) || 10000; 51 | var maxScanLines = (config && config.maxScanLines) || 1000; 52 | 53 | var stack = []; 54 | var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/; 55 | var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1) 56 | : Math.max(cm.firstLine() - 1, where.line - maxScanLines); 57 | for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) { 58 | var line = cm.getLine(lineNo); 59 | if (!line) continue; 60 | var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1; 61 | if (line.length > maxScanLen) continue; 62 | if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0); 63 | for (; pos != end; pos += dir) { 64 | var ch = line.charAt(pos); 65 | if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) { 66 | var match = matching[ch]; 67 | if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch); 68 | else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch}; 69 | else stack.pop(); 70 | } 71 | } 72 | } 73 | return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null; 74 | } 75 | 76 | function matchBrackets(cm, autoclear, config) { 77 | // Disable brace matching in long lines, since it'll cause hugely slow updates 78 | var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000; 79 | var marks = [], ranges = cm.listSelections(); 80 | for (var i = 0; i < ranges.length; i++) { 81 | var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config); 82 | if (match && cm.getLine(match.from.line).length <= maxHighlightLen) { 83 | var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; 84 | marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style})); 85 | if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen) 86 | marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style})); 87 | } 88 | } 89 | 90 | if (marks.length) { 91 | // Kludge to work around the IE bug from issue #1193, where text 92 | // input stops going to the textare whever this fires. 93 | if (ie_lt8 && cm.state.focused) cm.focus(); 94 | 95 | var clear = function() { 96 | cm.operation(function() { 97 | for (var i = 0; i < marks.length; i++) marks[i].clear(); 98 | }); 99 | }; 100 | if (autoclear) setTimeout(clear, 800); 101 | else return clear; 102 | } 103 | } 104 | 105 | var currentlyHighlighted = null; 106 | function doMatchBrackets(cm) { 107 | cm.operation(function() { 108 | if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;} 109 | currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets); 110 | }); 111 | } 112 | 113 | CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) { 114 | if (old && old != CodeMirror.Init) { 115 | cm.off("cursorActivity", doMatchBrackets); 116 | if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;} 117 | } 118 | if (val) { 119 | cm.state.matchBrackets = typeof val == "object" ? val : {}; 120 | cm.on("cursorActivity", doMatchBrackets); 121 | } 122 | }); 123 | 124 | CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);}); 125 | CodeMirror.defineExtension("findMatchingBracket", function(pos, config, oldConfig){ 126 | // Backwards-compatibility kludge 127 | if (oldConfig || typeof config == "boolean") { 128 | if (!oldConfig) { 129 | config = config ? {strict: true} : null 130 | } else { 131 | oldConfig.strict = config 132 | config = oldConfig 133 | } 134 | } 135 | return findMatchingBracket(this, pos, config) 136 | }); 137 | CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){ 138 | return scanForBracket(this, pos, dir, style, config); 139 | }); 140 | }); 141 | -------------------------------------------------------------------------------- /third_party/CodeMirror/lib/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | color: black; 8 | direction: ltr; 9 | } 10 | 11 | /* PADDING */ 12 | 13 | .CodeMirror-lines { 14 | padding: 4px 0; /* Vertical padding around content */ 15 | } 16 | .CodeMirror pre { 17 | padding: 0 4px; /* Horizontal padding of content */ 18 | } 19 | 20 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 21 | background-color: white; /* The little square between H and V scrollbars */ 22 | } 23 | 24 | /* GUTTER */ 25 | 26 | .CodeMirror-gutters { 27 | border-right: 1px solid #ddd; 28 | background-color: #f7f7f7; 29 | white-space: nowrap; 30 | } 31 | .CodeMirror-linenumbers {} 32 | .CodeMirror-linenumber { 33 | padding: 0 3px 0 5px; 34 | min-width: 20px; 35 | text-align: right; 36 | color: #999; 37 | white-space: nowrap; 38 | } 39 | 40 | .CodeMirror-guttermarker { color: black; } 41 | .CodeMirror-guttermarker-subtle { color: #999; } 42 | 43 | /* CURSOR */ 44 | 45 | .CodeMirror-cursor { 46 | border-left: 1px solid black; 47 | border-right: none; 48 | width: 0; 49 | } 50 | /* Shown when moving in bi-directional text */ 51 | .CodeMirror div.CodeMirror-secondarycursor { 52 | border-left: 1px solid silver; 53 | } 54 | .cm-fat-cursor .CodeMirror-cursor { 55 | width: auto; 56 | border: 0 !important; 57 | background: #7e7; 58 | } 59 | .cm-fat-cursor div.CodeMirror-cursors { 60 | z-index: 1; 61 | } 62 | .cm-fat-cursor-mark { 63 | background-color: rgba(20, 255, 20, 0.5); 64 | -webkit-animation: blink 1.06s steps(1) infinite; 65 | -moz-animation: blink 1.06s steps(1) infinite; 66 | animation: blink 1.06s steps(1) infinite; 67 | } 68 | .cm-animate-fat-cursor { 69 | width: auto; 70 | border: 0; 71 | -webkit-animation: blink 1.06s steps(1) infinite; 72 | -moz-animation: blink 1.06s steps(1) infinite; 73 | animation: blink 1.06s steps(1) infinite; 74 | background-color: #7e7; 75 | } 76 | @-moz-keyframes blink { 77 | 0% {} 78 | 50% { background-color: transparent; } 79 | 100% {} 80 | } 81 | @-webkit-keyframes blink { 82 | 0% {} 83 | 50% { background-color: transparent; } 84 | 100% {} 85 | } 86 | @keyframes blink { 87 | 0% {} 88 | 50% { background-color: transparent; } 89 | 100% {} 90 | } 91 | 92 | /* Can style cursor different in overwrite (non-insert) mode */ 93 | .CodeMirror-overwrite .CodeMirror-cursor {} 94 | 95 | .cm-tab { display: inline-block; text-decoration: inherit; } 96 | 97 | .CodeMirror-rulers { 98 | position: absolute; 99 | left: 0; right: 0; top: -50px; bottom: -20px; 100 | overflow: hidden; 101 | } 102 | .CodeMirror-ruler { 103 | border-left: 1px solid #ccc; 104 | top: 0; bottom: 0; 105 | position: absolute; 106 | } 107 | 108 | /* DEFAULT THEME */ 109 | 110 | .cm-s-default .cm-header {color: blue;} 111 | .cm-s-default .cm-quote {color: #090;} 112 | .cm-negative {color: #d44;} 113 | .cm-positive {color: #292;} 114 | .cm-header, .cm-strong {font-weight: bold;} 115 | .cm-em {font-style: italic;} 116 | .cm-link {text-decoration: underline;} 117 | .cm-strikethrough {text-decoration: line-through;} 118 | 119 | .cm-s-default .cm-keyword {color: #708;} 120 | .cm-s-default .cm-atom {color: #219;} 121 | .cm-s-default .cm-number {color: #164;} 122 | .cm-s-default .cm-def {color: #00f;} 123 | .cm-s-default .cm-variable, 124 | .cm-s-default .cm-punctuation, 125 | .cm-s-default .cm-property, 126 | .cm-s-default .cm-operator {} 127 | .cm-s-default .cm-variable-2 {color: #05a;} 128 | .cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;} 129 | .cm-s-default .cm-comment {color: #a50;} 130 | .cm-s-default .cm-string {color: #a11;} 131 | .cm-s-default .cm-string-2 {color: #f50;} 132 | .cm-s-default .cm-meta {color: #555;} 133 | .cm-s-default .cm-qualifier {color: #555;} 134 | .cm-s-default .cm-builtin {color: #30a;} 135 | .cm-s-default .cm-bracket {color: #997;} 136 | .cm-s-default .cm-tag {color: #170;} 137 | .cm-s-default .cm-attribute {color: #00c;} 138 | .cm-s-default .cm-hr {color: #999;} 139 | .cm-s-default .cm-link {color: #00c;} 140 | 141 | .cm-s-default .cm-error {color: #f00;} 142 | .cm-invalidchar {color: #f00;} 143 | 144 | .CodeMirror-composing { border-bottom: 2px solid; } 145 | 146 | /* Default styles for common addons */ 147 | 148 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 149 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 150 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } 151 | .CodeMirror-activeline-background {background: #e8f2ff;} 152 | 153 | /* STOP */ 154 | 155 | /* The rest of this file contains styles related to the mechanics of 156 | the editor. You probably shouldn't touch them. */ 157 | 158 | .CodeMirror { 159 | position: relative; 160 | overflow: hidden; 161 | background: white; 162 | } 163 | 164 | .CodeMirror-scroll { 165 | overflow: scroll !important; /* Things will break if this is overridden */ 166 | /* 30px is the magic margin used to hide the element's real scrollbars */ 167 | /* See overflow: hidden in .CodeMirror */ 168 | margin-bottom: -30px; margin-right: -30px; 169 | padding-bottom: 30px; 170 | height: 100%; 171 | outline: none; /* Prevent dragging from highlighting the element */ 172 | position: relative; 173 | } 174 | .CodeMirror-sizer { 175 | position: relative; 176 | border-right: 30px solid transparent; 177 | } 178 | 179 | /* The fake, visible scrollbars. Used to force redraw during scrolling 180 | before actual scrolling happens, thus preventing shaking and 181 | flickering artifacts. */ 182 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 183 | position: absolute; 184 | z-index: 6; 185 | display: none; 186 | } 187 | .CodeMirror-vscrollbar { 188 | right: 0; top: 0; 189 | overflow-x: hidden; 190 | overflow-y: scroll; 191 | } 192 | .CodeMirror-hscrollbar { 193 | bottom: 0; left: 0; 194 | overflow-y: hidden; 195 | overflow-x: scroll; 196 | } 197 | .CodeMirror-scrollbar-filler { 198 | right: 0; bottom: 0; 199 | } 200 | .CodeMirror-gutter-filler { 201 | left: 0; bottom: 0; 202 | } 203 | 204 | .CodeMirror-gutters { 205 | position: absolute; left: 0; top: 0; 206 | min-height: 100%; 207 | z-index: 3; 208 | } 209 | .CodeMirror-gutter { 210 | white-space: normal; 211 | height: 100%; 212 | display: inline-block; 213 | vertical-align: top; 214 | margin-bottom: -30px; 215 | } 216 | .CodeMirror-gutter-wrapper { 217 | position: absolute; 218 | z-index: 4; 219 | background: none !important; 220 | border: none !important; 221 | } 222 | .CodeMirror-gutter-background { 223 | position: absolute; 224 | top: 0; bottom: 0; 225 | z-index: 4; 226 | } 227 | .CodeMirror-gutter-elt { 228 | position: absolute; 229 | cursor: default; 230 | z-index: 4; 231 | } 232 | .CodeMirror-gutter-wrapper ::selection { background-color: transparent } 233 | .CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent } 234 | 235 | .CodeMirror-lines { 236 | cursor: text; 237 | min-height: 1px; /* prevents collapsing before first draw */ 238 | } 239 | .CodeMirror pre { 240 | /* Reset some styles that the rest of the page might have set */ 241 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; 242 | border-width: 0; 243 | background: transparent; 244 | font-family: inherit; 245 | font-size: inherit; 246 | margin: 0; 247 | white-space: pre; 248 | word-wrap: normal; 249 | line-height: inherit; 250 | color: inherit; 251 | z-index: 2; 252 | position: relative; 253 | overflow: visible; 254 | -webkit-tap-highlight-color: transparent; 255 | -webkit-font-variant-ligatures: contextual; 256 | font-variant-ligatures: contextual; 257 | } 258 | .CodeMirror-wrap pre { 259 | word-wrap: break-word; 260 | white-space: pre-wrap; 261 | word-break: normal; 262 | } 263 | 264 | .CodeMirror-linebackground { 265 | position: absolute; 266 | left: 0; right: 0; top: 0; bottom: 0; 267 | z-index: 0; 268 | } 269 | 270 | .CodeMirror-linewidget { 271 | position: relative; 272 | z-index: 2; 273 | overflow: auto; 274 | } 275 | 276 | .CodeMirror-widget {} 277 | 278 | .CodeMirror-rtl pre { direction: rtl; } 279 | 280 | .CodeMirror-code { 281 | outline: none; 282 | } 283 | 284 | /* Force content-box sizing for the elements where we expect it */ 285 | .CodeMirror-scroll, 286 | .CodeMirror-sizer, 287 | .CodeMirror-gutter, 288 | .CodeMirror-gutters, 289 | .CodeMirror-linenumber { 290 | -moz-box-sizing: content-box; 291 | box-sizing: content-box; 292 | } 293 | 294 | .CodeMirror-measure { 295 | position: absolute; 296 | width: 100%; 297 | height: 0; 298 | overflow: hidden; 299 | visibility: hidden; 300 | } 301 | 302 | .CodeMirror-cursor { 303 | position: absolute; 304 | pointer-events: none; 305 | } 306 | .CodeMirror-measure pre { position: static; } 307 | 308 | div.CodeMirror-cursors { 309 | visibility: hidden; 310 | position: relative; 311 | z-index: 3; 312 | } 313 | div.CodeMirror-dragcursors { 314 | visibility: visible; 315 | } 316 | 317 | .CodeMirror-focused div.CodeMirror-cursors { 318 | visibility: visible; 319 | } 320 | 321 | .CodeMirror-selected { background: #d9d9d9; } 322 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 323 | .CodeMirror-crosshair { cursor: crosshair; } 324 | .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; } 325 | .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } 326 | 327 | .cm-searching { 328 | background-color: #ffa; 329 | background-color: rgba(255, 255, 0, .4); 330 | } 331 | 332 | /* Used to force a border model for a node */ 333 | .cm-force-border { padding-right: .1px; } 334 | 335 | @media print { 336 | /* Hide the cursor when printing */ 337 | .CodeMirror div.CodeMirror-cursors { 338 | visibility: hidden; 339 | } 340 | } 341 | 342 | /* See issue #2901 */ 343 | .cm-tab-wrap-hack:after { content: ''; } 344 | 345 | /* Help users use markselection to safely style text background */ 346 | span.CodeMirror-selectedtext { background: none; } 347 | --------------------------------------------------------------------------------