| @@ -1,14 +1,14 @@ |
| 1 | /* PrismJS 1.29.0 | 1 | /* PrismJS 1.30.0 |
| 2 | https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+cmake+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+latex+lua+markdown+markup-templating+matlab+nginx+nim+nix+ocaml+perl+php+python+qml+r+jsx+ruby+rust+scss+scala+shell-session+sql+typescript+yaml+zig */ | 2 | https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+cmake+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+latex+lua+markdown+markup-templating+matlab+nginx+nim+nix+ocaml+perl+php+python+qml+r+jsx+ruby+rust+scss+scala+shell-session+sql+tcl+typescript+yaml+zig */ |
| 3 | /// <reference lib="WebWorker"/> | 3 | /// <reference lib="WebWorker"/> |
| 4 | | 4 | |
| 5 | var _self = | 5 | var _self = (typeof window !== 'undefined') |
| 6 | typeof window !== "undefined" | 6 | ? window // if in browser |
| 7 | ? window // if in browser | 7 | : ( |
| 8 | : typeof WorkerGlobalScope !== "undefined" && | 8 | (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) |
| 9 | self instanceof WorkerGlobalScope | 9 | ? self // if in worker |
| 10 | ? self // if in worker | 10 | : {} // if in node js |
| 11 | : {}; // if in node js | 11 | ); |
| 12 | | 12 | |
| 13 | /** | 13 | /** |
| 14 | * Prism: Lightweight, robust, elegant syntax highlighting | 14 | * Prism: Lightweight, robust, elegant syntax highlighting |
| @@ -19,1260 +19,1200 @@ var _self = · 4 unmodified lines |
| 19 | * @public | 19 | * @public |
| 20 | */ | 20 | */ |
| 21 | var Prism = (function (_self) { | 21 | var Prism = (function (_self) { |
| 22 | // Private helper vars | 22 | |
| 23 | var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i; | 23 | // Private helper vars |
| 24 | var uniqueId = 0; | 24 | var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i; |
| 25 | | 25 | var uniqueId = 0; |
| 26 | // The grammar object for plaintext | 26 | |
| 27 | var plainTextGrammar = {}; | 27 | // The grammar object for plaintext |
| 28 | | 28 | var plainTextGrammar = {}; |
| 29 | var _ = { | 29 | |
| 30 | /** | 30 | |
| 31 | * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the | 31 | var _ = { |
| 32 | * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load | 32 | /** |
| 33 | * additional languages or plugins yourself. | 33 | * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the |
| 34 | * | 34 | * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load |
| 35 | * By setting this value to `true`, Prism will not automatically highlight all code elements on the page. | 35 | * additional languages or plugins yourself. |
| 36 | * | 36 | * |
| 37 | * You obviously have to change this value before the automatic highlighting started. To do this, you can add an | 37 | * By setting this value to `true`, Prism will not automatically highlight all code elements on the page. |
| 38 | * empty Prism object into the global scope before loading the Prism script like this: | 38 | * |
| 39 | * | 39 | * You obviously have to change this value before the automatic highlighting started. To do this, you can add an |
| 40 | * ```js | 40 | * empty Prism object into the global scope before loading the Prism script like this: |
| 41 | * window.Prism = window.Prism || {}; | 41 | * |
| 42 | * Prism.manual = true; | 42 | * ```js |
| 43 | * // add a new <script> to load Prism's script | 43 | * window.Prism = window.Prism || {}; |
| 44 | * ``` | 44 | * Prism.manual = true; |
| 45 | * | 45 | * // add a new <script> to load Prism's script |
| 46 | * @default false | 46 | * ``` |
| 47 | * @type {boolean} | 47 | * |
| 48 | * @memberof Prism | 48 | * @default false |
| 49 | * @public | 49 | * @type {boolean} |
| 50 | */ | 50 | * @memberof Prism |
| 51 | manual: _self.Prism && _self.Prism.manual, | 51 | * @public |
| 52 | /** | 52 | */ |
| 53 | * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses | 53 | manual: _self.Prism && _self.Prism.manual, |
| 54 | * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your | 54 | /** |
| 55 | * own worker, you don't want it to do this. | 55 | * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses |
| 56 | * | 56 | * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your |
| 57 | * By setting this value to `true`, Prism will not add its own listeners to the worker. | 57 | * own worker, you don't want it to do this. |
| 58 | * | 58 | * |
| 59 | * You obviously have to change this value before Prism executes. To do this, you can add an | 59 | * By setting this value to `true`, Prism will not add its own listeners to the worker. |
| 60 | * empty Prism object into the global scope before loading the Prism script like this: | 60 | * |
| 61 | * | 61 | * You obviously have to change this value before Prism executes. To do this, you can add an |
| 62 | * ```js | 62 | * empty Prism object into the global scope before loading the Prism script like this: |
| 63 | * window.Prism = window.Prism || {}; | 63 | * |
| 64 | * Prism.disableWorkerMessageHandler = true; | 64 | * ```js |
| 65 | * // Load Prism's script | 65 | * window.Prism = window.Prism || {}; |
| 66 | * ``` | 66 | * Prism.disableWorkerMessageHandler = true; |
| 67 | * | 67 | * // Load Prism's script |
| 68 | * @default false | 68 | * ``` |
| 69 | * @type {boolean} | 69 | * |
| 70 | * @memberof Prism | 70 | * @default false |
| 71 | * @public | 71 | * @type {boolean} |
| 72 | */ | 72 | * @memberof Prism |
| 73 | disableWorkerMessageHandler: | 73 | * @public |
| 74 | _self.Prism && _self.Prism.disableWorkerMessageHandler, | 74 | */ |
| 75 | | 75 | disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, |
| 76 | /** | 76 | |
| 77 | * A namespace for utility methods. | 77 | /** |
| 78 | * | 78 | * A namespace for utility methods. |
| 79 | * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may | 79 | * |
| 80 | * change or disappear at any time. | 80 | * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may |
| 81 | * | 81 | * change or disappear at any time. |
| 82 | * @namespace | 82 | * |
| 83 | * @memberof Prism | 83 | * @namespace |
| 84 | */ | 84 | * @memberof Prism |
| 85 | util: { | 85 | */ |
| 86 | encode: function encode(tokens) { | 86 | util: { |
| 87 | if (tokens instanceof Token) { | 87 | encode: function encode(tokens) { |
| 88 | return new Token(tokens.type, encode(tokens.content), tokens.alias); | 88 | if (tokens instanceof Token) { |
| 89 | } else if (Array.isArray(tokens)) { | 89 | return new Token(tokens.type, encode(tokens.content), tokens.alias); |
| 90 | return tokens.map(encode); | 90 | } else if (Array.isArray(tokens)) { |
| 91 | } else { | 91 | return tokens.map(encode); |
| 92 | return tokens | 92 | } else { |
| 93 | .replace(/&/g, "&") | 93 | return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' '); |
| 94 | .replace(/</g, "<") | 94 | } |
| 95 | .replace(/\u00a0/g, " "); | 95 | }, |
| 96 | } | 96 | |
| 97 | }, | 97 | /** |
| 98 | | 98 | * Returns the name of the type of the given value. |
| 99 | /** | 99 | * |
| 100 | * Returns the name of the type of the given value. | 100 | * @param {any} o |
| 101 | * | 101 | * @returns {string} |
| 102 | * @param {any} o | 102 | * @example |
| 103 | * @returns {string} | 103 | * type(null) === 'Null' |
| 104 | * @example | 104 | * type(undefined) === 'Undefined' |
| 105 | * type(null) === 'Null' | 105 | * type(123) === 'Number' |
| 106 | * type(undefined) === 'Undefined' | 106 | * type('foo') === 'String' |
| 107 | * type(123) === 'Number' | 107 | * type(true) === 'Boolean' |
| 108 | * type('foo') === 'String' | 108 | * type([1, 2]) === 'Array' |
| 109 | * type(true) === 'Boolean' | 109 | * type({}) === 'Object' |
| 110 | * type([1, 2]) === 'Array' | 110 | * type(String) === 'Function' |
| 111 | * type({}) === 'Object' | 111 | * type(/abc+/) === 'RegExp' |
| 112 | * type(String) === 'Function' | 112 | */ |
| 113 | * type(/abc+/) === 'RegExp' | 113 | type: function (o) { |
| 114 | */ | 114 | return Object.prototype.toString.call(o).slice(8, -1); |
| 115 | type: function (o) { | 115 | }, |
| 116 | return Object.prototype.toString.call(o).slice(8, -1); | 116 | |
| 117 | }, | 117 | /** |
| 118 | | 118 | * Returns a unique number for the given object. Later calls will still return the same number. |
| 119 | /** | 119 | * |
| 120 | * Returns a unique number for the given object. Later calls will still return the same number. | 120 | * @param {Object} obj |
| 121 | * | 121 | * @returns {number} |
| 122 | * @param {Object} obj | 122 | */ |
| 123 | * @returns {number} | 123 | objId: function (obj) { |
| 124 | */ | 124 | if (!obj['__id']) { |
| 125 | objId: function (obj) { | 125 | Object.defineProperty(obj, '__id', { value: ++uniqueId }); |
| 126 | if (!obj["__id"]) { | 126 | } |
| 127 | Object.defineProperty(obj, "__id", { value: ++uniqueId }); | 127 | return obj['__id']; |
| 128 | } | 128 | }, |
| 129 | return obj["__id"]; | 129 | |
| 130 | }, | 130 | /** |
| 131 | | 131 | * Creates a deep clone of the given object. |
| 132 | /** | 132 | * |
| 133 | * Creates a deep clone of the given object. | 133 | * The main intended use of this function is to clone language definitions. |
| 134 | * | 134 | * |
| 135 | * The main intended use of this function is to clone language definitions. | 135 | * @param {T} o |
| 136 | * | 136 | * @param {Record<number, any>} [visited] |
| 137 | * @param {T} o | 137 | * @returns {T} |
| 138 | * @param {Record<number, any>} [visited] | 138 | * @template T |
| 139 | * @returns {T} | 139 | */ |
| 140 | * @template T | 140 | clone: function deepClone(o, visited) { |
| 141 | */ | 141 | visited = visited || {}; |
| 142 | clone: function deepClone(o, visited) { | 142 | |
| 143 | visited = visited || {}; | 143 | var clone; var id; |
| 144 | | 144 | switch (_.util.type(o)) { |
| 145 | var clone; | 145 | case 'Object': |
| 146 | var id; | 146 | id = _.util.objId(o); |
| 147 | switch (_.util.type(o)) { | 147 | if (visited[id]) { |
| 148 | case "Object": | 148 | return visited[id]; |
| 149 | id = _.util.objId(o); | 149 | } |
| 150 | if (visited[id]) { | 150 | clone = /** @type {Record<string, any>} */ ({}); |
| 151 | return visited[id]; | 151 | visited[id] = clone; |
| 152 | } | 152 | |
| 153 | clone = /** @type {Record<string, any>} */ ({}); | 153 | for (var key in o) { |
| 154 | visited[id] = clone; | 154 | if (o.hasOwnProperty(key)) { |
| 155 | | 155 | clone[key] = deepClone(o[key], visited); |
| 156 | for (var key in o) { | 156 | } |
| 157 | if (o.hasOwnProperty(key)) { | 157 | } |
| 158 | clone[key] = deepClone(o[key], visited); | 158 | |
| 159 | } | 159 | return /** @type {any} */ (clone); |
| 160 | } | 160 | |
| 161 | | 161 | case 'Array': |
| 162 | return /** @type {any} */ (clone); | 162 | id = _.util.objId(o); |
| 163 | | 163 | if (visited[id]) { |
| 164 | case "Array": | 164 | return visited[id]; |
| 165 | id = _.util.objId(o); | 165 | } |
| 166 | if (visited[id]) { | 166 | clone = []; |
| 167 | return visited[id]; | 167 | visited[id] = clone; |
| 168 | } | 168 | |
| 169 | clone = []; | 169 | (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) { |
| 170 | visited[id] = clone; | 170 | clone[i] = deepClone(v, visited); |
| 171 | | 171 | }); |
| 172 | /** @type {Array} */ (/** @type {any} */ (o)).forEach( | 172 | |
| 173 | function (v, i) { | 173 | return /** @type {any} */ (clone); |
| 174 | clone[i] = deepClone(v, visited); | 174 | |
| 175 | }, | 175 | default: |
| 176 | ); | 176 | return o; |
| 177 | | 177 | } |
| 178 | return /** @type {any} */ (clone); | 178 | }, |
| 179 | | 179 | |
| 180 | default: | 180 | /** |
| 181 | return o; | 181 | * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class. |
| 182 | } | 182 | * |
| 183 | }, | 183 | * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned. |
| 184 | | 184 | * |
| 185 | /** | 185 | * @param {Element} element |
| 186 | * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class. | 186 | * @returns {string} |
| 187 | * | 187 | */ |
| 188 | * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned. | 188 | getLanguage: function (element) { |
| 189 | * | 189 | while (element) { |
| 190 | * @param {Element} element | 190 | var m = lang.exec(element.className); |
| 191 | * @returns {string} | 191 | if (m) { |
| 192 | */ | 192 | return m[1].toLowerCase(); |
| 193 | getLanguage: function (element) { | 193 | } |
| 194 | while (element) { | 194 | element = element.parentElement; |
| 195 | var m = lang.exec(element.className); | 195 | } |
| 196 | if (m) { | 196 | return 'none'; |
| 197 | return m[1].toLowerCase(); | 197 | }, |
| 198 | } | 198 | |
| 199 | element = element.parentElement; | 199 | /** |
| 200 | } | 200 | * Sets the Prism `language-xxxx` class of the given element. |
| 201 | return "none"; | 201 | * |
| 202 | }, | 202 | * @param {Element} element |
| 203 | | 203 | * @param {string} language |
| 204 | /** | 204 | * @returns {void} |
| 205 | * Sets the Prism `language-xxxx` class of the given element. | 205 | */ |
| 206 | * | 206 | setLanguage: function (element, language) { |
| 207 | * @param {Element} element | 207 | // remove all `language-xxxx` classes |
| 208 | * @param {string} language | 208 | // (this might leave behind a leading space) |
| 209 | * @returns {void} | 209 | element.className = element.className.replace(RegExp(lang, 'gi'), ''); |
| 210 | */ | 210 | |
| 211 | setLanguage: function (element, language) { | 211 | // add the new `language-xxxx` class |
| 212 | // remove all `language-xxxx` classes | 212 | // (using `classList` will automatically clean up spaces for us) |
| 213 | // (this might leave behind a leading space) | 213 | element.classList.add('language-' + language); |
| 214 | element.className = element.className.replace(RegExp(lang, "gi"), ""); | 214 | }, |
| 215 | | 215 | |
| 216 | // add the new `language-xxxx` class | 216 | /** |
| 217 | // (using `classList` will automatically clean up spaces for us) | 217 | * Returns the script element that is currently executing. |
| 218 | element.classList.add("language-" + language); | 218 | * |
| 219 | }, | 219 | * This does __not__ work for line script element. |
| 220 | | 220 | * |
| 221 | /** | 221 | * @returns {HTMLScriptElement | null} |
| 222 | * Returns the script element that is currently executing. | 222 | */ |
| 223 | * | 223 | currentScript: function () { |
| 224 | * This does __not__ work for line script element. | 224 | if (typeof document === 'undefined') { |
| 225 | * | 225 | return null; |
| 226 | * @returns {HTMLScriptElement | null} | 226 | } |
| 227 | */ | 227 | if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) { |
| 228 | currentScript: function () { | 228 | return /** @type {any} */ (document.currentScript); |
| 229 | if (typeof document === "undefined") { | 229 | } |
| 230 | return null; | 230 | |
| 231 | } | 231 | // IE11 workaround |
| 232 | if ( | 232 | // we'll get the src of the current script by parsing IE11's error stack trace |
| 233 | "currentScript" in document && | 233 | // this will not work for inline scripts |
| 234 | 1 < 2 /* hack to trip TS' flow analysis */ | 234 | |
| 235 | ) { | 235 | try { |
| 236 | return /** @type {any} */ (document.currentScript); | 236 | throw new Error(); |
| 237 | } | 237 | } catch (err) { |
| 238 | | 238 | // Get file src url from stack. Specifically works with the format of stack traces in IE. |
| 239 | // IE11 workaround | 239 | // A stack will look like this: |
| 240 | // we'll get the src of the current script by parsing IE11's error stack trace | 240 | // |
| 241 | // this will not work for inline scripts | 241 | // Error |
| 242 | | 242 | // at _.util.currentScript (http://localhost/components/prism-core.js:119:5) |
| 243 | try { | 243 | // at Global code (http://localhost/components/prism-core.js:606:1) |
| 244 | throw new Error(); | 244 | |
| 245 | } catch (err) { | 245 | var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1]; |
| 246 | // Get file src url from stack. Specifically works with the format of stack traces in IE. | 246 | if (src) { |
| 247 | // A stack will look like this: | 247 | var scripts = document.getElementsByTagName('script'); |
| 248 | // | 248 | for (var i in scripts) { |
| 249 | // Error | 249 | if (scripts[i].src == src) { |
| 250 | // at _.util.currentScript (http://localhost/components/prism-core.js:119:5) | 250 | return scripts[i]; |
| 251 | // at Global code (http://localhost/components/prism-core.js:606:1) | 251 | } |
| 252 | | 252 | } |
| 253 | var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || | 253 | } |
| 254 | [])[1]; | 254 | return null; |
| 255 | if (src) { | 255 | } |
| 256 | var scripts = document.getElementsByTagName("script"); | 256 | }, |
| 257 | for (var i in scripts) { | 257 | |
| 258 | if (scripts[i].src == src) { | 258 | /** |
| 259 | return scripts[i]; | 259 | * Returns whether a given class is active for `element`. |
| 260 | } | 260 | * |
| 261 | } | 261 | * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated |
| 262 | } | 262 | * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the |
| 263 | return null; | 263 | * given class is just the given class with a `no-` prefix. |
| 264 | } | 264 | * |
| 265 | }, | 265 | * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is |
| 266 | | 266 | * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its |
| 267 | /** | 267 | * ancestors have the given class or the negated version of it, then the default activation will be returned. |
| 268 | * Returns whether a given class is active for `element`. | 268 | * |
| 269 | * | 269 | * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated |
| 270 | * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated | 270 | * version of it, the class is considered active. |
| 271 | * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the | 271 | * |
| 272 | * given class is just the given class with a `no-` prefix. | 272 | * @param {Element} element |
| 273 | * | 273 | * @param {string} className |
| 274 | * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is | 274 | * @param {boolean} [defaultActivation=false] |
| 275 | * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its | 275 | * @returns {boolean} |
| 276 | * ancestors have the given class or the negated version of it, then the default activation will be returned. | 276 | */ |
| 277 | * | 277 | isActive: function (element, className, defaultActivation) { |
| 278 | * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated | 278 | var no = 'no-' + className; |
| 279 | * version of it, the class is considered active. | 279 | |
| 280 | * | 280 | while (element) { |
| 281 | * @param {Element} element | 281 | var classList = element.classList; |
| 282 | * @param {string} className | 282 | if (classList.contains(className)) { |
| 283 | * @param {boolean} [defaultActivation=false] | 283 | return true; |
| 284 | * @returns {boolean} | 284 | } |
| 285 | */ | 285 | if (classList.contains(no)) { |
| 286 | isActive: function (element, className, defaultActivation) { | 286 | return false; |
| 287 | var no = "no-" + className; | 287 | } |
| 288 | | 288 | element = element.parentElement; |
| 289 | while (element) { | 289 | } |
| 290 | var classList = element.classList; | 290 | return !!defaultActivation; |
| 291 | if (classList.contains(className)) { | 291 | } |
| 292 | return true; | 292 | }, |
| 293 | } | 293 | |
| 294 | if (classList.contains(no)) { | 294 | /** |
| 295 | return false; | 295 | * This namespace contains all currently loaded languages and the some helper functions to create and modify languages. |
| 296 | } | 296 | * |
| 297 | element = element.parentElement; | 297 | * @namespace |
| 298 | } | 298 | * @memberof Prism |
| 299 | return !!defaultActivation; | 299 | * @public |
| 300 | }, | 300 | */ |
| 301 | }, | 301 | languages: { |
| 302 | | 302 | /** |
| 303 | /** | 303 | * The grammar for plain, unformatted text. |
| 304 | * This namespace contains all currently loaded languages and the some helper functions to create and modify languages. | 304 | */ |
| 305 | * | 305 | plain: plainTextGrammar, |
| 306 | * @namespace | 306 | plaintext: plainTextGrammar, |
| 307 | * @memberof Prism | 307 | text: plainTextGrammar, |
| 308 | * @public | 308 | txt: plainTextGrammar, |
| 309 | */ | 309 | |
| 310 | languages: { | 310 | /** |
| 311 | /** | 311 | * Creates a deep copy of the language with the given id and appends the given tokens. |
| 312 | * The grammar for plain, unformatted text. | 312 | * |
| 313 | */ | 313 | * If a token in `redef` also appears in the copied language, then the existing token in the copied language |
| 314 | plain: plainTextGrammar, | 314 | * will be overwritten at its original position. |
| 315 | plaintext: plainTextGrammar, | 315 | * |
| 316 | text: plainTextGrammar, | 316 | * ## Best practices |
| 317 | txt: plainTextGrammar, | 317 | * |
| 318 | | 318 | * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language) |
| 319 | /** | 319 | * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to |
| 320 | * Creates a deep copy of the language with the given id and appends the given tokens. | 320 | * understand the language definition because, normally, the order of tokens matters in Prism grammars. |
| 321 | * | 321 | * |
| 322 | * If a token in `redef` also appears in the copied language, then the existing token in the copied language | 322 | * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens. |
| 323 | * will be overwritten at its original position. | 323 | * Furthermore, all non-overwriting tokens should be placed after the overwriting ones. |
| 324 | * | 324 | * |
| 325 | * ## Best practices | 325 | * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`. |
| 326 | * | 326 | * @param {Grammar} redef The new tokens to append. |
| 327 | * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language) | 327 | * @returns {Grammar} The new language created. |
| 328 | * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to | 328 | * @public |
| 329 | * understand the language definition because, normally, the order of tokens matters in Prism grammars. | 329 | * @example |
| 330 | * | 330 | * Prism.languages['css-with-colors'] = Prism.languages.extend('css', { |
| 331 | * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens. | 331 | * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token |
| 332 | * Furthermore, all non-overwriting tokens should be placed after the overwriting ones. | 332 | * // at its original position |
| 333 | * | 333 | * 'comment': { ... }, |
| 334 | * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`. | 334 | * // CSS doesn't have a 'color' token, so this token will be appended |
| 335 | * @param {Grammar} redef The new tokens to append. | 335 | * 'color': /\b(?:red|green|blue)\b/ |
| 336 | * @returns {Grammar} The new language created. | 336 | * }); |
| 337 | * @public | 337 | */ |
| 338 | * @example | 338 | extend: function (id, redef) { |
| 339 | * Prism.languages['css-with-colors'] = Prism.languages.extend('css', { | 339 | var lang = _.util.clone(_.languages[id]); |
| 340 | * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token | 340 | |
| 341 | * // at its original position | 341 | for (var key in redef) { |
| 342 | * 'comment': { ... }, | 342 | lang[key] = redef[key]; |
| 343 | * // CSS doesn't have a 'color' token, so this token will be appended | 343 | } |
| 344 | * 'color': /\b(?:red|green|blue)\b/ | 344 | |
| 345 | * }); | 345 | return lang; |
| 346 | */ | 346 | }, |
| 347 | extend: function (id, redef) { | 347 | |
| 348 | var lang = _.util.clone(_.languages[id]); | 348 | /** |
| 349 | | 349 | * Inserts tokens _before_ another token in a language definition or any other grammar. |
| 350 | for (var key in redef) { | 350 | * |
| 351 | lang[key] = redef[key]; | 351 | * ## Usage |
| 352 | } | 352 | * |
| 353 | | 353 | * This helper method makes it easy to modify existing languages. For example, the CSS language definition |
| 354 | return lang; | 354 | * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded |
| 355 | }, | 355 | * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the |
| 356 | | 356 | * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do |
| 357 | /** | 357 | * this: |
| 358 | * Inserts tokens _before_ another token in a language definition or any other grammar. | 358 | * |
| 359 | * | 359 | * ```js |
| 360 | * ## Usage | 360 | * Prism.languages.markup.style = { |
| 361 | * | 361 | * // token |
| 362 | * This helper method makes it easy to modify existing languages. For example, the CSS language definition | 362 | * }; |
| 363 | * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded | 363 | * ``` |
| 364 | * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the | 364 | * |
| 365 | * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do | 365 | * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens |
| 366 | * this: | 366 | * before existing tokens. For the CSS example above, you would use it like this: |
| 367 | * | 367 | * |
| 368 | * ```js | 368 | * ```js |
| 369 | * Prism.languages.markup.style = { | 369 | * Prism.languages.insertBefore('markup', 'cdata', { |
| 370 | * // token | 370 | * 'style': { |
| 371 | * }; | 371 | * // token |
| 372 | * ``` | 372 | * } |
| 373 | * | 373 | * }); |
| 374 | * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens | 374 | * ``` |
| 375 | * before existing tokens. For the CSS example above, you would use it like this: | 375 | * |
| 376 | * | 376 | * ## Special cases |
| 377 | * ```js | 377 | * |
| 378 | * Prism.languages.insertBefore('markup', 'cdata', { | 378 | * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar |
| 379 | * 'style': { | 379 | * will be ignored. |
| 380 | * // token | 380 | * |
| 381 | * } | 381 | * This behavior can be used to insert tokens after `before`: |
| 382 | * }); | 382 | * |
| 383 | * ``` | 383 | * ```js |
| 384 | * | 384 | * Prism.languages.insertBefore('markup', 'comment', { |
| 385 | * ## Special cases | 385 | * 'comment': Prism.languages.markup.comment, |
| 386 | * | 386 | * // tokens after 'comment' |
| 387 | * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar | 387 | * }); |
| 388 | * will be ignored. | 388 | * ``` |
| 389 | * | 389 | * |
| 390 | * This behavior can be used to insert tokens after `before`: | 390 | * ## Limitations |
| 391 | * | 391 | * |
| 392 | * ```js | 392 | * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object |
| 393 | * Prism.languages.insertBefore('markup', 'comment', { | 393 | * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave |
| 394 | * 'comment': Prism.languages.markup.comment, | 394 | * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily |
| 395 | * // tokens after 'comment' | 395 | * deleting properties which is necessary to insert at arbitrary positions. |
| 396 | * }); | 396 | * |
| 397 | * ``` | 397 | * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object. |
| 398 | * | 398 | * Instead, it will create a new object and replace all references to the target object with the new one. This |
| 399 | * ## Limitations | 399 | * can be done without temporarily deleting properties, so the iteration order is well-defined. |
| 400 | * | 400 | * |
| 401 | * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object | 401 | * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if |
| 402 | * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave | 402 | * you hold the target object in a variable, then the value of the variable will not change. |
| 403 | * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily | 403 | * |
| 404 | * deleting properties which is necessary to insert at arbitrary positions. | 404 | * ```js |
| 405 | * | 405 | * var oldMarkup = Prism.languages.markup; |
| 406 | * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object. | 406 | * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... }); |
| 407 | * Instead, it will create a new object and replace all references to the target object with the new one. This | 407 | * |
| 408 | * can be done without temporarily deleting properties, so the iteration order is well-defined. | 408 | * assert(oldMarkup !== Prism.languages.markup); |
| 409 | * | 409 | * assert(newMarkup === Prism.languages.markup); |
| 410 | * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if | 410 | * ``` |
| 411 | * you hold the target object in a variable, then the value of the variable will not change. | 411 | * |
| 412 | * | 412 | * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the |
| 413 | * ```js | 413 | * object to be modified. |
| 414 | * var oldMarkup = Prism.languages.markup; | 414 | * @param {string} before The key to insert before. |
| 415 | * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... }); | 415 | * @param {Grammar} insert An object containing the key-value pairs to be inserted. |
| 416 | * | 416 | * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the |
| 417 | * assert(oldMarkup !== Prism.languages.markup); | 417 | * object to be modified. |
| 418 | * assert(newMarkup === Prism.languages.markup); | 418 | * |
| 419 | * ``` | 419 | * Defaults to `Prism.languages`. |
| 420 | * | 420 | * @returns {Grammar} The new grammar object. |
| 421 | * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the | 421 | * @public |
| 422 | * object to be modified. | 422 | */ |
| 423 | * @param {string} before The key to insert before. | 423 | insertBefore: function (inside, before, insert, root) { |
| 424 | * @param {Grammar} insert An object containing the key-value pairs to be inserted. | 424 | root = root || /** @type {any} */ (_.languages); |
| 425 | * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the | 425 | var grammar = root[inside]; |
| 426 | * object to be modified. | 426 | /** @type {Grammar} */ |
| 427 | * | 427 | var ret = {}; |
| 428 | * Defaults to `Prism.languages`. | 428 | |
| 429 | * @returns {Grammar} The new grammar object. | 429 | for (var token in grammar) { |
| 430 | * @public | 430 | if (grammar.hasOwnProperty(token)) { |
| 431 | */ | 431 | |
| 432 | insertBefore: function (inside, before, insert, root) { | 432 | if (token == before) { |
| 433 | root = root || /** @type {any} */ (_.languages); | 433 | for (var newToken in insert) { |
| 434 | var grammar = root[inside]; | 434 | if (insert.hasOwnProperty(newToken)) { |
| 435 | /** @type {Grammar} */ | 435 | ret[newToken] = insert[newToken]; |
| 436 | var ret = {}; | 436 | } |
| 437 | | 437 | } |
| 438 | for (var token in grammar) { | 438 | } |
| 439 | if (grammar.hasOwnProperty(token)) { | 439 | |
| 440 | if (token == before) { | 440 | // Do not insert token which also occur in insert. See #1525 |
| 441 | for (var newToken in insert) { | 441 | if (!insert.hasOwnProperty(token)) { |
| 442 | if (insert.hasOwnProperty(newToken)) { | 442 | ret[token] = grammar[token]; |
| 443 | ret[newToken] = insert[newToken]; | 443 | } |
| 444 | } | 444 | } |
| 445 | } | 445 | } |
| 446 | } | 446 | |
| 447 | | 447 | var old = root[inside]; |
| 448 | // Do not insert token which also occur in insert. See #1525 | 448 | root[inside] = ret; |
| 449 | if (!insert.hasOwnProperty(token)) { | 449 | |
| 450 | ret[token] = grammar[token]; | 450 | // Update references in other language definitions |
| 451 | } | 451 | _.languages.DFS(_.languages, function (key, value) { |
| 452 | } | 452 | if (value === old && key != inside) { |
| 453 | } | 453 | this[key] = ret; |
| 454 | | 454 | } |
| 455 | var old = root[inside]; | 455 | }); |
| 456 | root[inside] = ret; | 456 | |
| 457 | | 457 | return ret; |
| 458 | // Update references in other language definitions | 458 | }, |
| 459 | _.languages.DFS(_.languages, function (key, value) { | 459 | |
| 460 | if (value === old && key != inside) { | 460 | // Traverse a language definition with Depth First Search |
| 461 | this[key] = ret; | 461 | DFS: function DFS(o, callback, type, visited) { |
| 462 | } | 462 | visited = visited || {}; |
| 463 | }); | 463 | |
| 464 | | 464 | var objId = _.util.objId; |
| 465 | return ret; | 465 | |
| 466 | }, | 466 | for (var i in o) { |
| 467 | | 467 | if (o.hasOwnProperty(i)) { |
| 468 | // Traverse a language definition with Depth First Search | 468 | callback.call(o, i, o[i], type || i); |
| 469 | DFS: function DFS(o, callback, type, visited) { | 469 | |
| 470 | visited = visited || {}; | 470 | var property = o[i]; |
| 471 | | 471 | var propertyType = _.util.type(property); |
| 472 | var objId = _.util.objId; | 472 | |
| 473 | | 473 | if (propertyType === 'Object' && !visited[objId(property)]) { |
| 474 | for (var i in o) { | 474 | visited[objId(property)] = true; |
| 475 | if (o.hasOwnProperty(i)) { | 475 | DFS(property, callback, null, visited); |
| 476 | callback.call(o, i, o[i], type || i); | 476 | } else if (propertyType === 'Array' && !visited[objId(property)]) { |
| 477 | | 477 | visited[objId(property)] = true; |
| 478 | var property = o[i]; | 478 | DFS(property, callback, i, visited); |
| 479 | var propertyType = _.util.type(property); | 479 | } |
| 480 | | 480 | } |
| 481 | if (propertyType === "Object" && !visited[objId(property)]) { | 481 | } |
| 482 | visited[objId(property)] = true; | 482 | } |
| 483 | DFS(property, callback, null, visited); | 483 | }, |
| 484 | } else if (propertyType === "Array" && !visited[objId(property)]) { | 484 | |
| 485 | visited[objId(property)] = true; | 485 | plugins: {}, |
| 486 | DFS(property, callback, i, visited); | 486 | |
| 487 | } | 487 | /** |
| 488 | } | 488 | * This is the most high-level function in Prism’s API. |
| 489 | } | 489 | * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on |
| 490 | }, | 490 | * each one of them. |
| 491 | }, | 491 | * |
| 492 | | 492 | * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`. |
| 493 | plugins: {}, | 493 | * |
| 494 | | 494 | * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}. |
| 495 | /** | 495 | * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}. |
| 496 | * This is the most high-level function in Prism’s API. | 496 | * @memberof Prism |
| 497 | * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on | 497 | * @public |
| 498 | * each one of them. | 498 | */ |
| 499 | * | 499 | highlightAll: function (async, callback) { |
| 500 | * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`. | 500 | _.highlightAllUnder(document, async, callback); |
| 501 | * | 501 | }, |
| 502 | * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}. | 502 | |
| 503 | * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}. | 503 | /** |
| 504 | * @memberof Prism | 504 | * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls |
| 505 | * @public | 505 | * {@link Prism.highlightElement} on each one of them. |
| 506 | */ | 506 | * |
| 507 | highlightAll: function (async, callback) { | 507 | * The following hooks will be run: |
| 508 | _.highlightAllUnder(document, async, callback); | 508 | * 1. `before-highlightall` |
| 509 | }, | 509 | * 2. `before-all-elements-highlight` |
| 510 | | 510 | * 3. All hooks of {@link Prism.highlightElement} for each element. |
| 511 | /** | 511 | * |
| 512 | * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls | 512 | * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted. |
| 513 | * {@link Prism.highlightElement} on each one of them. | 513 | * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers. |
| 514 | * | 514 | * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done. |
| 515 | * The following hooks will be run: | 515 | * @memberof Prism |
| 516 | * 1. `before-highlightall` | 516 | * @public |
| 517 | * 2. `before-all-elements-highlight` | 517 | */ |
| 518 | * 3. All hooks of {@link Prism.highlightElement} for each element. | 518 | highlightAllUnder: function (container, async, callback) { |
| 519 | * | 519 | var env = { |
| 520 | * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted. | 520 | callback: callback, |
| 521 | * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers. | 521 | container: container, |
| 522 | * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done. | 522 | selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code' |
| 523 | * @memberof Prism | 523 | }; |
| 524 | * @public | 524 | |
| 525 | */ | 525 | _.hooks.run('before-highlightall', env); |
| 526 | highlightAllUnder: function (container, async, callback) { | 526 | |
| 527 | var env = { | 527 | env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector)); |
| 528 | callback: callback, | 528 | |
| 529 | container: container, | 529 | _.hooks.run('before-all-elements-highlight', env); |
| 530 | selector: | 530 | |
| 531 | 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code', | 531 | for (var i = 0, element; (element = env.elements[i++]);) { |
| 532 | }; | 532 | _.highlightElement(element, async === true, env.callback); |
| 533 | | 533 | } |
| 534 | _.hooks.run("before-highlightall", env); | 534 | }, |
| 535 | | 535 | |
| 536 | env.elements = Array.prototype.slice.apply( | 536 | /** |
| 537 | env.container.querySelectorAll(env.selector), | 537 | * Highlights the code inside a single element. |
| 538 | ); | 538 | * |
| 539 | | 539 | * The following hooks will be run: |
| 540 | _.hooks.run("before-all-elements-highlight", env); | 540 | * 1. `before-sanity-check` |
| 541 | | 541 | * 2. `before-highlight` |
| 542 | for (var i = 0, element; (element = env.elements[i++]); ) { | 542 | * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`. |
| 543 | _.highlightElement(element, async === true, env.callback); | 543 | * 4. `before-insert` |
| 544 | } | 544 | * 5. `after-highlight` |
| 545 | }, | 545 | * 6. `complete` |
| 546 | | 546 | * |
| 547 | /** | 547 | * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for |
| 548 | * Highlights the code inside a single element. | 548 | * the element's language. |
| 549 | * | 549 | * |
| 550 | * The following hooks will be run: | 550 | * @param {Element} element The element containing the code. |
| 551 | * 1. `before-sanity-check` | 551 | * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier. |
| 552 | * 2. `before-highlight` | 552 | * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers |
| 553 | * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`. | 553 | * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is |
| 554 | * 4. `before-insert` | 554 | * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default). |
| 555 | * 5. `after-highlight` | 555 | * |
| 556 | * 6. `complete` | 556 | * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for |
| 557 | * | 557 | * asynchronous highlighting to work. You can build your own bundle on the |
| 558 | * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for | 558 | * [Download page](https://prismjs.com/download.html). |
| 559 | * the element's language. | 559 | * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done. |
| 560 | * | 560 | * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously. |
| 561 | * @param {Element} element The element containing the code. | 561 | * @memberof Prism |
| 562 | * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier. | 562 | * @public |
| 563 | * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers | 563 | */ |
| 564 | * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is | 564 | highlightElement: function (element, async, callback) { |
| 565 | * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default). | 565 | // Find language |
| 566 | * | 566 | var language = _.util.getLanguage(element); |
| 567 | * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for | 567 | var grammar = _.languages[language]; |
| 568 | * asynchronous highlighting to work. You can build your own bundle on the | 568 | |
| 569 | * [Download page](https://prismjs.com/download.html). | 569 | // Set language on the element, if not present |
| 570 | * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done. | 570 | _.util.setLanguage(element, language); |
| 571 | * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously. | 571 | |
| 572 | * @memberof Prism | 572 | // Set language on the parent, for styling |
| 573 | * @public | 573 | var parent = element.parentElement; |
| 574 | */ | 574 | if (parent && parent.nodeName.toLowerCase() === 'pre') { |
| 575 | highlightElement: function (element, async, callback) { | 575 | _.util.setLanguage(parent, language); |
| 576 | // Find language | 576 | } |
| 577 | var language = _.util.getLanguage(element); | 577 | |
| 578 | var grammar = _.languages[language]; | 578 | var code = element.textContent; |
| 579 | | 579 | |
| 580 | // Set language on the element, if not present | 580 | var env = { |
| 581 | _.util.setLanguage(element, language); | 581 | element: element, |
| 582 | | 582 | language: language, |
| 583 | // Set language on the parent, for styling | 583 | grammar: grammar, |
| 584 | var parent = element.parentElement; | 584 | code: code |
| 585 | if (parent && parent.nodeName.toLowerCase() === "pre") { | 585 | }; |
| 586 | _.util.setLanguage(parent, language); | 586 | |
| 587 | } | 587 | function insertHighlightedCode(highlightedCode) { |
| 588 | | 588 | env.highlightedCode = highlightedCode; |
| 589 | var code = element.textContent; | 589 | |
| 590 | | 590 | _.hooks.run('before-insert', env); |
| 591 | var env = { | 591 | |
| 592 | element: element, | 592 | env.element.innerHTML = env.highlightedCode; |
| 593 | language: language, | 593 | |
| 594 | grammar: grammar, | 594 | _.hooks.run('after-highlight', env); |
| 595 | code: code, | 595 | _.hooks.run('complete', env); |
| 596 | }; | 596 | callback && callback.call(env.element); |
| 597 | | 597 | } |
| 598 | function insertHighlightedCode(highlightedCode) { | 598 | |
| 599 | env.highlightedCode = highlightedCode; | 599 | _.hooks.run('before-sanity-check', env); |
| 600 | | 600 | |
| 601 | _.hooks.run("before-insert", env); | 601 | // plugins may change/add the parent/element |
| 602 | | 602 | parent = env.element.parentElement; |
| 603 | env.element.innerHTML = env.highlightedCode; | 603 | if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) { |
| 604 | | 604 | parent.setAttribute('tabindex', '0'); |
| 605 | _.hooks.run("after-highlight", env); | 605 | } |
| 606 | _.hooks.run("complete", env); | 606 | |
| 607 | callback && callback.call(env.element); | 607 | if (!env.code) { |
| 608 | } | 608 | _.hooks.run('complete', env); |
| 609 | | 609 | callback && callback.call(env.element); |
| 610 | _.hooks.run("before-sanity-check", env); | 610 | return; |
| 611 | | 611 | } |
| 612 | // plugins may change/add the parent/element | 612 | |
| 613 | parent = env.element.parentElement; | 613 | _.hooks.run('before-highlight', env); |
| 614 | if ( | 614 | |
| 615 | parent && | 615 | if (!env.grammar) { |
| 616 | parent.nodeName.toLowerCase() === "pre" && | 616 | insertHighlightedCode(_.util.encode(env.code)); |
| 617 | !parent.hasAttribute("tabindex") | 617 | return; |
| 618 | ) { | 618 | } |
| 619 | parent.setAttribute("tabindex", "0"); | 619 | |
| 620 | } | 620 | if (async && _self.Worker) { |
| 621 | | 621 | var worker = new Worker(_.filename); |
| 622 | if (!env.code) { | 622 | |
| 623 | _.hooks.run("complete", env); | 623 | worker.onmessage = function (evt) { |
| 624 | callback && callback.call(env.element); | 624 | insertHighlightedCode(evt.data); |
| 625 | return; | 625 | }; |
| 626 | } | 626 | |
| 627 | | 627 | worker.postMessage(JSON.stringify({ |
| 628 | _.hooks.run("before-highlight", env); | 628 | language: env.language, |
| 629 | | 629 | code: env.code, |
| 630 | if (!env.grammar) { | 630 | immediateClose: true |
| 631 | insertHighlightedCode(_.util.encode(env.code)); | 631 | })); |
| 632 | return; | 632 | } else { |
| 633 | } | 633 | insertHighlightedCode(_.highlight(env.code, env.grammar, env.language)); |
| 634 | | 634 | } |
| 635 | if (async && _self.Worker) { | 635 | }, |
| 636 | var worker = new Worker(_.filename); | 636 | |
| 637 | | 637 | /** |
| 638 | worker.onmessage = function (evt) { | 638 | * Low-level function, only use if you know what you’re doing. It accepts a string of text as input |
| 639 | insertHighlightedCode(evt.data); | 639 | * and the language definitions to use, and returns a string with the HTML produced. |
| 640 | }; | 640 | * |
| 641 | | 641 | * The following hooks will be run: |
| 642 | worker.postMessage( | 642 | * 1. `before-tokenize` |
| 643 | JSON.stringify({ | 643 | * 2. `after-tokenize` |
| 644 | language: env.language, | 644 | * 3. `wrap`: On each {@link Token}. |
| 645 | code: env.code, | 645 | * |
| 646 | immediateClose: true, | 646 | * @param {string} text A string with the code to be highlighted. |
| 647 | }), | 647 | * @param {Grammar} grammar An object containing the tokens to use. |
| 648 | ); | 648 | * |
| 649 | } else { | 649 | * Usually a language definition like `Prism.languages.markup`. |
| 650 | insertHighlightedCode(_.highlight(env.code, env.grammar, env.language)); | 650 | * @param {string} language The name of the language definition passed to `grammar`. |
| 651 | } | 651 | * @returns {string} The highlighted HTML. |
| 652 | }, | 652 | * @memberof Prism |
| 653 | | 653 | * @public |
| 654 | /** | 654 | * @example |
| 655 | * Low-level function, only use if you know what you’re doing. It accepts a string of text as input | 655 | * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript'); |
| 656 | * and the language definitions to use, and returns a string with the HTML produced. | 656 | */ |
| 657 | * | 657 | highlight: function (text, grammar, language) { |
| 658 | * The following hooks will be run: | 658 | var env = { |
| 659 | * 1. `before-tokenize` | 659 | code: text, |
| 660 | * 2. `after-tokenize` | 660 | grammar: grammar, |
| 661 | * 3. `wrap`: On each {@link Token}. | 661 | language: language |
| 662 | * | 662 | }; |
| 663 | * @param {string} text A string with the code to be highlighted. | 663 | _.hooks.run('before-tokenize', env); |
| 664 | * @param {Grammar} grammar An object containing the tokens to use. | 664 | if (!env.grammar) { |
| 665 | * | 665 | throw new Error('The language "' + env.language + '" has no grammar.'); |
| 666 | * Usually a language definition like `Prism.languages.markup`. | 666 | } |
| 667 | * @param {string} language The name of the language definition passed to `grammar`. | 667 | env.tokens = _.tokenize(env.code, env.grammar); |
| 668 | * @returns {string} The highlighted HTML. | 668 | _.hooks.run('after-tokenize', env); |
| 669 | * @memberof Prism | 669 | return Token.stringify(_.util.encode(env.tokens), env.language); |
| 670 | * @public | 670 | }, |
| 671 | * @example | 671 | |
| 672 | * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript'); | 672 | /** |
| 673 | */ | 673 | * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input |
| 674 | highlight: function (text, grammar, language) { | 674 | * and the language definitions to use, and returns an array with the tokenized code. |
| 675 | var env = { | 675 | * |
| 676 | code: text, | 676 | * When the language definition includes nested tokens, the function is called recursively on each of these tokens. |
| 677 | grammar: grammar, | 677 | * |
| 678 | language: language, | 678 | * This method could be useful in other contexts as well, as a very crude parser. |
| 679 | }; | 679 | * |
| 680 | _.hooks.run("before-tokenize", env); | 680 | * @param {string} text A string with the code to be highlighted. |
| 681 | if (!env.grammar) { | 681 | * @param {Grammar} grammar An object containing the tokens to use. |
| 682 | throw new Error('The language "' + env.language + '" has no grammar.'); | 682 | * |
| 683 | } | 683 | * Usually a language definition like `Prism.languages.markup`. |
| 684 | env.tokens = _.tokenize(env.code, env.grammar); | 684 | * @returns {TokenStream} An array of strings and tokens, a token stream. |
| 685 | _.hooks.run("after-tokenize", env); | 685 | * @memberof Prism |
| 686 | return Token.stringify(_.util.encode(env.tokens), env.language); | 686 | * @public |
| 687 | }, | 687 | * @example |
| 688 | | 688 | * let code = `var foo = 0;`; |
| 689 | /** | 689 | * let tokens = Prism.tokenize(code, Prism.languages.javascript); |
| 690 | * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input | 690 | * tokens.forEach(token => { |
| 691 | * and the language definitions to use, and returns an array with the tokenized code. | 691 | * if (token instanceof Prism.Token && token.type === 'number') { |
| 692 | * | 692 | * console.log(`Found numeric literal: ${token.content}`); |
| 693 | * When the language definition includes nested tokens, the function is called recursively on each of these tokens. | 693 | * } |
| 694 | * | 694 | * }); |
| 695 | * This method could be useful in other contexts as well, as a very crude parser. | 695 | */ |
| 696 | * | 696 | tokenize: function (text, grammar) { |
| 697 | * @param {string} text A string with the code to be highlighted. | 697 | var rest = grammar.rest; |
| 698 | * @param {Grammar} grammar An object containing the tokens to use. | 698 | if (rest) { |
| 699 | * | 699 | for (var token in rest) { |
| 700 | * Usually a language definition like `Prism.languages.markup`. | 700 | grammar[token] = rest[token]; |
| 701 | * @returns {TokenStream} An array of strings and tokens, a token stream. | 701 | } |
| 702 | * @memberof Prism | 702 | |
| 703 | * @public | 703 | delete grammar.rest; |
| 704 | * @example | 704 | } |
| 705 | * let code = `var foo = 0;`; | 705 | |
| 706 | * let tokens = Prism.tokenize(code, Prism.languages.javascript); | 706 | var tokenList = new LinkedList(); |
| 707 | * tokens.forEach(token => { | 707 | addAfter(tokenList, tokenList.head, text); |
| 708 | * if (token instanceof Prism.Token && token.type === 'number') { | 708 | |
| 709 | * console.log(`Found numeric literal: ${token.content}`); | 709 | matchGrammar(text, tokenList, grammar, tokenList.head, 0); |
| 710 | * } | 710 | |
| 711 | * }); | 711 | return toArray(tokenList); |
| 712 | */ | 712 | }, |
| 713 | tokenize: function (text, grammar) { | 713 | |
| 714 | var rest = grammar.rest; | 714 | /** |
| 715 | if (rest) { | 715 | * @namespace |
| 716 | for (var token in rest) { | 716 | * @memberof Prism |
| 717 | grammar[token] = rest[token]; | 717 | * @public |
| 718 | } | 718 | */ |
| 719 | | 719 | hooks: { |
| 720 | delete grammar.rest; | 720 | all: {}, |
| 721 | } | 721 | |
| 722 | | 722 | /** |
| 723 | var tokenList = new LinkedList(); | 723 | * Adds the given callback to the list of callbacks for the given hook. |
| 724 | addAfter(tokenList, tokenList.head, text); | 724 | * |
| 725 | | 725 | * The callback will be invoked when the hook it is registered for is run. |
| 726 | matchGrammar(text, tokenList, grammar, tokenList.head, 0); | 726 | * Hooks are usually directly run by a highlight function but you can also run hooks yourself. |
| 727 | | 727 | * |
| 728 | return toArray(tokenList); | 728 | * One callback function can be registered to multiple hooks and the same hook multiple times. |
| 729 | }, | 729 | * |
| 730 | | 730 | * @param {string} name The name of the hook. |
| 731 | /** | 731 | * @param {HookCallback} callback The callback function which is given environment variables. |
| 732 | * @namespace | 732 | * @public |
| 733 | * @memberof Prism | 733 | */ |
| 734 | * @public | 734 | add: function (name, callback) { |
| 735 | */ | 735 | var hooks = _.hooks.all; |
| 736 | hooks: { | 736 | |
| 737 | all: {}, | 737 | hooks[name] = hooks[name] || []; |
| 738 | | 738 | |
| 739 | /** | 739 | hooks[name].push(callback); |
| 740 | * Adds the given callback to the list of callbacks for the given hook. | 740 | }, |
| 741 | * | 741 | |
| 742 | * The callback will be invoked when the hook it is registered for is run. | 742 | /** |
| 743 | * Hooks are usually directly run by a highlight function but you can also run hooks yourself. | 743 | * Runs a hook invoking all registered callbacks with the given environment variables. |
| 744 | * | 744 | * |
| 745 | * One callback function can be registered to multiple hooks and the same hook multiple times. | 745 | * Callbacks will be invoked synchronously and in the order in which they were registered. |
| 746 | * | 746 | * |
| 747 | * @param {string} name The name of the hook. | 747 | * @param {string} name The name of the hook. |
| 748 | * @param {HookCallback} callback The callback function which is given environment variables. | 748 | * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered. |
| 749 | * @public | 749 | * @public |
| 750 | */ | 750 | */ |
| 751 | add: function (name, callback) { | 751 | run: function (name, env) { |
| 752 | var hooks = _.hooks.all; | 752 | var callbacks = _.hooks.all[name]; |
| 753 | | 753 | |
| 754 | hooks[name] = hooks[name] || []; | 754 | if (!callbacks || !callbacks.length) { |
| 755 | | 755 | return; |
| 756 | hooks[name].push(callback); | 756 | } |
| 757 | }, | 757 | |
| 758 | | 758 | for (var i = 0, callback; (callback = callbacks[i++]);) { |
| 759 | /** | 759 | callback(env); |
| 760 | * Runs a hook invoking all registered callbacks with the given environment variables. | 760 | } |
| 761 | * | 761 | } |
| 762 | * Callbacks will be invoked synchronously and in the order in which they were registered. | 762 | }, |
| 763 | * | 763 | |
| 764 | * @param {string} name The name of the hook. | 764 | Token: Token |
| 765 | * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered. | 765 | }; |
| 766 | * @public | 766 | _self.Prism = _; |
| 767 | */ | 767 | |
| 768 | run: function (name, env) { | 768 | |
| 769 | var callbacks = _.hooks.all[name]; | 769 | // Typescript note: |
| 770 | | 770 | // The following can be used to import the Token type in JSDoc: |
| 771 | if (!callbacks || !callbacks.length) { | 771 | // |
| 772 | return; | 772 | // @typedef {InstanceType<import("./prism-core")["Token"]>} Token |
| 773 | } | 773 | |
| 774 | | 774 | /** |
| 775 | for (var i = 0, callback; (callback = callbacks[i++]); ) { | 775 | * Creates a new token. |
| 776 | callback(env); | 776 | * |
| 777 | } | 777 | * @param {string} type See {@link Token#type type} |
| 778 | }, | 778 | * @param {string | TokenStream} content See {@link Token#content content} |
| 779 | }, | 779 | * @param {string|string[]} [alias] The alias(es) of the token. |
| 780 | | 780 | * @param {string} [matchedStr=""] A copy of the full string this token was created from. |
| 781 | Token: Token, | 781 | * @class |
| 782 | }; | 782 | * @global |
| 783 | _self.Prism = _; | 783 | * @public |
| 784 | | 784 | */ |
| 785 | // Typescript note: | 785 | function Token(type, content, alias, matchedStr) { |
| 786 | // The following can be used to import the Token type in JSDoc: | 786 | /** |
| 787 | // | 787 | * The type of the token. |
| 788 | // @typedef {InstanceType<import("./prism-core")["Token"]>} Token | 788 | * |
| 789 | | 789 | * This is usually the key of a pattern in a {@link Grammar}. |
| 790 | /** | 790 | * |
| 791 | * Creates a new token. | 791 | * @type {string} |
| 792 | * | 792 | * @see GrammarToken |
| 793 | * @param {string} type See {@link Token#type type} | 793 | * @public |
| 794 | * @param {string | TokenStream} content See {@link Token#content content} | 794 | */ |
| 795 | * @param {string|string[]} [alias] The alias(es) of the token. | 795 | this.type = type; |
| 796 | * @param {string} [matchedStr=""] A copy of the full string this token was created from. | 796 | /** |
| 797 | * @class | 797 | * The strings or tokens contained by this token. |
| 798 | * @global | 798 | * |
| 799 | * @public | 799 | * This will be a token stream if the pattern matched also defined an `inside` grammar. |
| 800 | */ | 800 | * |
| 801 | function Token(type, content, alias, matchedStr) { | 801 | * @type {string | TokenStream} |
| 802 | /** | 802 | * @public |
| 803 | * The type of the token. | 803 | */ |
| 804 | * | 804 | this.content = content; |
| 805 | * This is usually the key of a pattern in a {@link Grammar}. | 805 | /** |
| 806 | * | 806 | * The alias(es) of the token. |
| 807 | * @type {string} | 807 | * |
| 808 | * @see GrammarToken | 808 | * @type {string|string[]} |
| 809 | * @public | 809 | * @see GrammarToken |
| 810 | */ | 810 | * @public |
| 811 | this.type = type; | 811 | */ |
| 812 | /** | 812 | this.alias = alias; |
| 813 | * The strings or tokens contained by this token. | 813 | // Copy of the full string this token was created from |
| 814 | * | 814 | this.length = (matchedStr || '').length | 0; |
| 815 | * This will be a token stream if the pattern matched also defined an `inside` grammar. | 815 | } |
| 816 | * | 816 | |
| 817 | * @type {string | TokenStream} | 817 | /** |
| 818 | * @public | 818 | * A token stream is an array of strings and {@link Token Token} objects. |
| 819 | */ | 819 | * |
| 820 | this.content = content; | 820 | * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process |
| 821 | /** | 821 | * them. |
| 822 | * The alias(es) of the token. | 822 | * |
| 823 | * | 823 | * 1. No adjacent strings. |
| 824 | * @type {string|string[]} | 824 | * 2. No empty strings. |
| 825 | * @see GrammarToken | 825 | * |
| 826 | * @public | 826 | * The only exception here is the token stream that only contains the empty string and nothing else. |
| 827 | */ | 827 | * |
| 828 | this.alias = alias; | 828 | * @typedef {Array<string | Token>} TokenStream |
| 829 | // Copy of the full string this token was created from | 829 | * @global |
| 830 | this.length = (matchedStr || "").length | 0; | 830 | * @public |
| 831 | } | 831 | */ |
| 832 | | 832 | |
| 833 | /** | 833 | /** |
| 834 | * A token stream is an array of strings and {@link Token Token} objects. | 834 | * Converts the given token or token stream to an HTML representation. |
| 835 | * | 835 | * |
| 836 | * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process | 836 | * The following hooks will be run: |
| 837 | * them. | 837 | * 1. `wrap`: On each {@link Token}. |
| 838 | * | 838 | * |
| 839 | * 1. No adjacent strings. | 839 | * @param {string | Token | TokenStream} o The token or token stream to be converted. |
| 840 | * 2. No empty strings. | 840 | * @param {string} language The name of current language. |
| 841 | * | 841 | * @returns {string} The HTML representation of the token or token stream. |
| 842 | * The only exception here is the token stream that only contains the empty string and nothing else. | 842 | * @memberof Token |
| 843 | * | 843 | * @static |
| 844 | * @typedef {Array<string | Token>} TokenStream | 844 | */ |
| 845 | * @global | 845 | Token.stringify = function stringify(o, language) { |
| 846 | * @public | 846 | if (typeof o == 'string') { |
| 847 | */ | 847 | return o; |
| 848 | | 848 | } |
| 849 | /** | 849 | if (Array.isArray(o)) { |
| 850 | * Converts the given token or token stream to an HTML representation. | 850 | var s = ''; |
| 851 | * | 851 | o.forEach(function (e) { |
| 852 | * The following hooks will be run: | 852 | s += stringify(e, language); |
| 853 | * 1. `wrap`: On each {@link Token}. | 853 | }); |
| 854 | * | 854 | return s; |
| 855 | * @param {string | Token | TokenStream} o The token or token stream to be converted. | 855 | } |
| 856 | * @param {string} language The name of current language. | 856 | |
| 857 | * @returns {string} The HTML representation of the token or token stream. | 857 | var env = { |
| 858 | * @memberof Token | 858 | type: o.type, |
| 859 | * @static | 859 | content: stringify(o.content, language), |
| 860 | */ | 860 | tag: 'span', |
| 861 | Token.stringify = function stringify(o, language) { | 861 | classes: ['token', o.type], |
| 862 | if (typeof o == "string") { | 862 | attributes: {}, |
| 863 | return o; | 863 | language: language |
| 864 | } | 864 | }; |
| 865 | if (Array.isArray(o)) { | 865 | |
| 866 | var s = ""; | 866 | var aliases = o.alias; |
| 867 | o.forEach(function (e) { | 867 | if (aliases) { |
| 868 | s += stringify(e, language); | 868 | if (Array.isArray(aliases)) { |
| 869 | }); | 869 | Array.prototype.push.apply(env.classes, aliases); |
| 870 | return s; | 870 | } else { |
| 871 | } | 871 | env.classes.push(aliases); |
| 872 | | 872 | } |
| 873 | var env = { | 873 | } |
| 874 | type: o.type, | 874 | |
| 875 | content: stringify(o.content, language), | 875 | _.hooks.run('wrap', env); |
| 876 | tag: "span", | 876 | |
| 877 | classes: ["token", o.type], | 877 | var attributes = ''; |
| 878 | attributes: {}, | 878 | for (var name in env.attributes) { |
| 879 | language: language, | 879 | attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; |
| 880 | }; | 880 | } |
| 881 | | 881 | |
| 882 | var aliases = o.alias; | 882 | return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>'; |
| 883 | if (aliases) { | 883 | }; |
| 884 | if (Array.isArray(aliases)) { | 884 | |
| 885 | Array.prototype.push.apply(env.classes, aliases); | 885 | /** |
| 886 | } else { | 886 | * @param {RegExp} pattern |
| 887 | env.classes.push(aliases); | 887 | * @param {number} pos |
| 888 | } | 888 | * @param {string} text |
| 889 | } | 889 | * @param {boolean} lookbehind |
| 890 | | 890 | * @returns {RegExpExecArray | null} |
| 891 | _.hooks.run("wrap", env); | 891 | */ |
| 892 | | 892 | function matchPattern(pattern, pos, text, lookbehind) { |
| 893 | var attributes = ""; | 893 | pattern.lastIndex = pos; |
| 894 | for (var name in env.attributes) { | 894 | var match = pattern.exec(text); |
| 895 | attributes += | 895 | if (match && lookbehind && match[1]) { |
| 896 | " " + | 896 | // change the match to remove the text matched by the Prism lookbehind group |
| 897 | name + | 897 | var lookbehindLength = match[1].length; |
| 898 | '="' + | 898 | match.index += lookbehindLength; |
| 899 | (env.attributes[name] || "").replace(/"/g, """) + | 899 | match[0] = match[0].slice(lookbehindLength); |
| 900 | '"'; | 900 | } |
| 901 | } | 901 | return match; |
| 902 | | 902 | } |
| 903 | return ( | 903 | |
| 904 | "<" + | 904 | /** |
| 905 | env.tag + | 905 | * @param {string} text |
| 906 | ' class="' + | 906 | * @param {LinkedList<string | Token>} tokenList |
| 907 | env.classes.join(" ") + | 907 | * @param {any} grammar |
| 908 | '"' + | 908 | * @param {LinkedListNode<string | Token>} startNode |
| 909 | attributes + | 909 | * @param {number} startPos |
| 910 | ">" + | 910 | * @param {RematchOptions} [rematch] |
| 911 | env.content + | 911 | * @returns {void} |
| 912 | "</" + | 912 | * @private |
| 913 | env.tag + | 913 | * |
| 914 | ">" | 914 | * @typedef RematchOptions |
| 915 | ); | 915 | * @property {string} cause |
| 916 | }; | 916 | * @property {number} reach |
| 917 | | 917 | */ |
| 918 | /** | 918 | function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) { |
| 919 | * @param {RegExp} pattern | 919 | for (var token in grammar) { |
| 920 | * @param {number} pos | 920 | if (!grammar.hasOwnProperty(token) || !grammar[token]) { |
| 921 | * @param {string} text | 921 | continue; |
| 922 | * @param {boolean} lookbehind | 922 | } |
| 923 | * @returns {RegExpExecArray | null} | 923 | |
| 924 | */ | 924 | var patterns = grammar[token]; |
| 925 | function matchPattern(pattern, pos, text, lookbehind) { | 925 | patterns = Array.isArray(patterns) ? patterns : [patterns]; |
| 926 | pattern.lastIndex = pos; | 926 | |
| 927 | var match = pattern.exec(text); | 927 | for (var j = 0; j < patterns.length; ++j) { |
| 928 | if (match && lookbehind && match[1]) { | 928 | if (rematch && rematch.cause == token + ',' + j) { |
| 929 | // change the match to remove the text matched by the Prism lookbehind group | 929 | return; |
| 930 | var lookbehindLength = match[1].length; | 930 | } |
| 931 | match.index += lookbehindLength; | 931 | |
| 932 | match[0] = match[0].slice(lookbehindLength); | 932 | var patternObj = patterns[j]; |
| 933 | } | 933 | var inside = patternObj.inside; |
| 934 | return match; | 934 | var lookbehind = !!patternObj.lookbehind; |
| 935 | } | 935 | var greedy = !!patternObj.greedy; |
| 936 | | 936 | var alias = patternObj.alias; |
| 937 | /** | 937 | |
| 938 | * @param {string} text | 938 | if (greedy && !patternObj.pattern.global) { |
| 939 | * @param {LinkedList<string | Token>} tokenList | 939 | // Without the global flag, lastIndex won't work |
| 940 | * @param {any} grammar | 940 | var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0]; |
| 941 | * @param {LinkedListNode<string | Token>} startNode | 941 | patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g'); |
| 942 | * @param {number} startPos | 942 | } |
| 943 | * @param {RematchOptions} [rematch] | 943 | |
| 944 | * @returns {void} | 944 | /** @type {RegExp} */ |
| 945 | * @private | 945 | var pattern = patternObj.pattern || patternObj; |
| 946 | * | 946 | |
| 947 | * @typedef RematchOptions | 947 | for ( // iterate the token list and keep track of the current token/string position |
| 948 | * @property {string} cause | 948 | var currentNode = startNode.next, pos = startPos; |
| 949 | * @property {number} reach | 949 | currentNode !== tokenList.tail; |
| 950 | */ | 950 | pos += currentNode.value.length, currentNode = currentNode.next |
| 951 | function matchGrammar( | 951 | ) { |
| 952 | text, | 952 | |
| 953 | tokenList, | 953 | if (rematch && pos >= rematch.reach) { |
| 954 | grammar, | 954 | break; |
| 955 | startNode, | 955 | } |
| 956 | startPos, | 956 | |
| 957 | rematch, | 957 | var str = currentNode.value; |
| 958 | ) { | 958 | |
| 959 | for (var token in grammar) { | 959 | if (tokenList.length > text.length) { |
| 960 | if (!grammar.hasOwnProperty(token) || !grammar[token]) { | 960 | // Something went terribly wrong, ABORT, ABORT! |
| 961 | continue; | 961 | return; |
| 962 | } | 962 | } |
| 963 | | 963 | |
| 964 | var patterns = grammar[token]; | 964 | if (str instanceof Token) { |
| 965 | patterns = Array.isArray(patterns) ? patterns : [patterns]; | 965 | continue; |
| 966 | | 966 | } |
| 967 | for (var j = 0; j < patterns.length; ++j) { | 967 | |
| 968 | if (rematch && rematch.cause == token + "," + j) { | 968 | var removeCount = 1; // this is the to parameter of removeBetween |
| 969 | return; | 969 | var match; |
| 970 | } | 970 | |
| 971 | | 971 | if (greedy) { |
| 972 | var patternObj = patterns[j]; | 972 | match = matchPattern(pattern, pos, text, lookbehind); |
| 973 | var inside = patternObj.inside; | 973 | if (!match || match.index >= text.length) { |
| 974 | var lookbehind = !!patternObj.lookbehind; | 974 | break; |
| 975 | var greedy = !!patternObj.greedy; | 975 | } |
| 976 | var alias = patternObj.alias; | 976 | |
| 977 | | 977 | var from = match.index; |
| 978 | if (greedy && !patternObj.pattern.global) { | 978 | var to = match.index + match[0].length; |
| 979 | // Without the global flag, lastIndex won't work | 979 | var p = pos; |
| 980 | var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0]; | 980 | |
| 981 | patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g"); | 981 | // find the node that contains the match |
| 982 | } | 982 | p += currentNode.value.length; |
| 983 | | 983 | while (from >= p) { |
| 984 | /** @type {RegExp} */ | 984 | currentNode = currentNode.next; |
| 985 | var pattern = patternObj.pattern || patternObj; | 985 | p += currentNode.value.length; |
| 986 | | 986 | } |
| 987 | for ( | 987 | // adjust pos (and p) |
| 988 | // iterate the token list and keep track of the current token/string position | 988 | p -= currentNode.value.length; |
| 989 | var currentNode = startNode.next, pos = startPos; | 989 | pos = p; |
| 990 | currentNode !== tokenList.tail; | 990 | |
| 991 | pos += currentNode.value.length, currentNode = currentNode.next | 991 | // the current node is a Token, then the match starts inside another Token, which is invalid |
| 992 | ) { | 992 | if (currentNode.value instanceof Token) { |
| 993 | if (rematch && pos >= rematch.reach) { | 993 | continue; |
| 994 | break; | 994 | } |
| 995 | } | 995 | |
| 996 | | 996 | // find the last node which is affected by this match |
| 997 | var str = currentNode.value; | 997 | for ( |
| 998 | | 998 | var k = currentNode; |
| 999 | if (tokenList.length > text.length) { | 999 | k !== tokenList.tail && (p < to || typeof k.value === 'string'); |
| 1000 | // Something went terribly wrong, ABORT, ABORT! | 1000 | k = k.next |
| 1001 | return; | 1001 | ) { |
| 1002 | } | 1002 | removeCount++; |
| 1003 | | 1003 | p += k.value.length; |
| 1004 | if (str instanceof Token) { | 1004 | } |
| 1005 | continue; | 1005 | removeCount--; |
| 1006 | } | 1006 | |
| 1007 | | 1007 | // replace with the new match |
| 1008 | var removeCount = 1; // this is the to parameter of removeBetween | 1008 | str = text.slice(pos, p); |
| 1009 | var match; | 1009 | match.index -= pos; |
| 1010 | | 1010 | } else { |
| 1011 | if (greedy) { | 1011 | match = matchPattern(pattern, 0, str, lookbehind); |
| 1012 | match = matchPattern(pattern, pos, text, lookbehind); | 1012 | if (!match) { |
| 1013 | if (!match || match.index >= text.length) { | 1013 | continue; |
| 1014 | break; | 1014 | } |
| 1015 | } | 1015 | } |
| 1016 | | 1016 | |
| 1017 | var from = match.index; | 1017 | // eslint-disable-next-line no-redeclare |
| 1018 | var to = match.index + match[0].length; | 1018 | var from = match.index; |
| 1019 | var p = pos; | 1019 | var matchStr = match[0]; |
| 1020 | | 1020 | var before = str.slice(0, from); |
| 1021 | // find the node that contains the match | 1021 | var after = str.slice(from + matchStr.length); |
| 1022 | p += currentNode.value.length; | 1022 | |
| 1023 | while (from >= p) { | 1023 | var reach = pos + str.length; |
| 1024 | currentNode = currentNode.next; | 1024 | if (rematch && reach > rematch.reach) { |
| 1025 | p += currentNode.value.length; | 1025 | rematch.reach = reach; |
| 1026 | } | 1026 | } |
| 1027 | // adjust pos (and p) | 1027 | |
| 1028 | p -= currentNode.value.length; | 1028 | var removeFrom = currentNode.prev; |
| 1029 | pos = p; | 1029 | |
| 1030 | | 1030 | if (before) { |
| 1031 | // the current node is a Token, then the match starts inside another Token, which is invalid | 1031 | removeFrom = addAfter(tokenList, removeFrom, before); |
| 1032 | if (currentNode.value instanceof Token) { | 1032 | pos += before.length; |
| 1033 | continue; | 1033 | } |
| 1034 | } | 1034 | |
| 1035 | | 1035 | removeRange(tokenList, removeFrom, removeCount); |
| 1036 | // find the last node which is affected by this match | 1036 | |
| 1037 | for ( | 1037 | var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr); |
| 1038 | var k = currentNode; | 1038 | currentNode = addAfter(tokenList, removeFrom, wrapped); |
| 1039 | k !== tokenList.tail && (p < to || typeof k.value === "string"); | 1039 | |
| 1040 | k = k.next | 1040 | if (after) { |
| 1041 | ) { | 1041 | addAfter(tokenList, currentNode, after); |
| 1042 | removeCount++; | 1042 | } |
| 1043 | p += k.value.length; | 1043 | |
| 1044 | } | 1044 | if (removeCount > 1) { |
| 1045 | removeCount--; | 1045 | // at least one Token object was removed, so we have to do some rematching |
| 1046 | | 1046 | // this can only happen if the current pattern is greedy |
| 1047 | // replace with the new match | 1047 | |
| 1048 | str = text.slice(pos, p); | 1048 | /** @type {RematchOptions} */ |
| 1049 | match.index -= pos; | 1049 | var nestedRematch = { |
| 1050 | } else { | 1050 | cause: token + ',' + j, |
| 1051 | match = matchPattern(pattern, 0, str, lookbehind); | 1051 | reach: reach |
| 1052 | if (!match) { | 1052 | }; |
| 1053 | continue; | 1053 | matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch); |
| 1054 | } | 1054 | |
| 1055 | } | 1055 | // the reach might have been extended because of the rematching |
| 1056 | | 1056 | if (rematch && nestedRematch.reach > rematch.reach) { |
| 1057 | // eslint-disable-next-line no-redeclare | 1057 | rematch.reach = nestedRematch.reach; |
| 1058 | var from = match.index; | 1058 | } |
| 1059 | var matchStr = match[0]; | 1059 | } |
| 1060 | var before = str.slice(0, from); | 1060 | } |
| 1061 | var after = str.slice(from + matchStr.length); | 1061 | } |
| 1062 | | 1062 | } |
| 1063 | var reach = pos + str.length; | 1063 | } |
| 1064 | if (rematch && reach > rematch.reach) { | 1064 | |
| 1065 | rematch.reach = reach; | 1065 | /** |
| 1066 | } | 1066 | * @typedef LinkedListNode |
| 1067 | | 1067 | * @property {T} value |
| 1068 | var removeFrom = currentNode.prev; | 1068 | * @property {LinkedListNode<T> | null} prev The previous node. |
| 1069 | | 1069 | * @property {LinkedListNode<T> | null} next The next node. |
| 1070 | if (before) { | 1070 | * @template T |
| 1071 | removeFrom = addAfter(tokenList, removeFrom, before); | 1071 | * @private |
| 1072 | pos += before.length; | 1072 | */ |
| 1073 | } | 1073 | |
| 1074 | | 1074 | /** |
| 1075 | removeRange(tokenList, removeFrom, removeCount); | 1075 | * @template T |
| 1076 | | 1076 | * @private |
| 1077 | var wrapped = new Token( | 1077 | */ |
| 1078 | token, | 1078 | function LinkedList() { |
| 1079 | inside ? _.tokenize(matchStr, inside) : matchStr, | 1079 | /** @type {LinkedListNode<T>} */ |
| 1080 | alias, | 1080 | var head = { value: null, prev: null, next: null }; |
| 1081 | matchStr, | 1081 | /** @type {LinkedListNode<T>} */ |
| 1082 | ); | 1082 | var tail = { value: null, prev: head, next: null }; |
| 1083 | currentNode = addAfter(tokenList, removeFrom, wrapped); | 1083 | head.next = tail; |
| 1084 | | 1084 | |
| 1085 | if (after) { | 1085 | /** @type {LinkedListNode<T>} */ |
| 1086 | addAfter(tokenList, currentNode, after); | 1086 | this.head = head; |
| 1087 | } | 1087 | /** @type {LinkedListNode<T>} */ |
| 1088 | | 1088 | this.tail = tail; |
| 1089 | if (removeCount > 1) { | 1089 | this.length = 0; |
| 1090 | // at least one Token object was removed, so we have to do some rematching | 1090 | } |
| 1091 | // this can only happen if the current pattern is greedy | 1091 | |
| 1092 | | 1092 | /** |
| 1093 | /** @type {RematchOptions} */ | 1093 | * Adds a new node with the given value to the list. |
| 1094 | var nestedRematch = { | 1094 | * |
| 1095 | cause: token + "," + j, | 1095 | * @param {LinkedList<T>} list |
| 1096 | reach: reach, | 1096 | * @param {LinkedListNode<T>} node |
| 1097 | }; | 1097 | * @param {T} value |
| 1098 | matchGrammar( | 1098 | * @returns {LinkedListNode<T>} The added node. |
| 1099 | text, | 1099 | * @template T |
| 1100 | tokenList, | 1100 | */ |
| 1101 | grammar, | 1101 | function addAfter(list, node, value) { |
| 1102 | currentNode.prev, | 1102 | // assumes that node != list.tail && values.length >= 0 |
| 1103 | pos, | 1103 | var next = node.next; |
| 1104 | nestedRematch, | 1104 | |
| 1105 | ); | 1105 | var newNode = { value: value, prev: node, next: next }; |
| 1106 | | 1106 | node.next = newNode; |
| 1107 | // the reach might have been extended because of the rematching | 1107 | next.prev = newNode; |
| 1108 | if (rematch && nestedRematch.reach > rematch.reach) { | 1108 | list.length++; |
| 1109 | rematch.reach = nestedRematch.reach; | 1109 | |
| 1110 | } | 1110 | return newNode; |
| 1111 | } | 1111 | } |
| 1112 | } | 1112 | /** |
| 1113 | } | 1113 | * Removes `count` nodes after the given node. The given node will not be removed. |
| 1114 | } | 1114 | * |
| 1115 | } | 1115 | * @param {LinkedList<T>} list |
| 1116 | | 1116 | * @param {LinkedListNode<T>} node |
| 1117 | /** | 1117 | * @param {number} count |
| 1118 | * @typedef LinkedListNode | 1118 | * @template T |
| 1119 | * @property {T} value | 1119 | */ |
| 1120 | * @property {LinkedListNode<T> | null} prev The previous node. | 1120 | function removeRange(list, node, count) { |
| 1121 | * @property {LinkedListNode<T> | null} next The next node. | 1121 | var next = node.next; |
| 1122 | * @template T | 1122 | for (var i = 0; i < count && next !== list.tail; i++) { |
| 1123 | * @private | 1123 | next = next.next; |
| 1124 | */ | 1124 | } |
| 1125 | | 1125 | node.next = next; |
| 1126 | /** | 1126 | next.prev = node; |
| 1127 | * @template T | 1127 | list.length -= i; |
| 1128 | * @private | 1128 | } |
| 1129 | */ | 1129 | /** |
| 1130 | function LinkedList() { | 1130 | * @param {LinkedList<T>} list |
| 1131 | /** @type {LinkedListNode<T>} */ | 1131 | * @returns {T[]} |
| 1132 | var head = { value: null, prev: null, next: null }; | 1132 | * @template T |
| 1133 | /** @type {LinkedListNode<T>} */ | 1133 | */ |
| 1134 | var tail = { value: null, prev: head, next: null }; | 1134 | function toArray(list) { |
| 1135 | head.next = tail; | 1135 | var array = []; |
| 1136 | | 1136 | var node = list.head.next; |
| 1137 | /** @type {LinkedListNode<T>} */ | 1137 | while (node !== list.tail) { |
| 1138 | this.head = head; | 1138 | array.push(node.value); |
| 1139 | /** @type {LinkedListNode<T>} */ | 1139 | node = node.next; |
| 1140 | this.tail = tail; | 1140 | } |
| 1141 | this.length = 0; | 1141 | return array; |
| 1142 | } | 1142 | } |
| 1143 | | 1143 | |
| 1144 | /** | 1144 | |
| 1145 | * Adds a new node with the given value to the list. | 1145 | if (!_self.document) { |
| 1146 | * | 1146 | if (!_self.addEventListener) { |
| 1147 | * @param {LinkedList<T>} list | 1147 | // in Node.js |
| 1148 | * @param {LinkedListNode<T>} node | 1148 | return _; |
| 1149 | * @param {T} value | 1149 | } |
| 1150 | * @returns {LinkedListNode<T>} The added node. | 1150 | |
| 1151 | * @template T | 1151 | if (!_.disableWorkerMessageHandler) { |
| 1152 | */ | 1152 | // In worker |
| 1153 | function addAfter(list, node, value) { | 1153 | _self.addEventListener('message', function (evt) { |
| 1154 | // assumes that node != list.tail && values.length >= 0 | 1154 | var message = JSON.parse(evt.data); |
| 1155 | var next = node.next; | 1155 | var lang = message.language; |
| 1156 | | 1156 | var code = message.code; |
| 1157 | var newNode = { value: value, prev: node, next: next }; | 1157 | var immediateClose = message.immediateClose; |
| 1158 | node.next = newNode; | 1158 | |
| 1159 | next.prev = newNode; | 1159 | _self.postMessage(_.highlight(code, _.languages[lang], lang)); |
| 1160 | list.length++; | 1160 | if (immediateClose) { |
| 1161 | | 1161 | _self.close(); |
| 1162 | return newNode; | 1162 | } |
| 1163 | } | 1163 | }, false); |
| 1164 | /** | 1164 | } |
| 1165 | * Removes `count` nodes after the given node. The given node will not be removed. | 1165 | |
| 1166 | * | 1166 | return _; |
| 1167 | * @param {LinkedList<T>} list | 1167 | } |
| 1168 | * @param {LinkedListNode<T>} node | 1168 | |
| 1169 | * @param {number} count | 1169 | // Get current script and highlight |
| 1170 | * @template T | 1170 | var script = _.util.currentScript(); |
| 1171 | */ | 1171 | |
| 1172 | function removeRange(list, node, count) { | 1172 | if (script) { |
| 1173 | var next = node.next; | 1173 | _.filename = script.src; |
| 1174 | for (var i = 0; i < count && next !== list.tail; i++) { | 1174 | |
| 1175 | next = next.next; | 1175 | if (script.hasAttribute('data-manual')) { |
| 1176 | } | 1176 | _.manual = true; |
| 1177 | node.next = next; | 1177 | } |
| 1178 | next.prev = node; | 1178 | } |
| 1179 | list.length -= i; | 1179 | |
| 1180 | } | 1180 | function highlightAutomaticallyCallback() { |
| 1181 | /** | 1181 | if (!_.manual) { |
| 1182 | * @param {LinkedList<T>} list | 1182 | _.highlightAll(); |
| 1183 | * @returns {T[]} | 1183 | } |
| 1184 | * @template T | 1184 | } |
| 1185 | */ | 1185 | |
| 1186 | function toArray(list) { | 1186 | if (!_.manual) { |
| 1187 | var array = []; | 1187 | // If the document state is "loading", then we'll use DOMContentLoaded. |
| 1188 | var node = list.head.next; | 1188 | // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the |
| 1189 | while (node !== list.tail) { | 1189 | // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they |
| 1190 | array.push(node.value); | 1190 | // might take longer one animation frame to execute which can create a race condition where only some plugins have |
| 1191 | node = node.next; | 1191 | // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded. |
| 1192 | } | 1192 | // See https://github.com/PrismJS/prism/issues/2102 |
| 1193 | return array; | 1193 | var readyState = document.readyState; |
| 1194 | } | 1194 | if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) { |
| 1195 | | 1195 | document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback); |
| 1196 | if (!_self.document) { | 1196 | } else { |
| 1197 | if (!_self.addEventListener) { | 1197 | if (window.requestAnimationFrame) { |
| 1198 | // in Node.js | 1198 | window.requestAnimationFrame(highlightAutomaticallyCallback); |
| 1199 | return _; | 1199 | } else { |
| 1200 | } | 1200 | window.setTimeout(highlightAutomaticallyCallback, 16); |
| 1201 | | 1201 | } |
| 1202 | if (!_.disableWorkerMessageHandler) { | 1202 | } |
| 1203 | // In worker | 1203 | } |
| 1204 | _self.addEventListener( | 1204 | |
| 1205 | "message", | 1205 | return _; |
| 1206 | function (evt) { | 1206 | |
| 1207 | var message = JSON.parse(evt.data); | 1207 | }(_self)); |
| 1208 | var lang = message.language; | 1208 | |
| 1209 | var code = message.code; | 1209 | if (typeof module !== 'undefined' && module.exports) { |
| 1210 | var immediateClose = message.immediateClose; | 1210 | module.exports = Prism; |
| 1211 | | | |
| 1212 | _self.postMessage(_.highlight(code, _.languages[lang], lang)); | | |
| 1213 | if (immediateClose) { | | |
| 1214 | _self.close(); | | |
| 1215 | } | | |
| 1216 | }, | | |
| 1217 | false, | | |
| 1218 | ); | | |
| 1219 | } | | |
| 1220 | | | |
| 1221 | return _; | | |
| 1222 | } | | |
| 1223 | | | |
| 1224 | // Get current script and highlight | | |
| 1225 | var script = _.util.currentScript(); | | |
| 1226 | | | |
| 1227 | if (script) { | | |
| 1228 | _.filename = script.src; | | |
| 1229 | | | |
| 1230 | if (script.hasAttribute("data-manual")) { | | |
| 1231 | _.manual = true; | | |
| 1232 | } | | |
| 1233 | } | | |
| 1234 | | | |
| 1235 | function highlightAutomaticallyCallback() { | | |
| 1236 | if (!_.manual) { | | |
| 1237 | _.highlightAll(); | | |
| 1238 | } | | |
| 1239 | } | | |
| 1240 | | | |
| 1241 | if (!_.manual) { | | |
| 1242 | // If the document state is "loading", then we'll use DOMContentLoaded. | | |
| 1243 | // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the | | |
| 1244 | // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they | | |
| 1245 | // might take longer one animation frame to execute which can create a race condition where only some plugins have | | |
| 1246 | // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded. | | |
| 1247 | // See https://github.com/PrismJS/prism/issues/2102 | | |
| 1248 | var readyState = document.readyState; | | |
| 1249 | if ( | | |
| 1250 | readyState === "loading" || | | |
| 1251 | (readyState === "interactive" && script && script.defer) | | |
| 1252 | ) { | | |
| 1253 | document.addEventListener( | | |
| 1254 | "DOMContentLoaded", | | |
| 1255 | highlightAutomaticallyCallback, | | |
| 1256 | ); | | |
| 1257 | } else { | | |
| 1258 | if (requestAnimationFrame) { | | |
| 1259 | requestAnimationFrame(highlightAutomaticallyCallback); | | |
| 1260 | } else { | | |
| 1261 | window.setTimeout(highlightAutomaticallyCallback, 16); | | |
| 1262 | } | | |
| 1263 | } | | |
| 1264 | } | | |
| 1265 | | | |
| 1266 | return _; | | |
| 1267 | })(_self); | | |
| 1268 | | | |
| 1269 | if (typeof module !== "undefined" && module.exports) { | | |
| 1270 | module.exports = Prism; | | |
| 1271 | } | 1211 | } |
| 1272 | | 1212 | |
| 1273 | // hack for components to work correctly in node.js | 1213 | // hack for components to work correctly in node.js |
| 1274 | if (typeof global !== "undefined") { | 1214 | if (typeof global !== 'undefined') { |
| 1275 | global.Prism = Prism; | 1215 | global.Prism = Prism; |
| 1276 | } | 1216 | } |
| 1277 | | 1217 | |
| 1278 | // some additional documentation/types | 1218 | // some additional documentation/types |
| @@ -1323,1096 +1263,1007 @@ if (typeof global !== "undefined") { · 44 unmodified lines |
| 1323 | * @global | 1263 | * @global |
| 1324 | * @public | 1264 | * @public |
| 1325 | */ | 1265 | */ |
| | 1266 | ; |
| 1326 | Prism.languages.markup = { | 1267 | Prism.languages.markup = { |
| 1327 | comment: { | 1268 | 'comment': { |
| 1328 | pattern: /<!--(?:(?!<!--)[\s\S])*?-->/, | 1269 | pattern: /<!--(?:(?!<!--)[\s\S])*?-->/, |
| 1329 | greedy: true, | 1270 | greedy: true |
| 1330 | }, | 1271 | }, |
| 1331 | prolog: { | 1272 | 'prolog': { |
| 1332 | pattern: /<\?[\s\S]+?\?>/, | 1273 | pattern: /<\?[\s\S]+?\?>/, |
| 1333 | greedy: true, | 1274 | greedy: true |
| 1334 | }, | 1275 | }, |
| 1335 | doctype: { | 1276 | 'doctype': { |
| 1336 | // https://www.w3.org/TR/xml/#NT-doctypedecl | 1277 | // https://www.w3.org/TR/xml/#NT-doctypedecl |
| 1337 | pattern: | 1278 | pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i, |
| 1338 | /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i, | 1279 | greedy: true, |
| 1339 | greedy: true, | 1280 | inside: { |
| 1340 | inside: { | 1281 | 'internal-subset': { |
| 1341 | "internal-subset": { | 1282 | pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/, |
| 1342 | pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/, | 1283 | lookbehind: true, |
| 1343 | lookbehind: true, | 1284 | greedy: true, |
| 1344 | greedy: true, | 1285 | inside: null // see below |
| 1345 | inside: null, // see below | 1286 | }, |
| 1346 | }, | 1287 | 'string': { |
| 1347 | string: { | 1288 | pattern: /"[^"]*"|'[^']*'/, |
| 1348 | pattern: /"[^"]*"|'[^']*'/, | 1289 | greedy: true |
| 1349 | greedy: true, | 1290 | }, |
| 1350 | }, | 1291 | 'punctuation': /^<!|>$|[[\]]/, |
| 1351 | punctuation: /^<!|>$|[[\]]/, | 1292 | 'doctype-tag': /^DOCTYPE/i, |
| 1352 | "doctype-tag": /^DOCTYPE/i, | 1293 | 'name': /[^\s<>'"]+/ |
| 1353 | name: /[^\s<>'"]+/, | 1294 | } |
| 1354 | }, | 1295 | }, |
| 1355 | }, | 1296 | 'cdata': { |
| 1356 | cdata: { | 1297 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, |
| 1357 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, | 1298 | greedy: true |
| 1358 | greedy: true, | 1299 | }, |
| 1359 | }, | 1300 | 'tag': { |
| 1360 | tag: { | 1301 | pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/, |
| 1361 | pattern: | 1302 | greedy: true, |
| 1362 | /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/, | 1303 | inside: { |
| 1363 | greedy: true, | 1304 | 'tag': { |
| 1364 | inside: { | 1305 | pattern: /^<\/?[^\s>\/]+/, |
| 1365 | tag: { | 1306 | inside: { |
| 1366 | pattern: /^<\/?[^\s>\/]+/, | 1307 | 'punctuation': /^<\/?/, |
| 1367 | inside: { | 1308 | 'namespace': /^[^\s>\/:]+:/ |
| 1368 | punctuation: /^<\/?/, | 1309 | } |
| 1369 | namespace: /^[^\s>\/:]+:/, | 1310 | }, |
| 1370 | }, | 1311 | 'special-attr': [], |
| 1371 | }, | 1312 | 'attr-value': { |
| 1372 | "special-attr": [], | 1313 | pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/, |
| 1373 | "attr-value": { | 1314 | inside: { |
| 1374 | pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/, | 1315 | 'punctuation': [ |
| 1375 | inside: { | 1316 | { |
| 1376 | punctuation: [ | 1317 | pattern: /^=/, |
| 1377 | { | 1318 | alias: 'attr-equals' |
| 1378 | pattern: /^=/, | 1319 | }, |
| 1379 | alias: "attr-equals", | 1320 | { |
| 1380 | }, | 1321 | pattern: /^(\s*)["']|["']$/, |
| 1381 | { | 1322 | lookbehind: true |
| 1382 | pattern: /^(\s*)["']|["']$/, | 1323 | } |
| 1383 | lookbehind: true, | 1324 | ] |
| 1384 | }, | 1325 | } |
| 1385 | ], | 1326 | }, |
| 1386 | }, | 1327 | 'punctuation': /\/?>/, |
| 1387 | }, | 1328 | 'attr-name': { |
| 1388 | punctuation: /\/?>/, | 1329 | pattern: /[^\s>\/]+/, |
| 1389 | "attr-name": { | 1330 | inside: { |
| 1390 | pattern: /[^\s>\/]+/, | 1331 | 'namespace': /^[^\s>\/:]+:/ |
| 1391 | inside: { | 1332 | } |
| 1392 | namespace: /^[^\s>\/:]+:/, | 1333 | } |
| 1393 | }, | 1334 | |
| 1394 | }, | 1335 | } |
| 1395 | }, | 1336 | }, |
| 1396 | }, | 1337 | 'entity': [ |
| 1397 | entity: [ | 1338 | { |
| 1398 | { | 1339 | pattern: /&[\da-z]{1,8};/i, |
| 1399 | pattern: /&[\da-z]{1,8};/i, | 1340 | alias: 'named-entity' |
| 1400 | alias: "named-entity", | 1341 | }, |
| 1401 | }, | 1342 | /&#x?[\da-f]{1,8};/i |
| 1402 | /&#x?[\da-f]{1,8};/i, | 1343 | ] |
| 1403 | ], | | |
| 1404 | }; | 1344 | }; |
| 1405 | | 1345 | |
| 1406 | Prism.languages.markup["tag"].inside["attr-value"].inside["entity"] = | 1346 | Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = |
| 1407 | Prism.languages.markup["entity"]; | 1347 | Prism.languages.markup['entity']; |
| 1408 | Prism.languages.markup["doctype"].inside["internal-subset"].inside = | 1348 | Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup; |
| 1409 | Prism.languages.markup; | | |
| 1410 | | 1349 | |
| 1411 | // Plugin to make entity title show the real entity, idea by Roman Komarov | 1350 | // Plugin to make entity title show the real entity, idea by Roman Komarov |
| 1412 | Prism.hooks.add("wrap", function (env) { | 1351 | Prism.hooks.add('wrap', function (env) { |
| 1413 | if (env.type === "entity") { | 1352 | |
| 1414 | env.attributes["title"] = env.content.replace(/&/, "&"); | 1353 | if (env.type === 'entity') { |
| 1415 | } | 1354 | env.attributes['title'] = env.content.replace(/&/, '&'); |
| | 1355 | } |
| 1416 | }); | 1356 | }); |
| 1417 | | 1357 | |
| 1418 | Object.defineProperty(Prism.languages.markup.tag, "addInlined", { | 1358 | Object.defineProperty(Prism.languages.markup.tag, 'addInlined', { |
| 1419 | /** | 1359 | /** |
| 1420 | * Adds an inlined language to markup. | 1360 | * Adds an inlined language to markup. |
| 1421 | * | 1361 | * |
| 1422 | * An example of an inlined language is CSS with `<style>` tags. | 1362 | * An example of an inlined language is CSS with `<style>` tags. |
| 1423 | * | 1363 | * |
| 1424 | * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as | 1364 | * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as |
| 1425 | * case insensitive. | 1365 | * case insensitive. |
| 1426 | * @param {string} lang The language key. | 1366 | * @param {string} lang The language key. |
| 1427 | * @example | 1367 | * @example |
| 1428 | * addInlined('style', 'css'); | 1368 | * addInlined('style', 'css'); |
| 1429 | */ | 1369 | */ |
| 1430 | value: function addInlined(tagName, lang) { | 1370 | value: function addInlined(tagName, lang) { |
| 1431 | var includedCdataInside = {}; | 1371 | var includedCdataInside = {}; |
| 1432 | includedCdataInside["language-" + lang] = { | 1372 | includedCdataInside['language-' + lang] = { |
| 1433 | pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i, | 1373 | pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i, |
| 1434 | lookbehind: true, | 1374 | lookbehind: true, |
| 1435 | inside: Prism.languages[lang], | 1375 | inside: Prism.languages[lang] |
| 1436 | }; | 1376 | }; |
| 1437 | includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i; | 1377 | includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i; |
| 1438 | | 1378 | |
| 1439 | var inside = { | 1379 | var inside = { |
| 1440 | "included-cdata": { | 1380 | 'included-cdata': { |
| 1441 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, | 1381 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, |
| 1442 | inside: includedCdataInside, | 1382 | inside: includedCdataInside |
| 1443 | }, | 1383 | } |
| 1444 | }; | 1384 | }; |
| 1445 | inside["language-" + lang] = { | 1385 | inside['language-' + lang] = { |
| 1446 | pattern: /[\s\S]+/, | 1386 | pattern: /[\s\S]+/, |
| 1447 | inside: Prism.languages[lang], | 1387 | inside: Prism.languages[lang] |
| 1448 | }; | 1388 | }; |
| 1449 | | 1389 | |
| 1450 | var def = {}; | 1390 | var def = {}; |
| 1451 | def[tagName] = { | 1391 | def[tagName] = { |
| 1452 | pattern: RegExp( | 1392 | pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'), |
| 1453 | /(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace( | 1393 | lookbehind: true, |
| 1454 | /__/g, | 1394 | greedy: true, |
| 1455 | function () { | 1395 | inside: inside |
| 1456 | return tagName; | 1396 | }; |
| 1457 | }, | 1397 | |
| 1458 | ), | 1398 | Prism.languages.insertBefore('markup', 'cdata', def); |
| 1459 | "i", | 1399 | } |
| 1460 | ), | | |
| 1461 | lookbehind: true, | | |
| 1462 | greedy: true, | | |
| 1463 | inside: inside, | | |
| 1464 | }; | | |
| 1465 | | | |
| 1466 | Prism.languages.insertBefore("markup", "cdata", def); | | |
| 1467 | }, | | |
| 1468 | }); | 1400 | }); |
| 1469 | Object.defineProperty(Prism.languages.markup.tag, "addAttribute", { | 1401 | Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', { |
| 1470 | /** | 1402 | /** |
| 1471 | * Adds an pattern to highlight languages embedded in HTML attributes. | 1403 | * Adds an pattern to highlight languages embedded in HTML attributes. |
| 1472 | * | 1404 | * |
| 1473 | * An example of an inlined language is CSS with `style` attributes. | 1405 | * An example of an inlined language is CSS with `style` attributes. |
| 1474 | * | 1406 | * |
| 1475 | * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as | 1407 | * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as |
| 1476 | * case insensitive. | 1408 | * case insensitive. |
| 1477 | * @param {string} lang The language key. | 1409 | * @param {string} lang The language key. |
| 1478 | * @example | 1410 | * @example |
| 1479 | * addAttribute('style', 'css'); | 1411 | * addAttribute('style', 'css'); |
| 1480 | */ | 1412 | */ |
| 1481 | value: function (attrName, lang) { | 1413 | value: function (attrName, lang) { |
| 1482 | Prism.languages.markup.tag.inside["special-attr"].push({ | 1414 | Prism.languages.markup.tag.inside['special-attr'].push({ |
| 1483 | pattern: RegExp( | 1415 | pattern: RegExp( |
| 1484 | /(^|["'\s])/.source + | 1416 | /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source, |
| 1485 | "(?:" + | 1417 | 'i' |
| 1486 | attrName + | 1418 | ), |
| 1487 | ")" + | 1419 | lookbehind: true, |
| 1488 | /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source, | 1420 | inside: { |
| 1489 | "i", | 1421 | 'attr-name': /^[^\s=]+/, |
| 1490 | ), | 1422 | 'attr-value': { |
| 1491 | lookbehind: true, | 1423 | pattern: /=[\s\S]+/, |
| 1492 | inside: { | 1424 | inside: { |
| 1493 | "attr-name": /^[^\s=]+/, | 1425 | 'value': { |
| 1494 | "attr-value": { | 1426 | pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/, |
| 1495 | pattern: /=[\s\S]+/, | 1427 | lookbehind: true, |
| 1496 | inside: { | 1428 | alias: [lang, 'language-' + lang], |
| 1497 | value: { | 1429 | inside: Prism.languages[lang] |
| 1498 | pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/, | 1430 | }, |
| 1499 | lookbehind: true, | 1431 | 'punctuation': [ |
| 1500 | alias: [lang, "language-" + lang], | 1432 | { |
| 1501 | inside: Prism.languages[lang], | 1433 | pattern: /^=/, |
| 1502 | }, | 1434 | alias: 'attr-equals' |
| 1503 | punctuation: [ | 1435 | }, |
| 1504 | { | 1436 | /"|'/ |
| 1505 | pattern: /^=/, | 1437 | ] |
| 1506 | alias: "attr-equals", | 1438 | } |
| 1507 | }, | 1439 | } |
| 1508 | /"|'/, | 1440 | } |
| 1509 | ], | 1441 | }); |
| 1510 | }, | 1442 | } |
| 1511 | }, | | |
| 1512 | }, | | |
| 1513 | }); | | |
| 1514 | }, | | |
| 1515 | }); | 1443 | }); |
| 1516 | | 1444 | |
| 1517 | Prism.languages.html = Prism.languages.markup; | 1445 | Prism.languages.html = Prism.languages.markup; |
| 1518 | Prism.languages.mathml = Prism.languages.markup; | 1446 | Prism.languages.mathml = Prism.languages.markup; |
| 1519 | Prism.languages.svg = Prism.languages.markup; | 1447 | Prism.languages.svg = Prism.languages.markup; |
| 1520 | | 1448 | |
| 1521 | Prism.languages.xml = Prism.languages.extend("markup", {}); | 1449 | Prism.languages.xml = Prism.languages.extend('markup', {}); |
| 1522 | Prism.languages.ssml = Prism.languages.xml; | 1450 | Prism.languages.ssml = Prism.languages.xml; |
| 1523 | Prism.languages.atom = Prism.languages.xml; | 1451 | Prism.languages.atom = Prism.languages.xml; |
| 1524 | Prism.languages.rss = Prism.languages.xml; | 1452 | Prism.languages.rss = Prism.languages.xml; |
| 1525 | | 1453 | |
| 1526 | (function (Prism) { | 1454 | (function (Prism) { |
| 1527 | var string = | 1455 | |
| 1528 | /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/; | 1456 | var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/; |
| 1529 | | 1457 | |
| 1530 | Prism.languages.css = { | 1458 | Prism.languages.css = { |
| 1531 | comment: /\/\*[\s\S]*?\*\//, | 1459 | 'comment': /\/\*[\s\S]*?\*\//, |
| 1532 | atrule: { | 1460 | 'atrule': { |
| 1533 | pattern: RegExp( | 1461 | pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source), |
| 1534 | "@[\\w-](?:" + | 1462 | inside: { |
| 1535 | /[^;{\s"']|\s+(?!\s)/.source + | 1463 | 'rule': /^@[\w-]+/, |
| 1536 | "|" + | 1464 | 'selector-function-argument': { |
| 1537 | string.source + | 1465 | pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/, |
| 1538 | ")*?" + | 1466 | lookbehind: true, |
| 1539 | /(?:;|(?=\s*\{))/.source, | 1467 | alias: 'selector' |
| 1540 | ), | 1468 | }, |
| 1541 | inside: { | 1469 | 'keyword': { |
| 1542 | rule: /^@[\w-]+/, | 1470 | pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/, |
| 1543 | "selector-function-argument": { | 1471 | lookbehind: true |
| 1544 | pattern: | 1472 | } |
| 1545 | /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/, | 1473 | // See rest below |
| 1546 | lookbehind: true, | 1474 | } |
| 1547 | alias: "selector", | 1475 | }, |
| 1548 | }, | 1476 | 'url': { |
| 1549 | keyword: { | 1477 | // https://drafts.csswg.org/css-values-3/#urls |
| 1550 | pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/, | 1478 | pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'), |
| 1551 | lookbehind: true, | 1479 | greedy: true, |
| 1552 | }, | 1480 | inside: { |
| 1553 | // See rest below | 1481 | 'function': /^url/i, |
| 1554 | }, | 1482 | 'punctuation': /^\(|\)$/, |
| 1555 | }, | 1483 | 'string': { |
| 1556 | url: { | 1484 | pattern: RegExp('^' + string.source + '$'), |
| 1557 | // https://drafts.csswg.org/css-values-3/#urls | 1485 | alias: 'url' |
| 1558 | pattern: RegExp( | 1486 | } |
| 1559 | "\\burl\\((?:" + | 1487 | } |
| 1560 | string.source + | 1488 | }, |
| 1561 | "|" + | 1489 | 'selector': { |
| 1562 | /(?:[^\\\r\n()"']|\\[\s\S])*/.source + | 1490 | pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'), |
| 1563 | ")\\)", | 1491 | lookbehind: true |
| 1564 | "i", | 1492 | }, |
| 1565 | ), | 1493 | 'string': { |
| 1566 | greedy: true, | 1494 | pattern: string, |
| 1567 | inside: { | 1495 | greedy: true |
| 1568 | function: /^url/i, | 1496 | }, |
| 1569 | punctuation: /^\(|\)$/, | 1497 | 'property': { |
| 1570 | string: { | 1498 | pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i, |
| 1571 | pattern: RegExp("^" + string.source + "$"), | 1499 | lookbehind: true |
| 1572 | alias: "url", | 1500 | }, |
| 1573 | }, | 1501 | 'important': /!important\b/i, |
| 1574 | }, | 1502 | 'function': { |
| 1575 | }, | 1503 | pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i, |
| 1576 | selector: { | 1504 | lookbehind: true |
| 1577 | pattern: RegExp( | 1505 | }, |
| 1578 | "(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|" + | 1506 | 'punctuation': /[(){};:,]/ |
| 1579 | string.source + | 1507 | }; |
| 1580 | ")*(?=\\s*\\{)", | 1508 | |
| 1581 | ), | 1509 | Prism.languages.css['atrule'].inside.rest = Prism.languages.css; |
| 1582 | lookbehind: true, | 1510 | |
| 1583 | }, | 1511 | var markup = Prism.languages.markup; |
| 1584 | string: { | 1512 | if (markup) { |
| 1585 | pattern: string, | 1513 | markup.tag.addInlined('style', 'css'); |
| 1586 | greedy: true, | 1514 | markup.tag.addAttribute('style', 'css'); |
| 1587 | }, | 1515 | } |
| 1588 | property: { | 1516 | |
| 1589 | pattern: | 1517 | }(Prism)); |
| 1590 | /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i, | | |
| 1591 | lookbehind: true, | | |
| 1592 | }, | | |
| 1593 | important: /!important\b/i, | | |
| 1594 | function: { | | |
| 1595 | pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i, | | |
| 1596 | lookbehind: true, | | |
| 1597 | }, | | |
| 1598 | punctuation: /[(){};:,]/, | | |
| 1599 | }; | | |
| 1600 | | | |
| 1601 | Prism.languages.css["atrule"].inside.rest = Prism.languages.css; | | |
| 1602 | | | |
| 1603 | var markup = Prism.languages.markup; | | |
| 1604 | if (markup) { | | |
| 1605 | markup.tag.addInlined("style", "css"); | | |
| 1606 | markup.tag.addAttribute("style", "css"); | | |
| 1607 | } | | |
| 1608 | })(Prism); | | |
| 1609 | | 1518 | |
| 1610 | Prism.languages.clike = { | 1519 | Prism.languages.clike = { |
| 1611 | comment: [ | 1520 | 'comment': [ |
| 1612 | { | 1521 | { |
| 1613 | pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, | 1522 | pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, |
| 1614 | lookbehind: true, | 1523 | lookbehind: true, |
| 1615 | greedy: true, | 1524 | greedy: true |
| 1616 | }, | 1525 | }, |
| 1617 | { | 1526 | { |
| 1618 | pattern: /(^|[^\\:])\/\/.*/, | 1527 | pattern: /(^|[^\\:])\/\/.*/, |
| 1619 | lookbehind: true, | 1528 | lookbehind: true, |
| 1620 | greedy: true, | 1529 | greedy: true |
| 1621 | }, | 1530 | } |
| 1622 | ], | 1531 | ], |
| 1623 | string: { | 1532 | 'string': { |
| 1624 | pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, | 1533 | pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, |
| 1625 | greedy: true, | 1534 | greedy: true |
| 1626 | }, | 1535 | }, |
| 1627 | "class-name": { | 1536 | 'class-name': { |
| 1628 | pattern: | 1537 | pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i, |
| 1629 | /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i, | 1538 | lookbehind: true, |
| 1630 | lookbehind: true, | 1539 | inside: { |
| 1631 | inside: { | 1540 | 'punctuation': /[.\\]/ |
| 1632 | punctuation: /[.\\]/, | 1541 | } |
| 1633 | }, | 1542 | }, |
| 1634 | }, | 1543 | 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/, |
| 1635 | keyword: | 1544 | 'boolean': /\b(?:false|true)\b/, |
| 1636 | /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/, | 1545 | 'function': /\b\w+(?=\()/, |
| 1637 | boolean: /\b(?:false|true)\b/, | 1546 | 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, |
| 1638 | function: /\b\w+(?=\()/, | 1547 | 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/, |
| 1639 | number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, | 1548 | 'punctuation': /[{}[\];(),.:]/ |
| 1640 | operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/, | | |
| 1641 | punctuation: /[{}[\];(),.:]/, | | |
| 1642 | }; | 1549 | }; |
| 1643 | | 1550 | |
| 1644 | Prism.languages.javascript = Prism.languages.extend("clike", { | 1551 | Prism.languages.javascript = Prism.languages.extend('clike', { |
| 1645 | "class-name": [ | 1552 | 'class-name': [ |
| 1646 | Prism.languages.clike["class-name"], | 1553 | Prism.languages.clike['class-name'], |
| 1647 | { | 1554 | { |
| 1648 | pattern: | 1555 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/, |
| 1649 | /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/, | 1556 | lookbehind: true |
| 1650 | lookbehind: true, | 1557 | } |
| 1651 | }, | 1558 | ], |
| 1652 | ], | 1559 | 'keyword': [ |
| 1653 | keyword: [ | 1560 | { |
| 1654 | { | 1561 | pattern: /((?:^|\})\s*)catch\b/, |
| 1655 | pattern: /((?:^|\})\s*)catch\b/, | 1562 | lookbehind: true |
| 1656 | lookbehind: true, | 1563 | }, |
| 1657 | }, | 1564 | { |
| 1658 | { | 1565 | pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/, |
| 1659 | pattern: | 1566 | lookbehind: true |
| 1660 | /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/, | 1567 | }, |
| 1661 | lookbehind: true, | 1568 | ], |
| 1662 | }, | 1569 | // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) |
| 1663 | ], | 1570 | 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/, |
| 1664 | // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) | 1571 | 'number': { |
| 1665 | function: | 1572 | pattern: RegExp( |
| 1666 | /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/, | 1573 | /(^|[^\w$])/.source + |
| 1667 | number: { | 1574 | '(?:' + |
| 1668 | pattern: RegExp( | 1575 | ( |
| 1669 | /(^|[^\w$])/.source + | 1576 | // constant |
| 1670 | "(?:" + | 1577 | /NaN|Infinity/.source + |
| 1671 | // constant | 1578 | '|' + |
| 1672 | (/NaN|Infinity/.source + | 1579 | // binary integer |
| 1673 | "|" + | 1580 | /0[bB][01]+(?:_[01]+)*n?/.source + |
| 1674 | // binary integer | 1581 | '|' + |
| 1675 | /0[bB][01]+(?:_[01]+)*n?/.source + | 1582 | // octal integer |
| 1676 | "|" + | 1583 | /0[oO][0-7]+(?:_[0-7]+)*n?/.source + |
| 1677 | // octal integer | 1584 | '|' + |
| 1678 | /0[oO][0-7]+(?:_[0-7]+)*n?/.source + | 1585 | // hexadecimal integer |
| 1679 | "|" + | 1586 | /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + |
| 1680 | // hexadecimal integer | 1587 | '|' + |
| 1681 | /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + | 1588 | // decimal bigint |
| 1682 | "|" + | 1589 | /\d+(?:_\d+)*n/.source + |
| 1683 | // decimal bigint | 1590 | '|' + |
| 1684 | /\d+(?:_\d+)*n/.source + | 1591 | // decimal number (integer or float) but no bigint |
| 1685 | "|" + | 1592 | /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source |
| 1686 | // decimal number (integer or float) but no bigint | 1593 | ) + |
| 1687 | /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/ | 1594 | ')' + |
| 1688 | .source) + | 1595 | /(?![\w$])/.source |
| 1689 | ")" + | 1596 | ), |
| 1690 | /(?![\w$])/.source, | 1597 | lookbehind: true |
| 1691 | ), | 1598 | }, |
| 1692 | lookbehind: true, | 1599 | 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/ |
| 1693 | }, | | |
| 1694 | operator: | | |
| 1695 | /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/, | | |
| 1696 | }); | 1600 | }); |
| 1697 | | 1601 | |
| 1698 | Prism.languages.javascript["class-name"][0].pattern = | 1602 | Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/; |
| 1699 | /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/; | 1603 | |
| 1700 | | 1604 | Prism.languages.insertBefore('javascript', 'keyword', { |
| 1701 | Prism.languages.insertBefore("javascript", "keyword", { | 1605 | 'regex': { |
| 1702 | regex: { | 1606 | pattern: RegExp( |
| 1703 | pattern: RegExp( | 1607 | // lookbehind |
| 1704 | // lookbehind | 1608 | // eslint-disable-next-line regexp/no-dupe-characters-character-class |
| 1705 | // eslint-disable-next-line regexp/no-dupe-characters-character-class | 1609 | /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + |
| 1706 | /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + | 1610 | // Regex pattern: |
| 1707 | // Regex pattern: | 1611 | // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character |
| 1708 | // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character | 1612 | // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible |
| 1709 | // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible | 1613 | // with the only syntax, so we have to define 2 different regex patterns. |
| 1710 | // with the only syntax, so we have to define 2 different regex patterns. | 1614 | /\//.source + |
| 1711 | /\//.source + | 1615 | '(?:' + |
| 1712 | "(?:" + | 1616 | /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + |
| 1713 | /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/ | 1617 | '|' + |
| 1714 | .source + | 1618 | // `v` flag syntax. This supports 3 levels of nested character classes. |
| 1715 | "|" + | 1619 | /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + |
| 1716 | // `v` flag syntax. This supports 3 levels of nested character classes. | 1620 | ')' + |
| 1717 | /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/ | 1621 | // lookahead |
| 1718 | .source + | 1622 | /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source |
| 1719 | ")" + | 1623 | ), |
| 1720 | // lookahead | 1624 | lookbehind: true, |
| 1721 | /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/ | 1625 | greedy: true, |
| 1722 | .source, | 1626 | inside: { |
| 1723 | ), | 1627 | 'regex-source': { |
| 1724 | lookbehind: true, | 1628 | pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/, |
| 1725 | greedy: true, | 1629 | lookbehind: true, |
| 1726 | inside: { | 1630 | alias: 'language-regex', |
| 1727 | "regex-source": { | 1631 | inside: Prism.languages.regex |
| 1728 | pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/, | 1632 | }, |
| 1729 | lookbehind: true, | 1633 | 'regex-delimiter': /^\/|\/$/, |
| 1730 | alias: "language-regex", | 1634 | 'regex-flags': /^[a-z]+$/, |
| 1731 | inside: Prism.languages.regex, | 1635 | } |
| 1732 | }, | 1636 | }, |
| 1733 | "regex-delimiter": /^\/|\/$/, | 1637 | // This must be declared before keyword because we use "function" inside the look-forward |
| 1734 | "regex-flags": /^[a-z]+$/, | 1638 | 'function-variable': { |
| 1735 | }, | 1639 | pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/, |
| 1736 | }, | 1640 | alias: 'function' |
| 1737 | // This must be declared before keyword because we use "function" inside the look-forward | 1641 | }, |
| 1738 | "function-variable": { | 1642 | 'parameter': [ |
| 1739 | pattern: | 1643 | { |
| 1740 | /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/, | 1644 | pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/, |
| 1741 | alias: "function", | 1645 | lookbehind: true, |
| 1742 | }, | 1646 | inside: Prism.languages.javascript |
| 1743 | parameter: [ | 1647 | }, |
| 1744 | { | 1648 | { |
| 1745 | pattern: | 1649 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i, |
| 1746 | /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/, | 1650 | lookbehind: true, |
| 1747 | lookbehind: true, | 1651 | inside: Prism.languages.javascript |
| 1748 | inside: Prism.languages.javascript, | 1652 | }, |
| 1749 | }, | 1653 | { |
| 1750 | { | 1654 | pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/, |
| 1751 | pattern: | 1655 | lookbehind: true, |
| 1752 | /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i, | 1656 | inside: Prism.languages.javascript |
| 1753 | lookbehind: true, | 1657 | }, |
| 1754 | inside: Prism.languages.javascript, | 1658 | { |
| 1755 | }, | 1659 | pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/, |
| 1756 | { | 1660 | lookbehind: true, |
| 1757 | pattern: | 1661 | inside: Prism.languages.javascript |
| 1758 | /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/, | 1662 | } |
| 1759 | lookbehind: true, | 1663 | ], |
| 1760 | inside: Prism.languages.javascript, | 1664 | 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/ |
| 1761 | }, | | |
| 1762 | { | | |
| 1763 | pattern: | | |
| 1764 | /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/, | | |
| 1765 | lookbehind: true, | | |
| 1766 | inside: Prism.languages.javascript, | | |
| 1767 | }, | | |
| 1768 | ], | | |
| 1769 | constant: /\b[A-Z](?:[A-Z_]|\dx?)*\b/, | | |
| 1770 | }); | 1665 | }); |
| 1771 | | 1666 | |
| 1772 | Prism.languages.insertBefore("javascript", "string", { | 1667 | Prism.languages.insertBefore('javascript', 'string', { |
| 1773 | hashbang: { | 1668 | 'hashbang': { |
| 1774 | pattern: /^#!.*/, | 1669 | pattern: /^#!.*/, |
| 1775 | greedy: true, | 1670 | greedy: true, |
| 1776 | alias: "comment", | 1671 | alias: 'comment' |
| 1777 | }, | 1672 | }, |
| 1778 | "template-string": { | 1673 | 'template-string': { |
| 1779 | pattern: | 1674 | pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, |
| 1780 | /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, | 1675 | greedy: true, |
| 1781 | greedy: true, | 1676 | inside: { |
| 1782 | inside: { | 1677 | 'template-punctuation': { |
| 1783 | "template-punctuation": { | 1678 | pattern: /^`|`$/, |
| 1784 | pattern: /^`|`$/, | 1679 | alias: 'string' |
| 1785 | alias: "string", | 1680 | }, |
| 1786 | }, | 1681 | 'interpolation': { |
| 1787 | interpolation: { | 1682 | pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, |
| 1788 | pattern: | 1683 | lookbehind: true, |
| 1789 | /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, | 1684 | inside: { |
| 1790 | lookbehind: true, | 1685 | 'interpolation-punctuation': { |
| 1791 | inside: { | 1686 | pattern: /^\$\{|\}$/, |
| 1792 | "interpolation-punctuation": { | 1687 | alias: 'punctuation' |
| 1793 | pattern: /^\$\{|\}$/, | 1688 | }, |
| 1794 | alias: "punctuation", | 1689 | rest: Prism.languages.javascript |
| 1795 | }, | 1690 | } |
| 1796 | rest: Prism.languages.javascript, | 1691 | }, |
| 1797 | }, | 1692 | 'string': /[\s\S]+/ |
| 1798 | }, | 1693 | } |
| 1799 | string: /[\s\S]+/, | 1694 | }, |
| 1800 | }, | 1695 | 'string-property': { |
| 1801 | }, | 1696 | pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m, |
| 1802 | "string-property": { | 1697 | lookbehind: true, |
| 1803 | pattern: | 1698 | greedy: true, |
| 1804 | /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m, | 1699 | alias: 'property' |
| 1805 | lookbehind: true, | 1700 | } |
| 1806 | greedy: true, | | |
| 1807 | alias: "property", | | |
| 1808 | }, | | |
| 1809 | }); | 1701 | }); |
| 1810 | | 1702 | |
| 1811 | Prism.languages.insertBefore("javascript", "operator", { | 1703 | Prism.languages.insertBefore('javascript', 'operator', { |
| 1812 | "literal-property": { | 1704 | 'literal-property': { |
| 1813 | pattern: | 1705 | pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m, |
| 1814 | /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m, | 1706 | lookbehind: true, |
| 1815 | lookbehind: true, | 1707 | alias: 'property' |
| 1816 | alias: "property", | 1708 | }, |
| 1817 | }, | | |
| 1818 | }); | 1709 | }); |
| 1819 | | 1710 | |
| 1820 | if (Prism.languages.markup) { | 1711 | if (Prism.languages.markup) { |
| 1821 | Prism.languages.markup.tag.addInlined("script", "javascript"); | 1712 | Prism.languages.markup.tag.addInlined('script', 'javascript'); |
| 1822 | | 1713 | |
| 1823 | // add attribute support for all DOM events. | 1714 | // add attribute support for all DOM events. |
| 1824 | // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events | 1715 | // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events |
| 1825 | Prism.languages.markup.tag.addAttribute( | 1716 | Prism.languages.markup.tag.addAttribute( |
| 1826 | /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/ | 1717 | /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source, |
| 1827 | .source, | 1718 | 'javascript' |
| 1828 | "javascript", | 1719 | ); |
| 1829 | ); | | |
| 1830 | } | 1720 | } |
| 1831 | | 1721 | |
| 1832 | Prism.languages.js = Prism.languages.javascript; | 1722 | Prism.languages.js = Prism.languages.javascript; |
| 1833 | | 1723 | |
| 1834 | (function (Prism) { | 1724 | (function (Prism) { |
| 1835 | // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|' | 1725 | // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|' |
| 1836 | // + LC_ALL, RANDOM, REPLY, SECONDS. | 1726 | // + LC_ALL, RANDOM, REPLY, SECONDS. |
| 1837 | // + make sure PS1..4 are here as they are not always set, | 1727 | // + make sure PS1..4 are here as they are not always set, |
| 1838 | // - some useless things. | 1728 | // - some useless things. |
| 1839 | var envVars = | 1729 | var envVars = '\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b'; |
| 1840 | "\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b"; | 1730 | |
| 1841 | | 1731 | var commandAfterHeredoc = { |
| 1842 | var commandAfterHeredoc = { | 1732 | pattern: /(^(["']?)\w+\2)[ \t]+\S.*/, |
| 1843 | pattern: /(^(["']?)\w+\2)[ \t]+\S.*/, | 1733 | lookbehind: true, |
| 1844 | lookbehind: true, | 1734 | alias: 'punctuation', // this looks reasonably well in all themes |
| 1845 | alias: "punctuation", // this looks reasonably well in all themes | 1735 | inside: null // see below |
| 1846 | inside: null, // see below | 1736 | }; |
| 1847 | }; | 1737 | |
| 1848 | | 1738 | var insideString = { |
| 1849 | var insideString = { | 1739 | 'bash': commandAfterHeredoc, |
| 1850 | bash: commandAfterHeredoc, | 1740 | 'environment': { |
| 1851 | environment: { | 1741 | pattern: RegExp('\\$' + envVars), |
| 1852 | pattern: RegExp("\\$" + envVars), | 1742 | alias: 'constant' |
| 1853 | alias: "constant", | 1743 | }, |
| 1854 | }, | 1744 | 'variable': [ |
| 1855 | variable: [ | 1745 | // [0]: Arithmetic Environment |
| 1856 | // [0]: Arithmetic Environment | 1746 | { |
| 1857 | { | 1747 | pattern: /\$?\(\([\s\S]+?\)\)/, |
| 1858 | pattern: /\$?\(\([\s\S]+?\)\)/, | 1748 | greedy: true, |
| 1859 | greedy: true, | 1749 | inside: { |
| 1860 | inside: { | 1750 | // If there is a $ sign at the beginning highlight $(( and )) as variable |
| 1861 | // If there is a $ sign at the beginning highlight $(( and )) as variable | 1751 | 'variable': [ |
| 1862 | variable: [ | 1752 | { |
| 1863 | { | 1753 | pattern: /(^\$\(\([\s\S]+)\)\)/, |
| 1864 | pattern: /(^\$\(\([\s\S]+)\)\)/, | 1754 | lookbehind: true |
| 1865 | lookbehind: true, | 1755 | }, |
| 1866 | }, | 1756 | /^\$\(\(/ |
| 1867 | /^\$\(\(/, | 1757 | ], |
| 1868 | ], | 1758 | 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/, |
| 1869 | number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/, | 1759 | // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic |
| 1870 | // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic | 1760 | 'operator': /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/, |
| 1871 | operator: /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/, | 1761 | // If there is no $ sign at the beginning highlight (( and )) as punctuation |
| 1872 | // If there is no $ sign at the beginning highlight (( and )) as punctuation | 1762 | 'punctuation': /\(\(?|\)\)?|,|;/ |
| 1873 | punctuation: /\(\(?|\)\)?|,|;/, | 1763 | } |
| 1874 | }, | 1764 | }, |
| 1875 | }, | 1765 | // [1]: Command Substitution |
| 1876 | // [1]: Command Substitution | 1766 | { |
| 1877 | { | 1767 | pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/, |
| 1878 | pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/, | 1768 | greedy: true, |
| 1879 | greedy: true, | 1769 | inside: { |
| 1880 | inside: { | 1770 | 'variable': /^\$\(|^`|\)$|`$/ |
| 1881 | variable: /^\$\(|^`|\)$|`$/, | 1771 | } |
| 1882 | }, | 1772 | }, |
| 1883 | }, | 1773 | // [2]: Brace expansion |
| 1884 | // [2]: Brace expansion | 1774 | { |
| 1885 | { | 1775 | pattern: /\$\{[^}]+\}/, |
| 1886 | pattern: /\$\{[^}]+\}/, | 1776 | greedy: true, |
| 1887 | greedy: true, | 1777 | inside: { |
| 1888 | inside: { | 1778 | 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/, |
| 1889 | operator: /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/, | 1779 | 'punctuation': /[\[\]]/, |
| 1890 | punctuation: /[\[\]]/, | 1780 | 'environment': { |
| 1891 | environment: { | 1781 | pattern: RegExp('(\\{)' + envVars), |
| 1892 | pattern: RegExp("(\\{)" + envVars), | 1782 | lookbehind: true, |
| 1893 | lookbehind: true, | 1783 | alias: 'constant' |
| 1894 | alias: "constant", | 1784 | } |
| 1895 | }, | 1785 | } |
| 1896 | }, | 1786 | }, |
| 1897 | }, | 1787 | /\$(?:\w+|[#?*!@$])/ |
| 1898 | /\$(?:\w+|[#?*!@$])/, | 1788 | ], |
| 1899 | ], | 1789 | // Escape sequences from echo and printf's manuals, and escaped quotes. |
| 1900 | // Escape sequences from echo and printf's manuals, and escaped quotes. | 1790 | 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/ |
| 1901 | entity: | 1791 | }; |
| 1902 | /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/, | 1792 | |
| 1903 | }; | 1793 | Prism.languages.bash = { |
| 1904 | | 1794 | 'shebang': { |
| 1905 | Prism.languages.bash = { | 1795 | pattern: /^#!\s*\/.*/, |
| 1906 | shebang: { | 1796 | alias: 'important' |
| 1907 | pattern: /^#!\s*\/.*/, | 1797 | }, |
| 1908 | alias: "important", | 1798 | 'comment': { |
| 1909 | }, | 1799 | pattern: /(^|[^"{\\$])#.*/, |
| 1910 | comment: { | 1800 | lookbehind: true |
| 1911 | pattern: /(^|[^"{\\$])#.*/, | 1801 | }, |
| 1912 | lookbehind: true, | 1802 | 'function-name': [ |
| 1913 | }, | 1803 | // a) function foo { |
| 1914 | "function-name": [ | 1804 | // b) foo() { |
| 1915 | // a) function foo { | 1805 | // c) function foo() { |
| 1916 | // b) foo() { | 1806 | // but not “foo {” |
| 1917 | // c) function foo() { | 1807 | { |
| 1918 | // but not “foo {” | 1808 | // a) and c) |
| 1919 | { | 1809 | pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/, |
| 1920 | // a) and c) | 1810 | lookbehind: true, |
| 1921 | pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/, | 1811 | alias: 'function' |
| 1922 | lookbehind: true, | 1812 | }, |
| 1923 | alias: "function", | 1813 | { |
| 1924 | }, | 1814 | // b) |
| 1925 | { | 1815 | pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/, |
| 1926 | // b) | 1816 | alias: 'function' |
| 1927 | pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/, | 1817 | } |
| 1928 | alias: "function", | 1818 | ], |
| 1929 | }, | 1819 | // Highlight variable names as variables in for and select beginnings. |
| 1930 | ], | 1820 | 'for-or-select': { |
| 1931 | // Highlight variable names as variables in for and select beginnings. | 1821 | pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/, |
| 1932 | "for-or-select": { | 1822 | alias: 'variable', |
| 1933 | pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/, | 1823 | lookbehind: true |
| 1934 | alias: "variable", | 1824 | }, |
| 1935 | lookbehind: true, | 1825 | // Highlight variable names as variables in the left-hand part |
| 1936 | }, | 1826 | // of assignments (“=” and “+=”). |
| 1937 | // Highlight variable names as variables in the left-hand part | 1827 | 'assign-left': { |
| 1938 | // of assignments (“=” and “+=”). | 1828 | pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/, |
| 1939 | "assign-left": { | 1829 | inside: { |
| 1940 | pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/, | 1830 | 'environment': { |
| 1941 | inside: { | 1831 | pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars), |
| 1942 | environment: { | 1832 | lookbehind: true, |
| 1943 | pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars), | 1833 | alias: 'constant' |
| 1944 | lookbehind: true, | 1834 | } |
| 1945 | alias: "constant", | 1835 | }, |
| 1946 | }, | 1836 | alias: 'variable', |
| 1947 | }, | 1837 | lookbehind: true |
| 1948 | alias: "variable", | 1838 | }, |
| 1949 | lookbehind: true, | 1839 | // Highlight parameter names as variables |
| 1950 | }, | 1840 | 'parameter': { |
| 1951 | // Highlight parameter names as variables | 1841 | pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/, |
| 1952 | parameter: { | 1842 | alias: 'variable', |
| 1953 | pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/, | 1843 | lookbehind: true |
| 1954 | alias: "variable", | 1844 | }, |
| 1955 | lookbehind: true, | 1845 | 'string': [ |
| 1956 | }, | 1846 | // Support for Here-documents https://en.wikipedia.org/wiki/Here_document |
| 1957 | string: [ | 1847 | { |
| 1958 | // Support for Here-documents https://en.wikipedia.org/wiki/Here_document | 1848 | pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/, |
| 1959 | { | 1849 | lookbehind: true, |
| 1960 | pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/, | 1850 | greedy: true, |
| 1961 | lookbehind: true, | 1851 | inside: insideString |
| 1962 | greedy: true, | 1852 | }, |
| 1963 | inside: insideString, | 1853 | // Here-document with quotes around the tag |
| 1964 | }, | 1854 | // → No expansion (so no “inside”). |
| 1965 | // Here-document with quotes around the tag | 1855 | { |
| 1966 | // → No expansion (so no “inside”). | 1856 | pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/, |
| 1967 | { | 1857 | lookbehind: true, |
| 1968 | pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/, | 1858 | greedy: true, |
| 1969 | lookbehind: true, | 1859 | inside: { |
| 1970 | greedy: true, | 1860 | 'bash': commandAfterHeredoc |
| 1971 | inside: { | 1861 | } |
| 1972 | bash: commandAfterHeredoc, | 1862 | }, |
| 1973 | }, | 1863 | // “Normal” string |
| 1974 | }, | 1864 | { |
| 1975 | // “Normal” string | 1865 | // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html |
| 1976 | { | 1866 | pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/, |
| 1977 | // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html | 1867 | lookbehind: true, |
| 1978 | pattern: | 1868 | greedy: true, |
| 1979 | /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/, | 1869 | inside: insideString |
| 1980 | lookbehind: true, | 1870 | }, |
| 1981 | greedy: true, | 1871 | { |
| 1982 | inside: insideString, | 1872 | // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html |
| 1983 | }, | 1873 | pattern: /(^|[^$\\])'[^']*'/, |
| 1984 | { | 1874 | lookbehind: true, |
| 1985 | // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html | 1875 | greedy: true |
| 1986 | pattern: /(^|[^$\\])'[^']*'/, | 1876 | }, |
| 1987 | lookbehind: true, | 1877 | { |
| 1988 | greedy: true, | 1878 | // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html |
| 1989 | }, | 1879 | pattern: /\$'(?:[^'\\]|\\[\s\S])*'/, |
| 1990 | { | 1880 | greedy: true, |
| 1991 | // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html | 1881 | inside: { |
| 1992 | pattern: /\$'(?:[^'\\]|\\[\s\S])*'/, | 1882 | 'entity': insideString.entity |
| 1993 | greedy: true, | 1883 | } |
| 1994 | inside: { | 1884 | } |
| 1995 | entity: insideString.entity, | 1885 | ], |
| 1996 | }, | 1886 | 'environment': { |
| 1997 | }, | 1887 | pattern: RegExp('\\$?' + envVars), |
| 1998 | ], | 1888 | alias: 'constant' |
| 1999 | environment: { | 1889 | }, |
| 2000 | pattern: RegExp("\\$?" + envVars), | 1890 | 'variable': insideString.variable, |
| 2001 | alias: "constant", | 1891 | 'function': { |
| 2002 | }, | 1892 | pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/, |
| 2003 | variable: insideString.variable, | 1893 | lookbehind: true |
| 2004 | function: { | 1894 | }, |
| 2005 | pattern: | 1895 | 'keyword': { |
| 2006 | /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/, | 1896 | pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/, |
| 2007 | lookbehind: true, | 1897 | lookbehind: true |
| 2008 | }, | 1898 | }, |
| 2009 | keyword: { | 1899 | // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html |
| 2010 | pattern: | 1900 | 'builtin': { |
| 2011 | /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/, | 1901 | pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/, |
| 2012 | lookbehind: true, | 1902 | lookbehind: true, |
| 2013 | }, | 1903 | // Alias added to make those easier to distinguish from strings. |
| 2014 | // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html | 1904 | alias: 'class-name' |
| 2015 | builtin: { | 1905 | }, |
| 2016 | pattern: | 1906 | 'boolean': { |
| 2017 | /(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/, | 1907 | pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/, |
| 2018 | lookbehind: true, | 1908 | lookbehind: true |
| 2019 | // Alias added to make those easier to distinguish from strings. | 1909 | }, |
| 2020 | alias: "class-name", | 1910 | 'file-descriptor': { |
| 2021 | }, | 1911 | pattern: /\B&\d\b/, |
| 2022 | boolean: { | 1912 | alias: 'important' |
| 2023 | pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/, | 1913 | }, |
| 2024 | lookbehind: true, | 1914 | 'operator': { |
| 2025 | }, | 1915 | // Lots of redirections here, but not just that. |
| 2026 | "file-descriptor": { | 1916 | pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/, |
| 2027 | pattern: /\B&\d\b/, | 1917 | inside: { |
| 2028 | alias: "important", | 1918 | 'file-descriptor': { |
| 2029 | }, | 1919 | pattern: /^\d/, |
| 2030 | operator: { | 1920 | alias: 'important' |
| 2031 | // Lots of redirections here, but not just that. | 1921 | } |
| 2032 | pattern: | 1922 | } |
| 2033 | /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/, | 1923 | }, |
| 2034 | inside: { | 1924 | 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/, |
| 2035 | "file-descriptor": { | 1925 | 'number': { |
| 2036 | pattern: /^\d/, | 1926 | pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/, |
| 2037 | alias: "important", | 1927 | lookbehind: true |
| 2038 | }, | 1928 | } |
| 2039 | }, | 1929 | }; |
| 2040 | }, | 1930 | |
| 2041 | punctuation: /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/, | 1931 | commandAfterHeredoc.inside = Prism.languages.bash; |
| 2042 | number: { | 1932 | |
| 2043 | pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/, | 1933 | /* Patterns in command substitution. */ |
| 2044 | lookbehind: true, | 1934 | var toBeCopied = [ |
| 2045 | }, | 1935 | 'comment', |
| 2046 | }; | 1936 | 'function-name', |
| 2047 | | 1937 | 'for-or-select', |
| 2048 | commandAfterHeredoc.inside = Prism.languages.bash; | 1938 | 'assign-left', |
| 2049 | | 1939 | 'parameter', |
| 2050 | /* Patterns in command substitution. */ | 1940 | 'string', |
| 2051 | var toBeCopied = [ | 1941 | 'environment', |
| 2052 | "comment", | 1942 | 'function', |
| 2053 | "function-name", | 1943 | 'keyword', |
| 2054 | "for-or-select", | 1944 | 'builtin', |
| 2055 | "assign-left", | 1945 | 'boolean', |
| 2056 | "parameter", | 1946 | 'file-descriptor', |
| 2057 | "string", | 1947 | 'operator', |
| 2058 | "environment", | 1948 | 'punctuation', |
| 2059 | "function", | 1949 | 'number' |
| 2060 | "keyword", | 1950 | ]; |
| 2061 | "builtin", | 1951 | var inside = insideString.variable[1].inside; |
| 2062 | "boolean", | 1952 | for (var i = 0; i < toBeCopied.length; i++) { |
| 2063 | "file-descriptor", | 1953 | inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]]; |
| 2064 | "operator", | 1954 | } |
| 2065 | "punctuation", | 1955 | |
| 2066 | "number", | 1956 | Prism.languages.sh = Prism.languages.bash; |
| 2067 | ]; | 1957 | Prism.languages.shell = Prism.languages.bash; |
| 2068 | var inside = insideString.variable[1].inside; | 1958 | }(Prism)); |
| 2069 | for (var i = 0; i < toBeCopied.length; i++) { | 1959 | |
| 2070 | inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]]; | 1960 | Prism.languages.c = Prism.languages.extend('clike', { |
| 2071 | } | 1961 | 'comment': { |
| 2072 | | 1962 | pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/, |
| 2073 | Prism.languages.sh = Prism.languages.bash; | 1963 | greedy: true |
| 2074 | Prism.languages.shell = Prism.languages.bash; | 1964 | }, |
| 2075 | })(Prism); | 1965 | 'string': { |
| 2076 | | 1966 | // https://en.cppreference.com/w/c/language/string_literal |
| 2077 | Prism.languages.c = Prism.languages.extend("clike", { | 1967 | pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/, |
| 2078 | comment: { | 1968 | greedy: true |
| 2079 | pattern: | 1969 | }, |
| 2080 | /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/, | 1970 | 'class-name': { |
| 2081 | greedy: true, | 1971 | pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/, |
| 2082 | }, | 1972 | lookbehind: true |
| 2083 | string: { | 1973 | }, |
| 2084 | // https://en.cppreference.com/w/c/language/string_literal | 1974 | 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/, |
| 2085 | pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/, | 1975 | 'function': /\b[a-z_]\w*(?=\s*\()/i, |
| 2086 | greedy: true, | 1976 | 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i, |
| 2087 | }, | 1977 | 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/ |
| 2088 | "class-name": { | | |
| 2089 | pattern: | | |
| 2090 | /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/, | | |
| 2091 | lookbehind: true, | | |
| 2092 | }, | | |
| 2093 | keyword: | | |
| 2094 | /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/, | | |
| 2095 | function: /\b[a-z_]\w*(?=\s*\()/i, | | |
| 2096 | number: | | |
| 2097 | /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i, | | |
| 2098 | operator: />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/, | | |
| 2099 | }); | 1978 | }); |
| 2100 | | 1979 | |
| 2101 | Prism.languages.insertBefore("c", "string", { | 1980 | Prism.languages.insertBefore('c', 'string', { |
| 2102 | char: { | 1981 | 'char': { |
| 2103 | // https://en.cppreference.com/w/c/language/character_constant | 1982 | // https://en.cppreference.com/w/c/language/character_constant |
| 2104 | pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/, | 1983 | pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/, |
| 2105 | greedy: true, | 1984 | greedy: true |
| 2106 | }, | 1985 | } |
| 2107 | }); | 1986 | }); |
| 2108 | | 1987 | |
| 2109 | Prism.languages.insertBefore("c", "string", { | 1988 | Prism.languages.insertBefore('c', 'string', { |
| 2110 | macro: { | 1989 | 'macro': { |
| 2111 | // allow for multiline macro definitions | 1990 | // allow for multiline macro definitions |
| 2112 | // spaces after the # character compile fine with gcc | 1991 | // spaces after the # character compile fine with gcc |
| 2113 | pattern: | 1992 | pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, |
| 2114 | /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, | 1993 | lookbehind: true, |
| 2115 | lookbehind: true, | 1994 | greedy: true, |
| 2116 | greedy: true, | 1995 | alias: 'property', |
| 2117 | alias: "property", | 1996 | inside: { |
| 2118 | inside: { | 1997 | 'string': [ |
| 2119 | string: [ | 1998 | { |
| 2120 | { | 1999 | // highlight the path of the include statement as a string |
| 2121 | // highlight the path of the include statement as a string | 2000 | pattern: /^(#\s*include\s*)<[^>]+>/, |
| 2122 | pattern: /^(#\s*include\s*)<[^>]+>/, | 2001 | lookbehind: true |
| 2123 | lookbehind: true, | 2002 | }, |
| 2124 | }, | 2003 | Prism.languages.c['string'] |
| 2125 | Prism.languages.c["string"], | 2004 | ], |
| 2126 | ], | 2005 | 'char': Prism.languages.c['char'], |
| 2127 | char: Prism.languages.c["char"], | 2006 | 'comment': Prism.languages.c['comment'], |
| 2128 | comment: Prism.languages.c["comment"], | 2007 | 'macro-name': [ |
| 2129 | "macro-name": [ | 2008 | { |
| 2130 | { | 2009 | pattern: /(^#\s*define\s+)\w+\b(?!\()/i, |
| 2131 | pattern: /(^#\s*define\s+)\w+\b(?!\()/i, | 2010 | lookbehind: true |
| 2132 | lookbehind: true, | 2011 | }, |
| 2133 | }, | 2012 | { |
| 2134 | { | 2013 | pattern: /(^#\s*define\s+)\w+\b(?=\()/i, |
| 2135 | pattern: /(^#\s*define\s+)\w+\b(?=\()/i, | 2014 | lookbehind: true, |
| 2136 | lookbehind: true, | 2015 | alias: 'function' |
| 2137 | alias: "function", | 2016 | } |
| 2138 | }, | 2017 | ], |
| 2139 | ], | 2018 | // highlight macro directives as keywords |
| 2140 | // highlight macro directives as keywords | 2019 | 'directive': { |
| 2141 | directive: { | 2020 | pattern: /^(#\s*)[a-z]+/, |
| 2142 | pattern: /^(#\s*)[a-z]+/, | 2021 | lookbehind: true, |
| 2143 | lookbehind: true, | 2022 | alias: 'keyword' |
| 2144 | alias: "keyword", | 2023 | }, |
| 2145 | }, | 2024 | 'directive-hash': /^#/, |
| 2146 | "directive-hash": /^#/, | 2025 | 'punctuation': /##|\\(?=[\r\n])/, |
| 2147 | punctuation: /##|\\(?=[\r\n])/, | 2026 | 'expression': { |
| 2148 | expression: { | 2027 | pattern: /\S[\s\S]*/, |
| 2149 | pattern: /\S[\s\S]*/, | 2028 | inside: Prism.languages.c |
| 2150 | inside: Prism.languages.c, | 2029 | } |
| 2151 | }, | 2030 | } |
| 2152 | }, | 2031 | } |
| 2153 | }, | | |
| 2154 | }); | 2032 | }); |
| 2155 | | 2033 | |
| 2156 | Prism.languages.insertBefore("c", "function", { | 2034 | Prism.languages.insertBefore('c', 'function', { |
| 2157 | // highlight predefined macros as constants | 2035 | // highlight predefined macros as constants |
| 2158 | constant: | 2036 | 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/ |
| 2159 | /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/, | | |
| 2160 | }); | 2037 | }); |
| 2161 | | 2038 | |
| 2162 | delete Prism.languages.c["boolean"]; | 2039 | delete Prism.languages.c['boolean']; |
| 2163 | | 2040 | |
| 2164 | (function (Prism) { | 2041 | (function (Prism) { |
| 2165 | var keyword = | 2042 | |
| 2166 | /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/; | 2043 | var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/; |
| 2167 | var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace( | 2044 | var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; }); |
| 2168 | /<keyword>/g, | 2045 | |
| 2169 | function () { | 2046 | Prism.languages.cpp = Prism.languages.extend('c', { |
| 2170 | return keyword.source; | 2047 | 'class-name': [ |
| 2171 | }, | 2048 | { |
| 2172 | ); | 2049 | pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source |
| 2173 | | 2050 | .replace(/<keyword>/g, function () { return keyword.source; })), |
| 2174 | Prism.languages.cpp = Prism.languages.extend("c", { | 2051 | lookbehind: true |
| 2175 | "class-name": [ | 2052 | }, |
| 2176 | { | 2053 | // This is intended to capture the class name of method implementations like: |
| 2177 | pattern: RegExp( | 2054 | // void foo::bar() const {} |
| 2178 | /(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source.replace( | 2055 | // However! The `foo` in the above example could also be a namespace, so we only capture the class name if |
| 2179 | /<keyword>/g, | 2056 | // it starts with an uppercase letter. This approximation should give decent results. |
| 2180 | function () { | 2057 | /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/, |
| 2181 | return keyword.source; | 2058 | // This will capture the class name before destructors like: |
| 2182 | }, | 2059 | // Foo::~Foo() {} |
| 2183 | ), | 2060 | /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i, |
| 2184 | ), | 2061 | // This also intends to capture the class name of method implementations but here the class has template |
| 2185 | lookbehind: true, | 2062 | // parameters, so it can't be a namespace (until C++ adds generic namespaces). |
| 2186 | }, | 2063 | /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/ |
| 2187 | // This is intended to capture the class name of method implementations like: | 2064 | ], |
| 2188 | // void foo::bar() const {} | 2065 | 'keyword': keyword, |
| 2189 | // However! The `foo` in the above example could also be a namespace, so we only capture the class name if | 2066 | 'number': { |
| 2190 | // it starts with an uppercase letter. This approximation should give decent results. | 2067 | pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i, |
| 2191 | /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/, | 2068 | greedy: true |
| 2192 | // This will capture the class name before destructors like: | 2069 | }, |
| 2193 | // Foo::~Foo() {} | 2070 | 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/, |
| 2194 | /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i, | 2071 | 'boolean': /\b(?:false|true)\b/ |
| 2195 | // This also intends to capture the class name of method implementations but here the class has template | 2072 | }); |
| 2196 | // parameters, so it can't be a namespace (until C++ adds generic namespaces). | 2073 | |
| 2197 | /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/, | 2074 | Prism.languages.insertBefore('cpp', 'string', { |
| 2198 | ], | 2075 | 'module': { |
| 2199 | keyword: keyword, | 2076 | // https://en.cppreference.com/w/cpp/language/modules |
| 2200 | number: { | 2077 | pattern: RegExp( |
| 2201 | pattern: | 2078 | /(\b(?:import|module)\s+)/.source + |
| 2202 | /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i, | 2079 | '(?:' + |
| 2203 | greedy: true, | 2080 | // header-name |
| 2204 | }, | 2081 | /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source + |
| 2205 | operator: | 2082 | '|' + |
| 2206 | />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/, | 2083 | // module name or partition or both |
| 2207 | boolean: /\b(?:false|true)\b/, | 2084 | /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) + |
| 2208 | }); | 2085 | ')' |
| 2209 | | 2086 | ), |
| 2210 | Prism.languages.insertBefore("cpp", "string", { | 2087 | lookbehind: true, |
| 2211 | module: { | 2088 | greedy: true, |
| 2212 | // https://en.cppreference.com/w/cpp/language/modules | 2089 | inside: { |
| 2213 | pattern: RegExp( | 2090 | 'string': /^[<"][\s\S]+/, |
| 2214 | /(\b(?:import|module)\s+)/.source + | 2091 | 'operator': /:/, |
| 2215 | "(?:" + | 2092 | 'punctuation': /\./ |
| 2216 | // header-name | 2093 | } |
| 2217 | /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source + | 2094 | }, |
| 2218 | "|" + | 2095 | 'raw-string': { |
| 2219 | // module name or partition or both | 2096 | pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/, |
| 2220 | /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace( | 2097 | alias: 'string', |
| 2221 | /<mod-name>/g, | 2098 | greedy: true |
| 2222 | function () { | 2099 | } |
| 2223 | return modName; | 2100 | }); |
| 2224 | }, | 2101 | |
| 2225 | ) + | 2102 | Prism.languages.insertBefore('cpp', 'keyword', { |
| 2226 | ")", | 2103 | 'generic-function': { |
| 2227 | ), | 2104 | pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i, |
| 2228 | lookbehind: true, | 2105 | inside: { |
| 2229 | greedy: true, | 2106 | 'function': /^\w+/, |
| 2230 | inside: { | 2107 | 'generic': { |
| 2231 | string: /^[<"][\s\S]+/, | 2108 | pattern: /<[\s\S]+/, |
| 2232 | operator: /:/, | 2109 | alias: 'class-name', |
| 2233 | punctuation: /\./, | 2110 | inside: Prism.languages.cpp |
| 2234 | }, | 2111 | } |
| 2235 | }, | 2112 | } |
| 2236 | "raw-string": { | 2113 | } |
| 2237 | pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/, | 2114 | }); |
| 2238 | alias: "string", | 2115 | |
| 2239 | greedy: true, | 2116 | Prism.languages.insertBefore('cpp', 'operator', { |
| 2240 | }, | 2117 | 'double-colon': { |
| 2241 | }); | 2118 | pattern: /::/, |
| 2242 | | 2119 | alias: 'punctuation' |
| 2243 | Prism.languages.insertBefore("cpp", "keyword", { | 2120 | } |
| 2244 | "generic-function": { | 2121 | }); |
| 2245 | pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i, | 2122 | |
| 2246 | inside: { | 2123 | Prism.languages.insertBefore('cpp', 'class-name', { |
| 2247 | function: /^\w+/, | 2124 | // the base clause is an optional list of parent classes |
| 2248 | generic: { | 2125 | // https://en.cppreference.com/w/cpp/language/class |
| 2249 | pattern: /<[\s\S]+/, | 2126 | 'base-clause': { |
| 2250 | alias: "class-name", | 2127 | pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/, |
| 2251 | inside: Prism.languages.cpp, | 2128 | lookbehind: true, |
| 2252 | }, | 2129 | greedy: true, |
| 2253 | }, | 2130 | inside: Prism.languages.extend('cpp', {}) |
| 2254 | }, | 2131 | } |
| 2255 | }); | 2132 | }); |
| 2256 | | 2133 | |
| 2257 | Prism.languages.insertBefore("cpp", "operator", { | 2134 | Prism.languages.insertBefore('inside', 'double-colon', { |
| 2258 | "double-colon": { | 2135 | // All untokenized words that are not namespaces should be class names |
| 2259 | pattern: /::/, | 2136 | 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i |
| 2260 | alias: "punctuation", | 2137 | }, Prism.languages.cpp['base-clause']); |
| 2261 | }, | 2138 | |
| 2262 | }); | 2139 | }(Prism)); |
| 2263 | | | |
| 2264 | Prism.languages.insertBefore("cpp", "class-name", { | | |
| 2265 | // the base clause is an optional list of parent classes | | |
| 2266 | // https://en.cppreference.com/w/cpp/language/class | | |
| 2267 | "base-clause": { | | |
| 2268 | pattern: | | |
| 2269 | /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/, | | |
| 2270 | lookbehind: true, | | |
| 2271 | greedy: true, | | |
| 2272 | inside: Prism.languages.extend("cpp", {}), | | |
| 2273 | }, | | |
| 2274 | }); | | |
| 2275 | | | |
| 2276 | Prism.languages.insertBefore( | | |
| 2277 | "inside", | | |
| 2278 | "double-colon", | | |
| 2279 | { | | |
| 2280 | // All untokenized words that are not namespaces should be class names | | |
| 2281 | "class-name": /\b[a-z_]\w*\b(?!\s*::)/i, | | |
| 2282 | }, | | |
| 2283 | Prism.languages.cpp["base-clause"], | | |
| 2284 | ); | | |
| 2285 | })(Prism); | | |
| 2286 | | 2140 | |
| 2287 | Prism.languages.cmake = { | 2141 | Prism.languages.cmake = { |
| 2288 | comment: /#.*/, | 2142 | 'comment': /#.*/, |
| 2289 | string: { | 2143 | 'string': { |
| 2290 | pattern: /"(?:[^\\"]|\\.)*"/, | 2144 | pattern: /"(?:[^\\"]|\\.)*"/, |
| 2291 | greedy: true, | 2145 | greedy: true, |
| 2292 | inside: { | 2146 | inside: { |
| 2293 | interpolation: { | 2147 | 'interpolation': { |
| 2294 | pattern: /\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/, | 2148 | pattern: /\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/, |
| 2295 | inside: { | 2149 | inside: { |
| 2296 | punctuation: /\$\{|\}/, | 2150 | 'punctuation': /\$\{|\}/, |
| 2297 | variable: /\w+/, | 2151 | 'variable': /\w+/ |
| 2298 | }, | 2152 | } |
| 2299 | }, | 2153 | } |
| 2300 | }, | 2154 | } |
| 2301 | }, | 2155 | }, |
| 2302 | variable: | 2156 | 'variable': /\b(?:CMAKE_\w+|\w+_(?:(?:BINARY|SOURCE)_DIR|DESCRIPTION|HOMEPAGE_URL|ROOT|VERSION(?:_MAJOR|_MINOR|_PATCH|_TWEAK)?)|(?:ANDROID|APPLE|BORLAND|BUILD_SHARED_LIBS|CACHE|CPACK_(?:ABSOLUTE_DESTINATION_FILES|COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY|ERROR_ON_ABSOLUTE_INSTALL_DESTINATION|INCLUDE_TOPLEVEL_DIRECTORY|INSTALL_DEFAULT_DIRECTORY_PERMISSIONS|INSTALL_SCRIPT|PACKAGING_INSTALL_PREFIX|SET_DESTDIR|WARN_ON_ABSOLUTE_INSTALL_DESTINATION)|CTEST_(?:BINARY_DIRECTORY|BUILD_COMMAND|BUILD_NAME|BZR_COMMAND|BZR_UPDATE_OPTIONS|CHANGE_ID|CHECKOUT_COMMAND|CONFIGURATION_TYPE|CONFIGURE_COMMAND|COVERAGE_COMMAND|COVERAGE_EXTRA_FLAGS|CURL_OPTIONS|CUSTOM_(?:COVERAGE_EXCLUDE|ERROR_EXCEPTION|ERROR_MATCH|ERROR_POST_CONTEXT|ERROR_PRE_CONTEXT|MAXIMUM_FAILED_TEST_OUTPUT_SIZE|MAXIMUM_NUMBER_OF_(?:ERRORS|WARNINGS)|MAXIMUM_PASSED_TEST_OUTPUT_SIZE|MEMCHECK_IGNORE|POST_MEMCHECK|POST_TEST|PRE_MEMCHECK|PRE_TEST|TESTS_IGNORE|WARNING_EXCEPTION|WARNING_MATCH)|CVS_CHECKOUT|CVS_COMMAND|CVS_UPDATE_OPTIONS|DROP_LOCATION|DROP_METHOD|DROP_SITE|DROP_SITE_CDASH|DROP_SITE_PASSWORD|DROP_SITE_USER|EXTRA_COVERAGE_GLOB|GIT_COMMAND|GIT_INIT_SUBMODULES|GIT_UPDATE_CUSTOM|GIT_UPDATE_OPTIONS|HG_COMMAND|HG_UPDATE_OPTIONS|LABELS_FOR_SUBPROJECTS|MEMORYCHECK_(?:COMMAND|COMMAND_OPTIONS|SANITIZER_OPTIONS|SUPPRESSIONS_FILE|TYPE)|NIGHTLY_START_TIME|P4_CLIENT|P4_COMMAND|P4_OPTIONS|P4_UPDATE_OPTIONS|RUN_CURRENT_SCRIPT|SCP_COMMAND|SITE|SOURCE_DIRECTORY|SUBMIT_URL|SVN_COMMAND|SVN_OPTIONS|SVN_UPDATE_OPTIONS|TEST_LOAD|TEST_TIMEOUT|TRIGGER_SITE|UPDATE_COMMAND|UPDATE_OPTIONS|UPDATE_VERSION_ONLY|USE_LAUNCHERS)|CYGWIN|ENV|EXECUTABLE_OUTPUT_PATH|GHS-MULTI|IOS|LIBRARY_OUTPUT_PATH|MINGW|MSVC(?:10|11|12|14|60|70|71|80|90|_IDE|_TOOLSET_VERSION|_VERSION)?|MSYS|PROJECT_NAME|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE))\b/, |
| 2303 | /\b(?:CMAKE_\w+|\w+_(?:(?:BINARY|SOURCE)_DIR|DESCRIPTION|HOMEPAGE_URL|ROOT|VERSION(?:_MAJOR|_MINOR|_PATCH|_TWEAK)?)|(?:ANDROID|APPLE|BORLAND|BUILD_SHARED_LIBS|CACHE|CPACK_(?:ABSOLUTE_DESTINATION_FILES|COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY|ERROR_ON_ABSOLUTE_INSTALL_DESTINATION|INCLUDE_TOPLEVEL_DIRECTORY|INSTALL_DEFAULT_DIRECTORY_PERMISSIONS|INSTALL_SCRIPT|PACKAGING_INSTALL_PREFIX|SET_DESTDIR|WARN_ON_ABSOLUTE_INSTALL_DESTINATION)|CTEST_(?:BINARY_DIRECTORY|BUILD_COMMAND|BUILD_NAME|BZR_COMMAND|BZR_UPDATE_OPTIONS|CHANGE_ID|CHECKOUT_COMMAND|CONFIGURATION_TYPE|CONFIGURE_COMMAND|COVERAGE_COMMAND|COVERAGE_EXTRA_FLAGS|CURL_OPTIONS|CUSTOM_(?:COVERAGE_EXCLUDE|ERROR_EXCEPTION|ERROR_MATCH|ERROR_POST_CONTEXT|ERROR_PRE_CONTEXT|MAXIMUM_FAILED_TEST_OUTPUT_SIZE|MAXIMUM_NUMBER_OF_(?:ERRORS|WARNINGS)|MAXIMUM_PASSED_TEST_OUTPUT_SIZE|MEMCHECK_IGNORE|POST_MEMCHECK|POST_TEST|PRE_MEMCHECK|PRE_TEST|TESTS_IGNORE|WARNING_EXCEPTION|WARNING_MATCH)|CVS_CHECKOUT|CVS_COMMAND|CVS_UPDATE_OPTIONS|DROP_LOCATION|DROP_METHOD|DROP_SITE|DROP_SITE_CDASH|DROP_SITE_PASSWORD|DROP_SITE_USER|EXTRA_COVERAGE_GLOB|GIT_COMMAND|GIT_INIT_SUBMODULES|GIT_UPDATE_CUSTOM|GIT_UPDATE_OPTIONS|HG_COMMAND|HG_UPDATE_OPTIONS|LABELS_FOR_SUBPROJECTS|MEMORYCHECK_(?:COMMAND|COMMAND_OPTIONS|SANITIZER_OPTIONS|SUPPRESSIONS_FILE|TYPE)|NIGHTLY_START_TIME|P4_CLIENT|P4_COMMAND|P4_OPTIONS|P4_UPDATE_OPTIONS|RUN_CURRENT_SCRIPT|SCP_COMMAND|SITE|SOURCE_DIRECTORY|SUBMIT_URL|SVN_COMMAND|SVN_OPTIONS|SVN_UPDATE_OPTIONS|TEST_LOAD|TEST_TIMEOUT|TRIGGER_SITE|UPDATE_COMMAND|UPDATE_OPTIONS|UPDATE_VERSION_ONLY|USE_LAUNCHERS)|CYGWIN|ENV|EXECUTABLE_OUTPUT_PATH|GHS-MULTI|IOS|LIBRARY_OUTPUT_PATH|MINGW|MSVC(?:10|11|12|14|60|70|71|80|90|_IDE|_TOOLSET_VERSION|_VERSION)?|MSYS|PROJECT_NAME|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE))\b/, | 2157 | 'property': /\b(?:cxx_\w+|(?:ARCHIVE_OUTPUT_(?:DIRECTORY|NAME)|COMPILE_DEFINITIONS|COMPILE_PDB_NAME|COMPILE_PDB_OUTPUT_DIRECTORY|EXCLUDE_FROM_DEFAULT_BUILD|IMPORTED_(?:IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_LANGUAGES|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|NO_SONAME|OBJECTS|SONAME)|INTERPROCEDURAL_OPTIMIZATION|LIBRARY_OUTPUT_DIRECTORY|LIBRARY_OUTPUT_NAME|LINK_FLAGS|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|MAP_IMPORTED_CONFIG|OSX_ARCHITECTURES|OUTPUT_NAME|PDB_NAME|PDB_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_NAME|STATIC_LIBRARY_FLAGS|VS_CSHARP|VS_DOTNET_REFERENCEPROP|VS_DOTNET_REFERENCE|VS_GLOBAL_SECTION_POST|VS_GLOBAL_SECTION_PRE|VS_GLOBAL|XCODE_ATTRIBUTE)_\w+|\w+_(?:CLANG_TIDY|COMPILER_LAUNCHER|CPPCHECK|CPPLINT|INCLUDE_WHAT_YOU_USE|OUTPUT_NAME|POSTFIX|VISIBILITY_PRESET)|ABSTRACT|ADDITIONAL_MAKE_CLEAN_FILES|ADVANCED|ALIASED_TARGET|ALLOW_DUPLICATE_CUSTOM_TARGETS|ANDROID_(?:ANT_ADDITIONAL_OPTIONS|API|API_MIN|ARCH|ASSETS_DIRECTORIES|GUI|JAR_DEPENDENCIES|NATIVE_LIB_DEPENDENCIES|NATIVE_LIB_DIRECTORIES|PROCESS_MAX|PROGUARD|PROGUARD_CONFIG_PATH|SECURE_PROPS_PATH|SKIP_ANT_STEP|STL_TYPE)|ARCHIVE_OUTPUT_DIRECTORY|ATTACHED_FILES|ATTACHED_FILES_ON_FAIL|AUTOGEN_(?:BUILD_DIR|ORIGIN_DEPENDS|PARALLEL|SOURCE_GROUP|TARGETS_FOLDER|TARGET_DEPENDS)|AUTOMOC|AUTOMOC_(?:COMPILER_PREDEFINES|DEPEND_FILTERS|EXECUTABLE|MACRO_NAMES|MOC_OPTIONS|SOURCE_GROUP|TARGETS_FOLDER)|AUTORCC|AUTORCC_EXECUTABLE|AUTORCC_OPTIONS|AUTORCC_SOURCE_GROUP|AUTOUIC|AUTOUIC_EXECUTABLE|AUTOUIC_OPTIONS|AUTOUIC_SEARCH_PATHS|BINARY_DIR|BUILDSYSTEM_TARGETS|BUILD_RPATH|BUILD_RPATH_USE_ORIGIN|BUILD_WITH_INSTALL_NAME_DIR|BUILD_WITH_INSTALL_RPATH|BUNDLE|BUNDLE_EXTENSION|CACHE_VARIABLES|CLEAN_NO_CUSTOM|COMMON_LANGUAGE_RUNTIME|COMPATIBLE_INTERFACE_(?:BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|COMPILE_(?:DEFINITIONS|FEATURES|FLAGS|OPTIONS|PDB_NAME|PDB_OUTPUT_DIRECTORY)|COST|CPACK_DESKTOP_SHORTCUTS|CPACK_NEVER_OVERWRITE|CPACK_PERMANENT|CPACK_STARTUP_SHORTCUTS|CPACK_START_MENU_SHORTCUTS|CPACK_WIX_ACL|CROSSCOMPILING_EMULATOR|CUDA_EXTENSIONS|CUDA_PTX_COMPILATION|CUDA_RESOLVE_DEVICE_SYMBOLS|CUDA_SEPARABLE_COMPILATION|CUDA_STANDARD|CUDA_STANDARD_REQUIRED|CXX_EXTENSIONS|CXX_STANDARD|CXX_STANDARD_REQUIRED|C_EXTENSIONS|C_STANDARD|C_STANDARD_REQUIRED|DEBUG_CONFIGURATIONS|DEFINE_SYMBOL|DEFINITIONS|DEPENDS|DEPLOYMENT_ADDITIONAL_FILES|DEPLOYMENT_REMOTE_DIRECTORY|DISABLED|DISABLED_FEATURES|ECLIPSE_EXTRA_CPROJECT_CONTENTS|ECLIPSE_EXTRA_NATURES|ENABLED_FEATURES|ENABLED_LANGUAGES|ENABLE_EXPORTS|ENVIRONMENT|EXCLUDE_FROM_ALL|EXCLUDE_FROM_DEFAULT_BUILD|EXPORT_NAME|EXPORT_PROPERTIES|EXTERNAL_OBJECT|EchoString|FAIL_REGULAR_EXPRESSION|FIND_LIBRARY_USE_LIB32_PATHS|FIND_LIBRARY_USE_LIB64_PATHS|FIND_LIBRARY_USE_LIBX32_PATHS|FIND_LIBRARY_USE_OPENBSD_VERSIONING|FIXTURES_CLEANUP|FIXTURES_REQUIRED|FIXTURES_SETUP|FOLDER|FRAMEWORK|Fortran_FORMAT|Fortran_MODULE_DIRECTORY|GENERATED|GENERATOR_FILE_NAME|GENERATOR_IS_MULTI_CONFIG|GHS_INTEGRITY_APP|GHS_NO_SOURCE_GROUP_FILE|GLOBAL_DEPENDS_DEBUG_MODE|GLOBAL_DEPENDS_NO_CYCLES|GNUtoMS|HAS_CXX|HEADER_FILE_ONLY|HELPSTRING|IMPLICIT_DEPENDS_INCLUDE_TRANSFORM|IMPORTED|IMPORTED_(?:COMMON_LANGUAGE_RUNTIME|CONFIGURATIONS|GLOBAL|IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_(?:LANGUAGES|LIBRARIES|MULTIPLICITY)|LOCATION|NO_SONAME|OBJECTS|SONAME)|IMPORT_PREFIX|IMPORT_SUFFIX|INCLUDE_DIRECTORIES|INCLUDE_REGULAR_EXPRESSION|INSTALL_NAME_DIR|INSTALL_RPATH|INSTALL_RPATH_USE_LINK_PATH|INTERFACE_(?:AUTOUIC_OPTIONS|COMPILE_DEFINITIONS|COMPILE_FEATURES|COMPILE_OPTIONS|INCLUDE_DIRECTORIES|LINK_DEPENDS|LINK_DIRECTORIES|LINK_LIBRARIES|LINK_OPTIONS|POSITION_INDEPENDENT_CODE|SOURCES|SYSTEM_INCLUDE_DIRECTORIES)|INTERPROCEDURAL_OPTIMIZATION|IN_TRY_COMPILE|IOS_INSTALL_COMBINED|JOB_POOLS|JOB_POOL_COMPILE|JOB_POOL_LINK|KEEP_EXTENSION|LABELS|LANGUAGE|LIBRARY_OUTPUT_DIRECTORY|LINKER_LANGUAGE|LINK_(?:DEPENDS|DEPENDS_NO_SHARED|DIRECTORIES|FLAGS|INTERFACE_LIBRARIES|INTERFACE_MULTIPLICITY|LIBRARIES|OPTIONS|SEARCH_END_STATIC|SEARCH_START_STATIC|WHAT_YOU_USE)|LISTFILE_STACK|LOCATION|MACOSX_BUNDLE|MACOSX_BUNDLE_INFO_PLIST|MACOSX_FRAMEWORK_INFO_PLIST|MACOSX_PACKAGE_LOCATION|MACOSX_RPATH|MACROS|MANUALLY_ADDED_DEPENDENCIES|MEASUREMENT|MODIFIED|NAME|NO_SONAME|NO_SYSTEM_FROM_IMPORTED|OBJECT_DEPENDS|OBJECT_OUTPUTS|OSX_ARCHITECTURES|OUTPUT_NAME|PACKAGES_FOUND|PACKAGES_NOT_FOUND|PARENT_DIRECTORY|PASS_REGULAR_EXPRESSION|PDB_NAME|PDB_OUTPUT_DIRECTORY|POSITION_INDEPENDENT_CODE|POST_INSTALL_SCRIPT|PREDEFINED_TARGETS_FOLDER|PREFIX|PRE_INSTALL_SCRIPT|PRIVATE_HEADER|PROCESSORS|PROCESSOR_AFFINITY|PROJECT_LABEL|PUBLIC_HEADER|REPORT_UNDEFINED_PROPERTIES|REQUIRED_FILES|RESOURCE|RESOURCE_LOCK|RULE_LAUNCH_COMPILE|RULE_LAUNCH_CUSTOM|RULE_LAUNCH_LINK|RULE_MESSAGES|RUNTIME_OUTPUT_DIRECTORY|RUN_SERIAL|SKIP_AUTOGEN|SKIP_AUTOMOC|SKIP_AUTORCC|SKIP_AUTOUIC|SKIP_BUILD_RPATH|SKIP_RETURN_CODE|SOURCES|SOURCE_DIR|SOVERSION|STATIC_LIBRARY_FLAGS|STATIC_LIBRARY_OPTIONS|STRINGS|SUBDIRECTORIES|SUFFIX|SYMBOLIC|TARGET_ARCHIVES_MAY_BE_SHARED_LIBS|TARGET_MESSAGES|TARGET_SUPPORTS_SHARED_LIBS|TESTS|TEST_INCLUDE_FILE|TEST_INCLUDE_FILES|TIMEOUT|TIMEOUT_AFTER_MATCH|TYPE|USE_FOLDERS|VALUE|VARIABLES|VERSION|VISIBILITY_INLINES_HIDDEN|VS_(?:CONFIGURATION_TYPE|COPY_TO_OUT_DIR|DEBUGGER_(?:COMMAND|COMMAND_ARGUMENTS|ENVIRONMENT|WORKING_DIRECTORY)|DEPLOYMENT_CONTENT|DEPLOYMENT_LOCATION|DOTNET_REFERENCES|DOTNET_REFERENCES_COPY_LOCAL|INCLUDE_IN_VSIX|IOT_STARTUP_TASK|KEYWORD|RESOURCE_GENERATOR|SCC_AUXPATH|SCC_LOCALPATH|SCC_PROJECTNAME|SCC_PROVIDER|SDK_REFERENCES|SHADER_(?:DISABLE_OPTIMIZATIONS|ENABLE_DEBUG|ENTRYPOINT|FLAGS|MODEL|OBJECT_FILE_NAME|OUTPUT_HEADER_FILE|TYPE|VARIABLE_NAME)|STARTUP_PROJECT|TOOL_OVERRIDE|USER_PROPS|WINRT_COMPONENT|WINRT_EXTENSIONS|WINRT_REFERENCES|XAML_TYPE)|WILL_FAIL|WIN32_EXECUTABLE|WINDOWS_EXPORT_ALL_SYMBOLS|WORKING_DIRECTORY|WRAP_EXCLUDE|XCODE_(?:EMIT_EFFECTIVE_PLATFORM_NAME|EXPLICIT_FILE_TYPE|FILE_ATTRIBUTES|LAST_KNOWN_FILE_TYPE|PRODUCT_TYPE|SCHEME_(?:ADDRESS_SANITIZER|ADDRESS_SANITIZER_USE_AFTER_RETURN|ARGUMENTS|DISABLE_MAIN_THREAD_CHECKER|DYNAMIC_LIBRARY_LOADS|DYNAMIC_LINKER_API_USAGE|ENVIRONMENT|EXECUTABLE|GUARD_MALLOC|MAIN_THREAD_CHECKER_STOP|MALLOC_GUARD_EDGES|MALLOC_SCRIBBLE|MALLOC_STACK|THREAD_SANITIZER(?:_STOP)?|UNDEFINED_BEHAVIOUR_SANITIZER(?:_STOP)?|ZOMBIE_OBJECTS))|XCTEST)\b/, |
| 2304 | property: | 2158 | 'keyword': /\b(?:add_compile_definitions|add_compile_options|add_custom_command|add_custom_target|add_definitions|add_dependencies|add_executable|add_library|add_link_options|add_subdirectory|add_test|aux_source_directory|break|build_command|build_name|cmake_host_system_information|cmake_minimum_required|cmake_parse_arguments|cmake_policy|configure_file|continue|create_test_sourcelist|ctest_build|ctest_configure|ctest_coverage|ctest_empty_binary_directory|ctest_memcheck|ctest_read_custom_files|ctest_run_script|ctest_sleep|ctest_start|ctest_submit|ctest_test|ctest_update|ctest_upload|define_property|else|elseif|enable_language|enable_testing|endforeach|endfunction|endif|endmacro|endwhile|exec_program|execute_process|export|export_library_dependencies|file|find_file|find_library|find_package|find_path|find_program|fltk_wrap_ui|foreach|function|get_cmake_property|get_directory_property|get_filename_component|get_property|get_source_file_property|get_target_property|get_test_property|if|include|include_directories|include_external_msproject|include_guard|include_regular_expression|install|install_files|install_programs|install_targets|link_directories|link_libraries|list|load_cache|load_command|macro|make_directory|mark_as_advanced|math|message|option|output_required_files|project|qt_wrap_cpp|qt_wrap_ui|remove|remove_definitions|return|separate_arguments|set|set_directory_properties|set_property|set_source_files_properties|set_target_properties|set_tests_properties|site_name|source_group|string|subdir_depends|subdirs|target_compile_definitions|target_compile_features|target_compile_options|target_include_directories|target_link_directories|target_link_libraries|target_link_options|target_sources|try_compile|try_run|unset|use_mangled_mesa|utility_source|variable_requires|variable_watch|while|write_file)(?=\s*\()\b/, |
| 2305 | /\b(?:cxx_\w+|(?:ARCHIVE_OUTPUT_(?:DIRECTORY|NAME)|COMPILE_DEFINITIONS|COMPILE_PDB_NAME|COMPILE_PDB_OUTPUT_DIRECTORY|EXCLUDE_FROM_DEFAULT_BUILD|IMPORTED_(?:IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_LANGUAGES|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|NO_SONAME|OBJECTS|SONAME)|INTERPROCEDURAL_OPTIMIZATION|LIBRARY_OUTPUT_DIRECTORY|LIBRARY_OUTPUT_NAME|LINK_FLAGS|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|MAP_IMPORTED_CONFIG|OSX_ARCHITECTURES|OUTPUT_NAME|PDB_NAME|PDB_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_NAME|STATIC_LIBRARY_FLAGS|VS_CSHARP|VS_DOTNET_REFERENCEPROP|VS_DOTNET_REFERENCE|VS_GLOBAL_SECTION_POST|VS_GLOBAL_SECTION_PRE|VS_GLOBAL|XCODE_ATTRIBUTE)_\w+|\w+_(?:CLANG_TIDY|COMPILER_LAUNCHER|CPPCHECK|CPPLINT|INCLUDE_WHAT_YOU_USE|OUTPUT_NAME|POSTFIX|VISIBILITY_PRESET)|ABSTRACT|ADDITIONAL_MAKE_CLEAN_FILES|ADVANCED|ALIASED_TARGET|ALLOW_DUPLICATE_CUSTOM_TARGETS|ANDROID_(?:ANT_ADDITIONAL_OPTIONS|API|API_MIN|ARCH|ASSETS_DIRECTORIES|GUI|JAR_DEPENDENCIES|NATIVE_LIB_DEPENDENCIES|NATIVE_LIB_DIRECTORIES|PROCESS_MAX|PROGUARD|PROGUARD_CONFIG_PATH|SECURE_PROPS_PATH|SKIP_ANT_STEP|STL_TYPE)|ARCHIVE_OUTPUT_DIRECTORY|ATTACHED_FILES|ATTACHED_FILES_ON_FAIL|AUTOGEN_(?:BUILD_DIR|ORIGIN_DEPENDS|PARALLEL|SOURCE_GROUP|TARGETS_FOLDER|TARGET_DEPENDS)|AUTOMOC|AUTOMOC_(?:COMPILER_PREDEFINES|DEPEND_FILTERS|EXECUTABLE|MACRO_NAMES|MOC_OPTIONS|SOURCE_GROUP|TARGETS_FOLDER)|AUTORCC|AUTORCC_EXECUTABLE|AUTORCC_OPTIONS|AUTORCC_SOURCE_GROUP|AUTOUIC|AUTOUIC_EXECUTABLE|AUTOUIC_OPTIONS|AUTOUIC_SEARCH_PATHS|BINARY_DIR|BUILDSYSTEM_TARGETS|BUILD_RPATH|BUILD_RPATH_USE_ORIGIN|BUILD_WITH_INSTALL_NAME_DIR|BUILD_WITH_INSTALL_RPATH|BUNDLE|BUNDLE_EXTENSION|CACHE_VARIABLES|CLEAN_NO_CUSTOM|COMMON_LANGUAGE_RUNTIME|COMPATIBLE_INTERFACE_(?:BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|COMPILE_(?:DEFINITIONS|FEATURES|FLAGS|OPTIONS|PDB_NAME|PDB_OUTPUT_DIRECTORY)|COST|CPACK_DESKTOP_SHORTCUTS|CPACK_NEVER_OVERWRITE|CPACK_PERMANENT|CPACK_STARTUP_SHORTCUTS|CPACK_START_MENU_SHORTCUTS|CPACK_WIX_ACL|CROSSCOMPILING_EMULATOR|CUDA_EXTENSIONS|CUDA_PTX_COMPILATION|CUDA_RESOLVE_DEVICE_SYMBOLS|CUDA_SEPARABLE_COMPILATION|CUDA_STANDARD|CUDA_STANDARD_REQUIRED|CXX_EXTENSIONS|CXX_STANDARD|CXX_STANDARD_REQUIRED|C_EXTENSIONS|C_STANDARD|C_STANDARD_REQUIRED|DEBUG_CONFIGURATIONS|DEFINE_SYMBOL|DEFINITIONS|DEPENDS|DEPLOYMENT_ADDITIONAL_FILES|DEPLOYMENT_REMOTE_DIRECTORY|DISABLED|DISABLED_FEATURES|ECLIPSE_EXTRA_CPROJECT_CONTENTS|ECLIPSE_EXTRA_NATURES|ENABLED_FEATURES|ENABLED_LANGUAGES|ENABLE_EXPORTS|ENVIRONMENT|EXCLUDE_FROM_ALL|EXCLUDE_FROM_DEFAULT_BUILD|EXPORT_NAME|EXPORT_PROPERTIES|EXTERNAL_OBJECT|EchoString|FAIL_REGULAR_EXPRESSION|FIND_LIBRARY_USE_LIB32_PATHS|FIND_LIBRARY_USE_LIB64_PATHS|FIND_LIBRARY_USE_LIBX32_PATHS|FIND_LIBRARY_USE_OPENBSD_VERSIONING|FIXTURES_CLEANUP|FIXTURES_REQUIRED|FIXTURES_SETUP|FOLDER|FRAMEWORK|Fortran_FORMAT|Fortran_MODULE_DIRECTORY|GENERATED|GENERATOR_FILE_NAME|GENERATOR_IS_MULTI_CONFIG|GHS_INTEGRITY_APP|GHS_NO_SOURCE_GROUP_FILE|GLOBAL_DEPENDS_DEBUG_MODE|GLOBAL_DEPENDS_NO_CYCLES|GNUtoMS|HAS_CXX|HEADER_FILE_ONLY|HELPSTRING|IMPLICIT_DEPENDS_INCLUDE_TRANSFORM|IMPORTED|IMPORTED_(?:COMMON_LANGUAGE_RUNTIME|CONFIGURATIONS|GLOBAL|IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_(?:LANGUAGES|LIBRARIES|MULTIPLICITY)|LOCATION|NO_SONAME|OBJECTS|SONAME)|IMPORT_PREFIX|IMPORT_SUFFIX|INCLUDE_DIRECTORIES|INCLUDE_REGULAR_EXPRESSION|INSTALL_NAME_DIR|INSTALL_RPATH|INSTALL_RPATH_USE_LINK_PATH|INTERFACE_(?:AUTOUIC_OPTIONS|COMPILE_DEFINITIONS|COMPILE_FEATURES|COMPILE_OPTIONS|INCLUDE_DIRECTORIES|LINK_DEPENDS|LINK_DIRECTORIES|LINK_LIBRARIES|LINK_OPTIONS|POSITION_INDEPENDENT_CODE|SOURCES|SYSTEM_INCLUDE_DIRECTORIES)|INTERPROCEDURAL_OPTIMIZATION|IN_TRY_COMPILE|IOS_INSTALL_COMBINED|JOB_POOLS|JOB_POOL_COMPILE|JOB_POOL_LINK|KEEP_EXTENSION|LABELS|LANGUAGE|LIBRARY_OUTPUT_DIRECTORY|LINKER_LANGUAGE|LINK_(?:DEPENDS|DEPENDS_NO_SHARED|DIRECTORIES|FLAGS|INTERFACE_LIBRARIES|INTERFACE_MULTIPLICITY|LIBRARIES|OPTIONS|SEARCH_END_STATIC|SEARCH_START_STATIC|WHAT_YOU_USE)|LISTFILE_STACK|LOCATION|MACOSX_BUNDLE|MACOSX_BUNDLE_INFO_PLIST|MACOSX_FRAMEWORK_INFO_PLIST|MACOSX_PACKAGE_LOCATION|MACOSX_RPATH|MACROS|MANUALLY_ADDED_DEPENDENCIES|MEASUREMENT|MODIFIED|NAME|NO_SONAME|NO_SYSTEM_FROM_IMPORTED|OBJECT_DEPENDS|OBJECT_OUTPUTS|OSX_ARCHITECTURES|OUTPUT_NAME|PACKAGES_FOUND|PACKAGES_NOT_FOUND|PARENT_DIRECTORY|PASS_REGULAR_EXPRESSION|PDB_NAME|PDB_OUTPUT_DIRECTORY|POSITION_INDEPENDENT_CODE|POST_INSTALL_SCRIPT|PREDEFINED_TARGETS_FOLDER|PREFIX|PRE_INSTALL_SCRIPT|PRIVATE_HEADER|PROCESSORS|PROCESSOR_AFFINITY|PROJECT_LABEL|PUBLIC_HEADER|REPORT_UNDEFINED_PROPERTIES|REQUIRED_FILES|RESOURCE|RESOURCE_LOCK|RULE_LAUNCH_COMPILE|RULE_LAUNCH_CUSTOM|RULE_LAUNCH_LINK|RULE_MESSAGES|RUNTIME_OUTPUT_DIRECTORY|RUN_SERIAL|SKIP_AUTOGEN|SKIP_AUTOMOC|SKIP_AUTORCC|SKIP_AUTOUIC|SKIP_BUILD_RPATH|SKIP_RETURN_CODE|SOURCES|SOURCE_DIR|SOVERSION|STATIC_LIBRARY_FLAGS|STATIC_LIBRARY_OPTIONS|STRINGS|SUBDIRECTORIES|SUFFIX|SYMBOLIC|TARGET_ARCHIVES_MAY_BE_SHARED_LIBS|TARGET_MESSAGES|TARGET_SUPPORTS_SHARED_LIBS|TESTS|TEST_INCLUDE_FILE|TEST_INCLUDE_FILES|TIMEOUT|TIMEOUT_AFTER_MATCH|TYPE|USE_FOLDERS|VALUE|VARIABLES|VERSION|VISIBILITY_INLINES_HIDDEN|VS_(?:CONFIGURATION_TYPE|COPY_TO_OUT_DIR|DEBUGGER_(?:COMMAND|COMMAND_ARGUMENTS|ENVIRONMENT|WORKING_DIRECTORY)|DEPLOYMENT_CONTENT|DEPLOYMENT_LOCATION|DOTNET_REFERENCES|DOTNET_REFERENCES_COPY_LOCAL|INCLUDE_IN_VSIX|IOT_STARTUP_TASK|KEYWORD|RESOURCE_GENERATOR|SCC_AUXPATH|SCC_LOCALPATH|SCC_PROJECTNAME|SCC_PROVIDER|SDK_REFERENCES|SHADER_(?:DISABLE_OPTIMIZATIONS|ENABLE_DEBUG|ENTRYPOINT|FLAGS|MODEL|OBJECT_FILE_NAME|OUTPUT_HEADER_FILE|TYPE|VARIABLE_NAME)|STARTUP_PROJECT|TOOL_OVERRIDE|USER_PROPS|WINRT_COMPONENT|WINRT_EXTENSIONS|WINRT_REFERENCES|XAML_TYPE)|WILL_FAIL|WIN32_EXECUTABLE|WINDOWS_EXPORT_ALL_SYMBOLS|WORKING_DIRECTORY|WRAP_EXCLUDE|XCODE_(?:EMIT_EFFECTIVE_PLATFORM_NAME|EXPLICIT_FILE_TYPE|FILE_ATTRIBUTES|LAST_KNOWN_FILE_TYPE|PRODUCT_TYPE|SCHEME_(?:ADDRESS_SANITIZER|ADDRESS_SANITIZER_USE_AFTER_RETURN|ARGUMENTS|DISABLE_MAIN_THREAD_CHECKER|DYNAMIC_LIBRARY_LOADS|DYNAMIC_LINKER_API_USAGE|ENVIRONMENT|EXECUTABLE|GUARD_MALLOC|MAIN_THREAD_CHECKER_STOP|MALLOC_GUARD_EDGES|MALLOC_SCRIBBLE|MALLOC_STACK|THREAD_SANITIZER(?:_STOP)?|UNDEFINED_BEHAVIOUR_SANITIZER(?:_STOP)?|ZOMBIE_OBJECTS))|XCTEST)\b/, | 2159 | 'boolean': /\b(?:FALSE|OFF|ON|TRUE)\b/, |
| 2306 | keyword: | 2160 | 'namespace': /\b(?:INTERFACE|PRIVATE|PROPERTIES|PUBLIC|SHARED|STATIC|TARGET_OBJECTS)\b/, |
| 2307 | /\b(?:add_compile_definitions|add_compile_options|add_custom_command|add_custom_target|add_definitions|add_dependencies|add_executable|add_library|add_link_options|add_subdirectory|add_test|aux_source_directory|break|build_command|build_name|cmake_host_system_information|cmake_minimum_required|cmake_parse_arguments|cmake_policy|configure_file|continue|create_test_sourcelist|ctest_build|ctest_configure|ctest_coverage|ctest_empty_binary_directory|ctest_memcheck|ctest_read_custom_files|ctest_run_script|ctest_sleep|ctest_start|ctest_submit|ctest_test|ctest_update|ctest_upload|define_property|else|elseif|enable_language|enable_testing|endforeach|endfunction|endif|endmacro|endwhile|exec_program|execute_process|export|export_library_dependencies|file|find_file|find_library|find_package|find_path|find_program|fltk_wrap_ui|foreach|function|get_cmake_property|get_directory_property|get_filename_component|get_property|get_source_file_property|get_target_property|get_test_property|if|include|include_directories|include_external_msproject|include_guard|include_regular_expression|install|install_files|install_programs|install_targets|link_directories|link_libraries|list|load_cache|load_command|macro|make_directory|mark_as_advanced|math|message|option|output_required_files|project|qt_wrap_cpp|qt_wrap_ui|remove|remove_definitions|return|separate_arguments|set|set_directory_properties|set_property|set_source_files_properties|set_target_properties|set_tests_properties|site_name|source_group|string|subdir_depends|subdirs|target_compile_definitions|target_compile_features|target_compile_options|target_include_directories|target_link_directories|target_link_libraries|target_link_options|target_sources|try_compile|try_run|unset|use_mangled_mesa|utility_source|variable_requires|variable_watch|while|write_file)(?=\s*\()\b/, | 2161 | 'operator': /\b(?:AND|DEFINED|EQUAL|GREATER|LESS|MATCHES|NOT|OR|STREQUAL|STRGREATER|STRLESS|VERSION_EQUAL|VERSION_GREATER|VERSION_LESS)\b/, |
| 2308 | boolean: /\b(?:FALSE|OFF|ON|TRUE)\b/, | 2162 | 'inserted': { |
| 2309 | namespace: | 2163 | pattern: /\b\w+::\w+\b/, |
| 2310 | /\b(?:INTERFACE|PRIVATE|PROPERTIES|PUBLIC|SHARED|STATIC|TARGET_OBJECTS)\b/, | 2164 | alias: 'class-name' |
| 2311 | operator: | 2165 | }, |
| 2312 | /\b(?:AND|DEFINED|EQUAL|GREATER|LESS|MATCHES|NOT|OR|STREQUAL|STRGREATER|STRLESS|VERSION_EQUAL|VERSION_GREATER|VERSION_LESS)\b/, | 2166 | 'number': /\b\d+(?:\.\d+)*\b/, |
| 2313 | inserted: { | 2167 | 'function': /\b[a-z_]\w*(?=\s*\()\b/i, |
| 2314 | pattern: /\b\w+::\w+\b/, | 2168 | 'punctuation': /[()>}]|\$[<{]/ |
| 2315 | alias: "class-name", | | |
| 2316 | }, | | |
| 2317 | number: /\b\d+(?:\.\d+)*\b/, | | |
| 2318 | function: /\b[a-z_]\w*(?=\s*\()\b/i, | | |
| 2319 | punctuation: /[()>}]|\$[<{]/, | | |
| 2320 | }; | 2169 | }; |
| 2321 | | 2170 | |
| 2322 | (function (Prism) { | 2171 | (function (Prism) { |
| 2323 | // Ignore comments starting with { to privilege string interpolation highlighting | 2172 | |
| 2324 | var comment = /#(?!\{).+/; | 2173 | // Ignore comments starting with { to privilege string interpolation highlighting |
| 2325 | var interpolation = { | 2174 | var comment = /#(?!\{).+/; |
| 2326 | pattern: /#\{[^}]+\}/, | 2175 | var interpolation = { |
| 2327 | alias: "variable", | 2176 | pattern: /#\{[^}]+\}/, |
| 2328 | }; | 2177 | alias: 'variable' |
| 2329 | | 2178 | }; |
| 2330 | Prism.languages.coffeescript = Prism.languages.extend("javascript", { | 2179 | |
| 2331 | comment: comment, | 2180 | Prism.languages.coffeescript = Prism.languages.extend('javascript', { |
| 2332 | string: [ | 2181 | 'comment': comment, |
| 2333 | // Strings are multiline | 2182 | 'string': [ |
| 2334 | { | 2183 | |
| 2335 | pattern: /'(?:\\[\s\S]|[^\\'])*'/, | 2184 | // Strings are multiline |
| 2336 | greedy: true, | 2185 | { |
| 2337 | }, | 2186 | pattern: /'(?:\\[\s\S]|[^\\'])*'/, |
| 2338 | | 2187 | greedy: true |
| 2339 | { | 2188 | }, |
| 2340 | // Strings are multiline | 2189 | |
| 2341 | pattern: /"(?:\\[\s\S]|[^\\"])*"/, | 2190 | { |
| 2342 | greedy: true, | 2191 | // Strings are multiline |
| 2343 | inside: { | 2192 | pattern: /"(?:\\[\s\S]|[^\\"])*"/, |
| 2344 | interpolation: interpolation, | 2193 | greedy: true, |
| 2345 | }, | 2194 | inside: { |
| 2346 | }, | 2195 | 'interpolation': interpolation |
| 2347 | ], | 2196 | } |
| 2348 | keyword: | 2197 | } |
| 2349 | /\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/, | 2198 | ], |
| 2350 | "class-member": { | 2199 | 'keyword': /\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/, |
| 2351 | pattern: /@(?!\d)\w+/, | 2200 | 'class-member': { |
| 2352 | alias: "variable", | 2201 | pattern: /@(?!\d)\w+/, |
| 2353 | }, | 2202 | alias: 'variable' |
| 2354 | }); | 2203 | } |
| 2355 | | 2204 | }); |
| 2356 | Prism.languages.insertBefore("coffeescript", "comment", { | 2205 | |
| 2357 | "multiline-comment": { | 2206 | Prism.languages.insertBefore('coffeescript', 'comment', { |
| 2358 | pattern: /###[\s\S]+?###/, | 2207 | 'multiline-comment': { |
| 2359 | alias: "comment", | 2208 | pattern: /###[\s\S]+?###/, |
| 2360 | }, | 2209 | alias: 'comment' |
| 2361 | | 2210 | }, |
| 2362 | // Block regexp can contain comments and interpolation | 2211 | |
| 2363 | "block-regex": { | 2212 | // Block regexp can contain comments and interpolation |
| 2364 | pattern: /\/{3}[\s\S]*?\/{3}/, | 2213 | 'block-regex': { |
| 2365 | alias: "regex", | 2214 | pattern: /\/{3}[\s\S]*?\/{3}/, |
| 2366 | inside: { | 2215 | alias: 'regex', |
| 2367 | comment: comment, | 2216 | inside: { |
| 2368 | interpolation: interpolation, | 2217 | 'comment': comment, |
| 2369 | }, | 2218 | 'interpolation': interpolation |
| 2370 | }, | 2219 | } |
| 2371 | }); | 2220 | } |
| 2372 | | 2221 | }); |
| 2373 | Prism.languages.insertBefore("coffeescript", "string", { | 2222 | |
| 2374 | "inline-javascript": { | 2223 | Prism.languages.insertBefore('coffeescript', 'string', { |
| 2375 | pattern: /`(?:\\[\s\S]|[^\\`])*`/, | 2224 | 'inline-javascript': { |
| 2376 | inside: { | 2225 | pattern: /`(?:\\[\s\S]|[^\\`])*`/, |
| 2377 | delimiter: { | 2226 | inside: { |
| 2378 | pattern: /^`|`$/, | 2227 | 'delimiter': { |
| 2379 | alias: "punctuation", | 2228 | pattern: /^`|`$/, |
| 2380 | }, | 2229 | alias: 'punctuation' |
| 2381 | script: { | 2230 | }, |
| 2382 | pattern: /[\s\S]+/, | 2231 | 'script': { |
| 2383 | alias: "language-javascript", | 2232 | pattern: /[\s\S]+/, |
| 2384 | inside: Prism.languages.javascript, | 2233 | alias: 'language-javascript', |
| 2385 | }, | 2234 | inside: Prism.languages.javascript |
| 2386 | }, | 2235 | } |
| 2387 | }, | 2236 | } |
| 2388 | | 2237 | }, |
| 2389 | // Block strings | 2238 | |
| 2390 | "multiline-string": [ | 2239 | // Block strings |
| 2391 | { | 2240 | 'multiline-string': [ |
| 2392 | pattern: /'''[\s\S]*?'''/, | 2241 | { |
| 2393 | greedy: true, | 2242 | pattern: /'''[\s\S]*?'''/, |
| 2394 | alias: "string", | 2243 | greedy: true, |
| 2395 | }, | 2244 | alias: 'string' |
| 2396 | { | 2245 | }, |
| 2397 | pattern: /"""[\s\S]*?"""/, | 2246 | { |
| 2398 | greedy: true, | 2247 | pattern: /"""[\s\S]*?"""/, |
| 2399 | alias: "string", | 2248 | greedy: true, |
| 2400 | inside: { | 2249 | alias: 'string', |
| 2401 | interpolation: interpolation, | 2250 | inside: { |
| 2402 | }, | 2251 | interpolation: interpolation |
| 2403 | }, | 2252 | } |
| 2404 | ], | 2253 | } |
| 2405 | }); | 2254 | ] |
| 2406 | | 2255 | |
| 2407 | Prism.languages.insertBefore("coffeescript", "keyword", { | 2256 | }); |
| 2408 | // Object property | 2257 | |
| 2409 | property: /(?!\d)\w+(?=\s*:(?!:))/, | 2258 | Prism.languages.insertBefore('coffeescript', 'keyword', { |
| 2410 | }); | 2259 | // Object property |
| 2411 | | 2260 | 'property': /(?!\d)\w+(?=\s*:(?!:))/ |
| 2412 | delete Prism.languages.coffeescript["template-string"]; | 2261 | }); |
| 2413 | | 2262 | |
| 2414 | Prism.languages.coffee = Prism.languages.coffeescript; | 2263 | delete Prism.languages.coffeescript['template-string']; |
| 2415 | })(Prism); | 2264 | |
| | 2265 | Prism.languages.coffee = Prism.languages.coffeescript; |
| | 2266 | }(Prism)); |
| 2416 | | 2267 | |
| 2417 | /** | 2268 | /** |
| 2418 | * Original by Samuel Flores | 2269 | * Original by Samuel Flores |
| @@ -2421,1968 +2272,1833 @@ Prism.languages.cmake = { · 2 unmodified lines |
| 2421 | * constant, builtin, variable, symbol, regex | 2272 | * constant, builtin, variable, symbol, regex |
| 2422 | */ | 2273 | */ |
| 2423 | (function (Prism) { | 2274 | (function (Prism) { |
| 2424 | Prism.languages.ruby = Prism.languages.extend("clike", { | 2275 | Prism.languages.ruby = Prism.languages.extend('clike', { |
| 2425 | comment: { | 2276 | 'comment': { |
| 2426 | pattern: /#.*|^=begin\s[\s\S]*?^=end/m, | 2277 | pattern: /#.*|^=begin\s[\s\S]*?^=end/m, |
| 2427 | greedy: true, | 2278 | greedy: true |
| 2428 | }, | 2279 | }, |
| 2429 | "class-name": { | 2280 | 'class-name': { |
| 2430 | pattern: | 2281 | pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/, |
| 2431 | /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/, | 2282 | lookbehind: true, |
| 2432 | lookbehind: true, | 2283 | inside: { |
| 2433 | inside: { | 2284 | 'punctuation': /[.\\]/ |
| 2434 | punctuation: /[.\\]/, | 2285 | } |
| 2435 | }, | 2286 | }, |
| 2436 | }, | 2287 | 'keyword': /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/, |
| 2437 | keyword: | 2288 | 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/, |
| 2438 | /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/, | 2289 | 'punctuation': /[(){}[\].,;]/, |
| 2439 | operator: | 2290 | }); |
| 2440 | /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/, | 2291 | |
| 2441 | punctuation: /[(){}[\].,;]/, | 2292 | Prism.languages.insertBefore('ruby', 'operator', { |
| 2442 | }); | 2293 | 'double-colon': { |
| 2443 | | 2294 | pattern: /::/, |
| 2444 | Prism.languages.insertBefore("ruby", "operator", { | 2295 | alias: 'punctuation' |
| 2445 | "double-colon": { | 2296 | }, |
| 2446 | pattern: /::/, | 2297 | }); |
| 2447 | alias: "punctuation", | 2298 | |
| 2448 | }, | 2299 | var interpolation = { |
| 2449 | }); | 2300 | pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/, |
| 2450 | | 2301 | lookbehind: true, |
| 2451 | var interpolation = { | 2302 | inside: { |
| 2452 | pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/, | 2303 | 'content': { |
| 2453 | lookbehind: true, | 2304 | pattern: /^(#\{)[\s\S]+(?=\}$)/, |
| 2454 | inside: { | 2305 | lookbehind: true, |
| 2455 | content: { | 2306 | inside: Prism.languages.ruby |
| 2456 | pattern: /^(#\{)[\s\S]+(?=\}$)/, | 2307 | }, |
| 2457 | lookbehind: true, | 2308 | 'delimiter': { |
| 2458 | inside: Prism.languages.ruby, | 2309 | pattern: /^#\{|\}$/, |
| 2459 | }, | 2310 | alias: 'punctuation' |
| 2460 | delimiter: { | 2311 | } |
| 2461 | pattern: /^#\{|\}$/, | 2312 | } |
| 2462 | alias: "punctuation", | 2313 | }; |
| 2463 | }, | 2314 | |
| 2464 | }, | 2315 | delete Prism.languages.ruby.function; |
| 2465 | }; | 2316 | |
| 2466 | | 2317 | var percentExpression = '(?:' + [ |
| 2467 | delete Prism.languages.ruby.function; | 2318 | /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, |
| 2468 | | 2319 | /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source, |
| 2469 | var percentExpression = | 2320 | /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source, |
| 2470 | "(?:" + | 2321 | /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source, |
| 2471 | [ | 2322 | /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source |
| 2472 | /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, | 2323 | ].join('|') + ')'; |
| 2473 | /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source, | 2324 | |
| 2474 | /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source, | 2325 | var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source; |
| 2475 | /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source, | 2326 | |
| 2476 | /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source, | 2327 | Prism.languages.insertBefore('ruby', 'keyword', { |
| 2477 | ].join("|") + | 2328 | 'regex-literal': [ |
| 2478 | ")"; | 2329 | { |
| 2479 | | 2330 | pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source), |
| 2480 | var symbolName = | 2331 | greedy: true, |
| 2481 | /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/ | 2332 | inside: { |
| 2482 | .source; | 2333 | 'interpolation': interpolation, |
| 2483 | | 2334 | 'regex': /[\s\S]+/ |
| 2484 | Prism.languages.insertBefore("ruby", "keyword", { | 2335 | } |
| 2485 | "regex-literal": [ | 2336 | }, |
| 2486 | { | 2337 | { |
| 2487 | pattern: RegExp( | 2338 | pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/, |
| 2488 | /%r/.source + percentExpression + /[egimnosux]{0,6}/.source, | 2339 | lookbehind: true, |
| 2489 | ), | 2340 | greedy: true, |
| 2490 | greedy: true, | 2341 | inside: { |
| 2491 | inside: { | 2342 | 'interpolation': interpolation, |
| 2492 | interpolation: interpolation, | 2343 | 'regex': /[\s\S]+/ |
| 2493 | regex: /[\s\S]+/, | 2344 | } |
| 2494 | }, | 2345 | } |
| 2495 | }, | 2346 | ], |
| 2496 | { | 2347 | 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/, |
| 2497 | pattern: | 2348 | 'symbol': [ |
| 2498 | /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/, | 2349 | { |
| 2499 | lookbehind: true, | 2350 | pattern: RegExp(/(^|[^:]):/.source + symbolName), |
| 2500 | greedy: true, | 2351 | lookbehind: true, |
| 2501 | inside: { | 2352 | greedy: true |
| 2502 | interpolation: interpolation, | 2353 | }, |
| 2503 | regex: /[\s\S]+/, | 2354 | { |
| 2504 | }, | 2355 | pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source), |
| 2505 | }, | 2356 | lookbehind: true, |
| 2506 | ], | 2357 | greedy: true |
| 2507 | variable: /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/, | 2358 | }, |
| 2508 | symbol: [ | 2359 | ], |
| 2509 | { | 2360 | 'method-definition': { |
| 2510 | pattern: RegExp(/(^|[^:]):/.source + symbolName), | 2361 | pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/, |
| 2511 | lookbehind: true, | 2362 | lookbehind: true, |
| 2512 | greedy: true, | 2363 | inside: { |
| 2513 | }, | 2364 | 'function': /\b\w+$/, |
| 2514 | { | 2365 | 'keyword': /^self\b/, |
| 2515 | pattern: RegExp( | 2366 | 'class-name': /^\w+/, |
| 2516 | /([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source, | 2367 | 'punctuation': /\./ |
| 2517 | ), | 2368 | } |
| 2518 | lookbehind: true, | 2369 | } |
| 2519 | greedy: true, | 2370 | }); |
| 2520 | }, | 2371 | |
| 2521 | ], | 2372 | Prism.languages.insertBefore('ruby', 'string', { |
| 2522 | "method-definition": { | 2373 | 'string-literal': [ |
| 2523 | pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/, | 2374 | { |
| 2524 | lookbehind: true, | 2375 | pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression), |
| 2525 | inside: { | 2376 | greedy: true, |
| 2526 | function: /\b\w+$/, | 2377 | inside: { |
| 2527 | keyword: /^self\b/, | 2378 | 'interpolation': interpolation, |
| 2528 | "class-name": /^\w+/, | 2379 | 'string': /[\s\S]+/ |
| 2529 | punctuation: /\./, | 2380 | } |
| 2530 | }, | 2381 | }, |
| 2531 | }, | 2382 | { |
| 2532 | }); | 2383 | pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/, |
| 2533 | | 2384 | greedy: true, |
| 2534 | Prism.languages.insertBefore("ruby", "string", { | 2385 | inside: { |
| 2535 | "string-literal": [ | 2386 | 'interpolation': interpolation, |
| 2536 | { | 2387 | 'string': /[\s\S]+/ |
| 2537 | pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression), | 2388 | } |
| 2538 | greedy: true, | 2389 | }, |
| 2539 | inside: { | 2390 | { |
| 2540 | interpolation: interpolation, | 2391 | pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i, |
| 2541 | string: /[\s\S]+/, | 2392 | alias: 'heredoc-string', |
| 2542 | }, | 2393 | greedy: true, |
| 2543 | }, | 2394 | inside: { |
| 2544 | { | 2395 | 'delimiter': { |
| 2545 | pattern: | 2396 | pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i, |
| 2546 | /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/, | 2397 | inside: { |
| 2547 | greedy: true, | 2398 | 'symbol': /\b\w+/, |
| 2548 | inside: { | 2399 | 'punctuation': /^<<[-~]?/ |
| 2549 | interpolation: interpolation, | 2400 | } |
| 2550 | string: /[\s\S]+/, | 2401 | }, |
| 2551 | }, | 2402 | 'interpolation': interpolation, |
| 2552 | }, | 2403 | 'string': /[\s\S]+/ |
| 2553 | { | 2404 | } |
| 2554 | pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i, | 2405 | }, |
| 2555 | alias: "heredoc-string", | 2406 | { |
| 2556 | greedy: true, | 2407 | pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i, |
| 2557 | inside: { | 2408 | alias: 'heredoc-string', |
| 2558 | delimiter: { | 2409 | greedy: true, |
| 2559 | pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i, | 2410 | inside: { |
| 2560 | inside: { | 2411 | 'delimiter': { |
| 2561 | symbol: /\b\w+/, | 2412 | pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i, |
| 2562 | punctuation: /^<<[-~]?/, | 2413 | inside: { |
| 2563 | }, | 2414 | 'symbol': /\b\w+/, |
| 2564 | }, | 2415 | 'punctuation': /^<<[-~]?'|'$/, |
| 2565 | interpolation: interpolation, | 2416 | } |
| 2566 | string: /[\s\S]+/, | 2417 | }, |
| 2567 | }, | 2418 | 'string': /[\s\S]+/ |
| 2568 | }, | 2419 | } |
| 2569 | { | 2420 | } |
| 2570 | pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i, | 2421 | ], |
| 2571 | alias: "heredoc-string", | 2422 | 'command-literal': [ |
| 2572 | greedy: true, | 2423 | { |
| 2573 | inside: { | 2424 | pattern: RegExp(/%x/.source + percentExpression), |
| 2574 | delimiter: { | 2425 | greedy: true, |
| 2575 | pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i, | 2426 | inside: { |
| 2576 | inside: { | 2427 | 'interpolation': interpolation, |
| 2577 | symbol: /\b\w+/, | 2428 | 'command': { |
| 2578 | punctuation: /^<<[-~]?'|'$/, | 2429 | pattern: /[\s\S]+/, |
| 2579 | }, | 2430 | alias: 'string' |
| 2580 | }, | 2431 | } |
| 2581 | string: /[\s\S]+/, | 2432 | } |
| 2582 | }, | 2433 | }, |
| 2583 | }, | 2434 | { |
| 2584 | ], | 2435 | pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/, |
| 2585 | "command-literal": [ | 2436 | greedy: true, |
| 2586 | { | 2437 | inside: { |
| 2587 | pattern: RegExp(/%x/.source + percentExpression), | 2438 | 'interpolation': interpolation, |
| 2588 | greedy: true, | 2439 | 'command': { |
| 2589 | inside: { | 2440 | pattern: /[\s\S]+/, |
| 2590 | interpolation: interpolation, | 2441 | alias: 'string' |
| 2591 | command: { | 2442 | } |
| 2592 | pattern: /[\s\S]+/, | 2443 | } |
| 2593 | alias: "string", | 2444 | } |
| 2594 | }, | 2445 | ] |
| 2595 | }, | 2446 | }); |
| 2596 | }, | 2447 | |
| 2597 | { | 2448 | delete Prism.languages.ruby.string; |
| 2598 | pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/, | 2449 | |
| 2599 | greedy: true, | 2450 | Prism.languages.insertBefore('ruby', 'number', { |
| 2600 | inside: { | 2451 | 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/, |
| 2601 | interpolation: interpolation, | 2452 | 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/ |
| 2602 | command: { | 2453 | }); |
| 2603 | pattern: /[\s\S]+/, | 2454 | |
| 2604 | alias: "string", | 2455 | Prism.languages.rb = Prism.languages.ruby; |
| 2605 | }, | 2456 | }(Prism)); |
| 2606 | }, | | |
| 2607 | }, | | |
| 2608 | ], | | |
| 2609 | }); | | |
| 2610 | | | |
| 2611 | delete Prism.languages.ruby.string; | | |
| 2612 | | | |
| 2613 | Prism.languages.insertBefore("ruby", "number", { | | |
| 2614 | builtin: | | |
| 2615 | /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/, | | |
| 2616 | constant: /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/, | | |
| 2617 | }); | | |
| 2618 | | | |
| 2619 | Prism.languages.rb = Prism.languages.ruby; | | |
| 2620 | })(Prism); | | |
| 2621 | | 2457 | |
| 2622 | (function (Prism) { | 2458 | (function (Prism) { |
| 2623 | Prism.languages.crystal = Prism.languages.extend("ruby", { | | |
| 2624 | keyword: [ | | |
| 2625 | /\b(?:__DIR__|__END_LINE__|__FILE__|__LINE__|abstract|alias|annotation|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|ifdef|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|ptr|require|rescue|return|select|self|sizeof|struct|super|then|type|typeof|undef|uninitialized|union|unless|until|when|while|with|yield)\b/, | | |
| 2626 | { | | |
| 2627 | pattern: /(\.\s*)(?:is_a|responds_to)\?/, | | |
| 2628 | lookbehind: true, | | |
| 2629 | }, | | |
| 2630 | ], | | |
| 2631 | number: | | |
| 2632 | /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/, | | |
| 2633 | operator: [/->/, Prism.languages.ruby.operator], | | |
| 2634 | punctuation: /[(){}[\].,;\\]/, | | |
| 2635 | }); | | |
| 2636 | | | |
| 2637 | Prism.languages.insertBefore("crystal", "string-literal", { | | |
| 2638 | attribute: { | | |
| 2639 | pattern: /@\[.*?\]/, | | |
| 2640 | inside: { | | |
| 2641 | delimiter: { | | |
| 2642 | pattern: /^@\[|\]$/, | | |
| 2643 | alias: "punctuation", | | |
| 2644 | }, | | |
| 2645 | attribute: { | | |
| 2646 | pattern: /^(\s*)\w+/, | | |
| 2647 | lookbehind: true, | | |
| 2648 | alias: "class-name", | | |
| 2649 | }, | | |
| 2650 | args: { | | |
| 2651 | pattern: /\S(?:[\s\S]*\S)?/, | | |
| 2652 | inside: Prism.languages.crystal, | | |
| 2653 | }, | | |
| 2654 | }, | | |
| 2655 | }, | | |
| 2656 | expansion: { | | |
| 2657 | pattern: /\{(?:\{.*?\}|%.*?%)\}/, | | |
| 2658 | inside: { | | |
| 2659 | content: { | | |
| 2660 | pattern: /^(\{.)[\s\S]+(?=.\}$)/, | | |
| 2661 | lookbehind: true, | | |
| 2662 | inside: Prism.languages.crystal, | | |
| 2663 | }, | | |
| 2664 | delimiter: { | | |
| 2665 | pattern: /^\{[\{%]|[\}%]\}$/, | | |
| 2666 | alias: "operator", | | |
| 2667 | }, | | |
| 2668 | }, | | |
| 2669 | }, | | |
| 2670 | char: { | | |
| 2671 | pattern: | | |
| 2672 | /'(?:[^\\\r\n]{1,2}|\\(?:.|u(?:[A-Fa-f0-9]{1,4}|\{[A-Fa-f0-9]{1,6}\})))'/, | | |
| 2673 | greedy: true, | | |
| 2674 | }, | | |
| 2675 | }); | | |
| 2676 | })(Prism); | | |
| 2677 | | | |
| 2678 | Prism.languages.d = Prism.languages.extend("clike", { | | |
| 2679 | comment: [ | | |
| 2680 | { | | |
| 2681 | // Shebang | | |
| 2682 | pattern: /^\s*#!.+/, | | |
| 2683 | greedy: true, | | |
| 2684 | }, | | |
| 2685 | { | | |
| 2686 | pattern: RegExp( | | |
| 2687 | /(^|[^\\])/.source + | | |
| 2688 | "(?:" + | | |
| 2689 | [ | | |
| 2690 | // /+ comment +/ | | |
| 2691 | // Allow one level of nesting | | |
| 2692 | /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source, | | |
| 2693 | // // comment | | |
| 2694 | /\/\/.*/.source, | | |
| 2695 | // /* comment */ | | |
| 2696 | /\/\*[\s\S]*?\*\//.source, | | |
| 2697 | ].join("|") + | | |
| 2698 | ")", | | |
| 2699 | ), | | |
| 2700 | lookbehind: true, | | |
| 2701 | greedy: true, | | |
| 2702 | }, | | |
| 2703 | ], | | |
| 2704 | string: [ | | |
| 2705 | { | | |
| 2706 | pattern: RegExp( | | |
| 2707 | [ | | |
| 2708 | // r"", x"" | | |
| 2709 | /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source, | | |
| 2710 | | | |
| 2711 | // q"[]", q"()", q"<>", q"{}" | | |
| 2712 | /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source, | | |
| 2713 | | | |
| 2714 | // q"IDENT | | |
| 2715 | // ... | | |