plugin.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.3.0 (2020-05-21)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var noop = function () {
  13. };
  14. var constant = function (value) {
  15. return function () {
  16. return value;
  17. };
  18. };
  19. var never = constant(false);
  20. var always = constant(true);
  21. var none = function () {
  22. return NONE;
  23. };
  24. var NONE = function () {
  25. var eq = function (o) {
  26. return o.isNone();
  27. };
  28. var call = function (thunk) {
  29. return thunk();
  30. };
  31. var id = function (n) {
  32. return n;
  33. };
  34. var me = {
  35. fold: function (n, _s) {
  36. return n();
  37. },
  38. is: never,
  39. isSome: never,
  40. isNone: always,
  41. getOr: id,
  42. getOrThunk: call,
  43. getOrDie: function (msg) {
  44. throw new Error(msg || 'error: getOrDie called on none.');
  45. },
  46. getOrNull: constant(null),
  47. getOrUndefined: constant(undefined),
  48. or: id,
  49. orThunk: call,
  50. map: none,
  51. each: noop,
  52. bind: none,
  53. exists: never,
  54. forall: always,
  55. filter: none,
  56. equals: eq,
  57. equals_: eq,
  58. toArray: function () {
  59. return [];
  60. },
  61. toString: constant('none()')
  62. };
  63. return me;
  64. }();
  65. var some = function (a) {
  66. var constant_a = constant(a);
  67. var self = function () {
  68. return me;
  69. };
  70. var bind = function (f) {
  71. return f(a);
  72. };
  73. var me = {
  74. fold: function (n, s) {
  75. return s(a);
  76. },
  77. is: function (v) {
  78. return a === v;
  79. },
  80. isSome: always,
  81. isNone: never,
  82. getOr: constant_a,
  83. getOrThunk: constant_a,
  84. getOrDie: constant_a,
  85. getOrNull: constant_a,
  86. getOrUndefined: constant_a,
  87. or: self,
  88. orThunk: self,
  89. map: function (f) {
  90. return some(f(a));
  91. },
  92. each: function (f) {
  93. f(a);
  94. },
  95. bind: bind,
  96. exists: bind,
  97. forall: bind,
  98. filter: function (f) {
  99. return f(a) ? me : NONE;
  100. },
  101. toArray: function () {
  102. return [a];
  103. },
  104. toString: function () {
  105. return 'some(' + a + ')';
  106. },
  107. equals: function (o) {
  108. return o.is(a);
  109. },
  110. equals_: function (o, elementEq) {
  111. return o.fold(never, function (b) {
  112. return elementEq(a, b);
  113. });
  114. }
  115. };
  116. return me;
  117. };
  118. var from = function (value) {
  119. return value === null || value === undefined ? NONE : some(value);
  120. };
  121. var Option = {
  122. some: some,
  123. none: none,
  124. from: from
  125. };
  126. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  127. function isCodeSample(elm) {
  128. return elm && elm.nodeName === 'PRE' && elm.className.indexOf('language-') !== -1;
  129. }
  130. function trimArg(predicateFn) {
  131. return function (arg1, arg2) {
  132. return predicateFn(arg2);
  133. };
  134. }
  135. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  136. var exports$1 = {}, module = { exports: exports$1 }, global$2 = {};
  137. (function (define, exports, module, require) {
  138. var oldprism = window.Prism;
  139. window.Prism = { manual: true };
  140. (function (f) {
  141. if (typeof exports === 'object' && typeof module !== 'undefined') {
  142. module.exports = f();
  143. } else if (typeof define === 'function' && define.amd) {
  144. define([], f);
  145. } else {
  146. var g;
  147. if (typeof window !== 'undefined') {
  148. g = window;
  149. } else if (typeof global$2 !== 'undefined') {
  150. g = global$2;
  151. } else if (typeof self !== 'undefined') {
  152. g = self;
  153. } else {
  154. g = this;
  155. }
  156. g.EphoxContactWrapper = f();
  157. }
  158. }(function () {
  159. return function () {
  160. function r(e, n, t) {
  161. function o(i, f) {
  162. if (!n[i]) {
  163. if (!e[i]) {
  164. var c = 'function' == typeof require && require;
  165. if (!f && c)
  166. return c(i, !0);
  167. if (u)
  168. return u(i, !0);
  169. var a = new Error('Cannot find module \'' + i + '\'');
  170. throw a.code = 'MODULE_NOT_FOUND', a;
  171. }
  172. var p = n[i] = { exports: {} };
  173. e[i][0].call(p.exports, function (r) {
  174. var n = e[i][1][r];
  175. return o(n || r);
  176. }, p, p.exports, r, e, n, t);
  177. }
  178. return n[i].exports;
  179. }
  180. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  181. o(t[i]);
  182. return o;
  183. }
  184. return r;
  185. }()({
  186. 1: [
  187. function (require, module, exports) {
  188. Prism.languages.c = Prism.languages.extend('clike', {
  189. 'class-name': {
  190. pattern: /(\b(?:enum|struct)\s+)\w+/,
  191. lookbehind: true
  192. },
  193. 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
  194. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/,
  195. 'number': /(?:\b0x(?:[\da-f]+\.?[\da-f]*|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i
  196. });
  197. Prism.languages.insertBefore('c', 'string', {
  198. 'macro': {
  199. pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,
  200. lookbehind: true,
  201. alias: 'property',
  202. inside: {
  203. 'string': {
  204. pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,
  205. lookbehind: true
  206. },
  207. 'directive': {
  208. pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  209. lookbehind: true,
  210. alias: 'keyword'
  211. }
  212. }
  213. },
  214. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  215. });
  216. delete Prism.languages.c['boolean'];
  217. },
  218. {}
  219. ],
  220. 2: [
  221. function (require, module, exports) {
  222. Prism.languages.clike = {
  223. 'comment': [
  224. {
  225. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  226. lookbehind: true
  227. },
  228. {
  229. pattern: /(^|[^\\:])\/\/.*/,
  230. lookbehind: true,
  231. greedy: true
  232. }
  233. ],
  234. 'string': {
  235. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  236. greedy: true
  237. },
  238. 'class-name': {
  239. pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
  240. lookbehind: true,
  241. inside: { 'punctuation': /[.\\]/ }
  242. },
  243. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  244. 'boolean': /\b(?:true|false)\b/,
  245. 'function': /\w+(?=\()/,
  246. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  247. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  248. 'punctuation': /[{}[\];(),.:]/
  249. };
  250. },
  251. {}
  252. ],
  253. 3: [
  254. function (require, module, exports) {
  255. (function (global) {
  256. var _self = typeof window !== 'undefined' ? window : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : {};
  257. var Prism = function (_self) {
  258. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  259. var uniqueId = 0;
  260. var _ = {
  261. manual: _self.Prism && _self.Prism.manual,
  262. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  263. util: {
  264. encode: function (tokens) {
  265. if (tokens instanceof Token) {
  266. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  267. } else if (Array.isArray(tokens)) {
  268. return tokens.map(_.util.encode);
  269. } else {
  270. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  271. }
  272. },
  273. type: function (o) {
  274. return Object.prototype.toString.call(o).slice(8, -1);
  275. },
  276. objId: function (obj) {
  277. if (!obj['__id']) {
  278. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  279. }
  280. return obj['__id'];
  281. },
  282. clone: function deepClone(o, visited) {
  283. var clone, id, type = _.util.type(o);
  284. visited = visited || {};
  285. switch (type) {
  286. case 'Object':
  287. id = _.util.objId(o);
  288. if (visited[id]) {
  289. return visited[id];
  290. }
  291. clone = {};
  292. visited[id] = clone;
  293. for (var key in o) {
  294. if (o.hasOwnProperty(key)) {
  295. clone[key] = deepClone(o[key], visited);
  296. }
  297. }
  298. return clone;
  299. case 'Array':
  300. id = _.util.objId(o);
  301. if (visited[id]) {
  302. return visited[id];
  303. }
  304. clone = [];
  305. visited[id] = clone;
  306. o.forEach(function (v, i) {
  307. clone[i] = deepClone(v, visited);
  308. });
  309. return clone;
  310. default:
  311. return o;
  312. }
  313. },
  314. getLanguage: function (element) {
  315. while (element && !lang.test(element.className)) {
  316. element = element.parentElement;
  317. }
  318. if (element) {
  319. return (element.className.match(lang) || [
  320. ,
  321. 'none'
  322. ])[1].toLowerCase();
  323. }
  324. return 'none';
  325. },
  326. currentScript: function () {
  327. if (typeof document === 'undefined') {
  328. return null;
  329. }
  330. if ('currentScript' in document) {
  331. return document.currentScript;
  332. }
  333. try {
  334. throw new Error();
  335. } catch (err) {
  336. var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
  337. if (src) {
  338. var scripts = document.getElementsByTagName('script');
  339. for (var i in scripts) {
  340. if (scripts[i].src == src) {
  341. return scripts[i];
  342. }
  343. }
  344. }
  345. return null;
  346. }
  347. }
  348. },
  349. languages: {
  350. extend: function (id, redef) {
  351. var lang = _.util.clone(_.languages[id]);
  352. for (var key in redef) {
  353. lang[key] = redef[key];
  354. }
  355. return lang;
  356. },
  357. insertBefore: function (inside, before, insert, root) {
  358. root = root || _.languages;
  359. var grammar = root[inside];
  360. var ret = {};
  361. for (var token in grammar) {
  362. if (grammar.hasOwnProperty(token)) {
  363. if (token == before) {
  364. for (var newToken in insert) {
  365. if (insert.hasOwnProperty(newToken)) {
  366. ret[newToken] = insert[newToken];
  367. }
  368. }
  369. }
  370. if (!insert.hasOwnProperty(token)) {
  371. ret[token] = grammar[token];
  372. }
  373. }
  374. }
  375. var old = root[inside];
  376. root[inside] = ret;
  377. _.languages.DFS(_.languages, function (key, value) {
  378. if (value === old && key != inside) {
  379. this[key] = ret;
  380. }
  381. });
  382. return ret;
  383. },
  384. DFS: function DFS(o, callback, type, visited) {
  385. visited = visited || {};
  386. var objId = _.util.objId;
  387. for (var i in o) {
  388. if (o.hasOwnProperty(i)) {
  389. callback.call(o, i, o[i], type || i);
  390. var property = o[i], propertyType = _.util.type(property);
  391. if (propertyType === 'Object' && !visited[objId(property)]) {
  392. visited[objId(property)] = true;
  393. DFS(property, callback, null, visited);
  394. } else if (propertyType === 'Array' && !visited[objId(property)]) {
  395. visited[objId(property)] = true;
  396. DFS(property, callback, i, visited);
  397. }
  398. }
  399. }
  400. }
  401. },
  402. plugins: {},
  403. highlightAll: function (async, callback) {
  404. _.highlightAllUnder(document, async, callback);
  405. },
  406. highlightAllUnder: function (container, async, callback) {
  407. var env = {
  408. callback: callback,
  409. container: container,
  410. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  411. };
  412. _.hooks.run('before-highlightall', env);
  413. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  414. _.hooks.run('before-all-elements-highlight', env);
  415. for (var i = 0, element; element = env.elements[i++];) {
  416. _.highlightElement(element, async === true, env.callback);
  417. }
  418. },
  419. highlightElement: function (element, async, callback) {
  420. var language = _.util.getLanguage(element);
  421. var grammar = _.languages[language];
  422. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  423. var parent = element.parentNode;
  424. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  425. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  426. }
  427. var code = element.textContent;
  428. var env = {
  429. element: element,
  430. language: language,
  431. grammar: grammar,
  432. code: code
  433. };
  434. function insertHighlightedCode(highlightedCode) {
  435. env.highlightedCode = highlightedCode;
  436. _.hooks.run('before-insert', env);
  437. env.element.innerHTML = env.highlightedCode;
  438. _.hooks.run('after-highlight', env);
  439. _.hooks.run('complete', env);
  440. callback && callback.call(env.element);
  441. }
  442. _.hooks.run('before-sanity-check', env);
  443. if (!env.code) {
  444. _.hooks.run('complete', env);
  445. callback && callback.call(env.element);
  446. return;
  447. }
  448. _.hooks.run('before-highlight', env);
  449. if (!env.grammar) {
  450. insertHighlightedCode(_.util.encode(env.code));
  451. return;
  452. }
  453. if (async && _self.Worker) {
  454. var worker = new Worker(_.filename);
  455. worker.onmessage = function (evt) {
  456. insertHighlightedCode(evt.data);
  457. };
  458. worker.postMessage(JSON.stringify({
  459. language: env.language,
  460. code: env.code,
  461. immediateClose: true
  462. }));
  463. } else {
  464. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  465. }
  466. },
  467. highlight: function (text, grammar, language) {
  468. var env = {
  469. code: text,
  470. grammar: grammar,
  471. language: language
  472. };
  473. _.hooks.run('before-tokenize', env);
  474. env.tokens = _.tokenize(env.code, env.grammar);
  475. _.hooks.run('after-tokenize', env);
  476. return Token.stringify(_.util.encode(env.tokens), env.language);
  477. },
  478. matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
  479. for (var token in grammar) {
  480. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  481. continue;
  482. }
  483. var patterns = grammar[token];
  484. patterns = Array.isArray(patterns) ? patterns : [patterns];
  485. for (var j = 0; j < patterns.length; ++j) {
  486. if (target && target == token + ',' + j) {
  487. return;
  488. }
  489. var pattern = patterns[j], inside = pattern.inside, lookbehind = !!pattern.lookbehind, greedy = !!pattern.greedy, lookbehindLength = 0, alias = pattern.alias;
  490. if (greedy && !pattern.pattern.global) {
  491. var flags = pattern.pattern.toString().match(/[imsuy]*$/)[0];
  492. pattern.pattern = RegExp(pattern.pattern.source, flags + 'g');
  493. }
  494. pattern = pattern.pattern || pattern;
  495. for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
  496. var str = strarr[i];
  497. if (strarr.length > text.length) {
  498. return;
  499. }
  500. if (str instanceof Token) {
  501. continue;
  502. }
  503. if (greedy && i != strarr.length - 1) {
  504. pattern.lastIndex = pos;
  505. var match = pattern.exec(text);
  506. if (!match) {
  507. break;
  508. }
  509. var from = match.index + (lookbehind && match[1] ? match[1].length : 0), to = match.index + match[0].length, k = i, p = pos;
  510. for (var len = strarr.length; k < len && (p < to || !strarr[k].type && !strarr[k - 1].greedy); ++k) {
  511. p += strarr[k].length;
  512. if (from >= p) {
  513. ++i;
  514. pos = p;
  515. }
  516. }
  517. if (strarr[i] instanceof Token) {
  518. continue;
  519. }
  520. delNum = k - i;
  521. str = text.slice(pos, p);
  522. match.index -= pos;
  523. } else {
  524. pattern.lastIndex = 0;
  525. var match = pattern.exec(str), delNum = 1;
  526. }
  527. if (!match) {
  528. if (oneshot) {
  529. break;
  530. }
  531. continue;
  532. }
  533. if (lookbehind) {
  534. lookbehindLength = match[1] ? match[1].length : 0;
  535. }
  536. var from = match.index + lookbehindLength, match = match[0].slice(lookbehindLength), to = from + match.length, before = str.slice(0, from), after = str.slice(to);
  537. var args = [
  538. i,
  539. delNum
  540. ];
  541. if (before) {
  542. ++i;
  543. pos += before.length;
  544. args.push(before);
  545. }
  546. var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy);
  547. args.push(wrapped);
  548. if (after) {
  549. args.push(after);
  550. }
  551. Array.prototype.splice.apply(strarr, args);
  552. if (delNum != 1)
  553. _.matchGrammar(text, strarr, grammar, i, pos, true, token + ',' + j);
  554. if (oneshot)
  555. break;
  556. }
  557. }
  558. }
  559. },
  560. tokenize: function (text, grammar) {
  561. var strarr = [text];
  562. var rest = grammar.rest;
  563. if (rest) {
  564. for (var token in rest) {
  565. grammar[token] = rest[token];
  566. }
  567. delete grammar.rest;
  568. }
  569. _.matchGrammar(text, strarr, grammar, 0, 0, false);
  570. return strarr;
  571. },
  572. hooks: {
  573. all: {},
  574. add: function (name, callback) {
  575. var hooks = _.hooks.all;
  576. hooks[name] = hooks[name] || [];
  577. hooks[name].push(callback);
  578. },
  579. run: function (name, env) {
  580. var callbacks = _.hooks.all[name];
  581. if (!callbacks || !callbacks.length) {
  582. return;
  583. }
  584. for (var i = 0, callback; callback = callbacks[i++];) {
  585. callback(env);
  586. }
  587. }
  588. },
  589. Token: Token
  590. };
  591. _self.Prism = _;
  592. function Token(type, content, alias, matchedStr, greedy) {
  593. this.type = type;
  594. this.content = content;
  595. this.alias = alias;
  596. this.length = (matchedStr || '').length | 0;
  597. this.greedy = !!greedy;
  598. }
  599. Token.stringify = function (o, language) {
  600. if (typeof o == 'string') {
  601. return o;
  602. }
  603. if (Array.isArray(o)) {
  604. return o.map(function (element) {
  605. return Token.stringify(element, language);
  606. }).join('');
  607. }
  608. var env = {
  609. type: o.type,
  610. content: Token.stringify(o.content, language),
  611. tag: 'span',
  612. classes: [
  613. 'token',
  614. o.type
  615. ],
  616. attributes: {},
  617. language: language
  618. };
  619. if (o.alias) {
  620. var aliases = Array.isArray(o.alias) ? o.alias : [o.alias];
  621. Array.prototype.push.apply(env.classes, aliases);
  622. }
  623. _.hooks.run('wrap', env);
  624. var attributes = Object.keys(env.attributes).map(function (name) {
  625. return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  626. }).join(' ');
  627. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
  628. };
  629. if (!_self.document) {
  630. if (!_self.addEventListener) {
  631. return _;
  632. }
  633. if (!_.disableWorkerMessageHandler) {
  634. _self.addEventListener('message', function (evt) {
  635. var message = JSON.parse(evt.data), lang = message.language, code = message.code, immediateClose = message.immediateClose;
  636. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  637. if (immediateClose) {
  638. _self.close();
  639. }
  640. }, false);
  641. }
  642. return _;
  643. }
  644. var script = _.util.currentScript();
  645. if (script) {
  646. _.filename = script.src;
  647. if (script.hasAttribute('data-manual')) {
  648. _.manual = true;
  649. }
  650. }
  651. if (!_.manual) {
  652. var highlightAutomaticallyCallback = function () {
  653. if (!_.manual) {
  654. _.highlightAll();
  655. }
  656. };
  657. var readyState = document.readyState;
  658. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  659. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  660. } else {
  661. if (window.requestAnimationFrame) {
  662. window.requestAnimationFrame(highlightAutomaticallyCallback);
  663. } else {
  664. window.setTimeout(highlightAutomaticallyCallback, 16);
  665. }
  666. }
  667. }
  668. return _;
  669. }(_self);
  670. if (typeof module !== 'undefined' && module.exports) {
  671. module.exports = Prism;
  672. }
  673. if (typeof global !== 'undefined') {
  674. global.Prism = Prism;
  675. }
  676. }.call(this, typeof global$2 !== 'undefined' ? global$2 : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {}));
  677. },
  678. {}
  679. ],
  680. 4: [
  681. function (require, module, exports) {
  682. Prism.languages.cpp = Prism.languages.extend('c', {
  683. 'class-name': {
  684. pattern: /(\b(?:class|enum|struct)\s+)\w+/,
  685. lookbehind: true
  686. },
  687. 'keyword': /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
  688. 'number': {
  689. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,
  690. greedy: true
  691. },
  692. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  693. 'boolean': /\b(?:true|false)\b/
  694. });
  695. Prism.languages.insertBefore('cpp', 'string', {
  696. 'raw-string': {
  697. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  698. alias: 'string',
  699. greedy: true
  700. }
  701. });
  702. },
  703. {}
  704. ],
  705. 5: [
  706. function (require, module, exports) {
  707. Prism.languages.csharp = Prism.languages.extend('clike', {
  708. 'keyword': /\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,
  709. 'string': [
  710. {
  711. pattern: /@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,
  712. greedy: true
  713. },
  714. {
  715. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,
  716. greedy: true
  717. }
  718. ],
  719. 'class-name': [
  720. {
  721. pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=\s+\w+)/,
  722. inside: { punctuation: /\./ }
  723. },
  724. {
  725. pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
  726. lookbehind: true,
  727. inside: { punctuation: /\./ }
  728. },
  729. {
  730. pattern: /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
  731. lookbehind: true,
  732. inside: { punctuation: /\./ }
  733. },
  734. {
  735. pattern: /((?:\b(?:class|interface|new)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
  736. lookbehind: true,
  737. inside: { punctuation: /\./ }
  738. }
  739. ],
  740. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i,
  741. 'operator': />>=?|<<=?|[-=]>|([-+&|?])\1|~|[-+*/%&|^!=<>]=?/,
  742. 'punctuation': /\?\.?|::|[{}[\];(),.:]/
  743. });
  744. Prism.languages.insertBefore('csharp', 'class-name', {
  745. 'generic-method': {
  746. pattern: /\w+\s*<[^>\r\n]+?>\s*(?=\()/,
  747. inside: {
  748. function: /^\w+/,
  749. 'class-name': {
  750. pattern: /\b[A-Z]\w*(?:\.\w+)*\b/,
  751. inside: { punctuation: /\./ }
  752. },
  753. keyword: Prism.languages.csharp.keyword,
  754. punctuation: /[<>(),.:]/
  755. }
  756. },
  757. 'preprocessor': {
  758. pattern: /(^\s*)#.*/m,
  759. lookbehind: true,
  760. alias: 'property',
  761. inside: {
  762. 'directive': {
  763. pattern: /(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
  764. lookbehind: true,
  765. alias: 'keyword'
  766. }
  767. }
  768. }
  769. });
  770. Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
  771. },
  772. {}
  773. ],
  774. 6: [
  775. function (require, module, exports) {
  776. (function (Prism) {
  777. var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
  778. Prism.languages.css = {
  779. 'comment': /\/\*[\s\S]*?\*\//,
  780. 'atrule': {
  781. pattern: /@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,
  782. inside: { 'rule': /@[\w-]+/ }
  783. },
  784. 'url': {
  785. pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
  786. inside: {
  787. 'function': /^url/i,
  788. 'punctuation': /^\(|\)$/
  789. }
  790. },
  791. 'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
  792. 'string': {
  793. pattern: string,
  794. greedy: true
  795. },
  796. 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
  797. 'important': /!important\b/i,
  798. 'function': /[-a-z0-9]+(?=\()/i,
  799. 'punctuation': /[(){};:,]/
  800. };
  801. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  802. var markup = Prism.languages.markup;
  803. if (markup) {
  804. markup.tag.addInlined('style', 'css');
  805. Prism.languages.insertBefore('inside', 'attr-value', {
  806. 'style-attr': {
  807. pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
  808. inside: {
  809. 'attr-name': {
  810. pattern: /^\s*style/i,
  811. inside: markup.tag.inside
  812. },
  813. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  814. 'attr-value': {
  815. pattern: /.+/i,
  816. inside: Prism.languages.css
  817. }
  818. },
  819. alias: 'language-css'
  820. }
  821. }, markup.tag);
  822. }
  823. }(Prism));
  824. },
  825. {}
  826. ],
  827. 7: [
  828. function (require, module, exports) {
  829. (function (Prism) {
  830. var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|null|open|opens|package|private|protected|provides|public|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  831. var className = /\b[A-Z](?:\w*[a-z]\w*)?\b/;
  832. Prism.languages.java = Prism.languages.extend('clike', {
  833. 'class-name': [
  834. className,
  835. /\b[A-Z]\w*(?=\s+\w+\s*[;,=())])/
  836. ],
  837. 'keyword': keywords,
  838. 'function': [
  839. Prism.languages.clike.function,
  840. {
  841. pattern: /(\:\:)[a-z_]\w*/,
  842. lookbehind: true
  843. }
  844. ],
  845. 'number': /\b0b[01][01_]*L?\b|\b0x[\da-f_]*\.?[\da-f_p+-]+\b|(?:\b\d[\d_]*\.?[\d_]*|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
  846. 'operator': {
  847. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  848. lookbehind: true
  849. }
  850. });
  851. Prism.languages.insertBefore('java', 'string', {
  852. 'triple-quoted-string': {
  853. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  854. greedy: true,
  855. alias: 'string'
  856. }
  857. });
  858. Prism.languages.insertBefore('java', 'class-name', {
  859. 'annotation': {
  860. alias: 'punctuation',
  861. pattern: /(^|[^.])@\w+/,
  862. lookbehind: true
  863. },
  864. 'namespace': {
  865. pattern: /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(?:\.[a-z]\w*)+/,
  866. lookbehind: true,
  867. inside: { 'punctuation': /\./ }
  868. },
  869. 'generics': {
  870. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  871. inside: {
  872. 'class-name': className,
  873. 'keyword': keywords,
  874. 'punctuation': /[<>(),.:]/,
  875. 'operator': /[?&|]/
  876. }
  877. }
  878. });
  879. }(Prism));
  880. },
  881. {}
  882. ],
  883. 8: [
  884. function (require, module, exports) {
  885. Prism.languages.javascript = Prism.languages.extend('clike', {
  886. 'class-name': [
  887. Prism.languages.clike['class-name'],
  888. {
  889. pattern: /(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,
  890. lookbehind: true
  891. }
  892. ],
  893. 'keyword': [
  894. {
  895. pattern: /((?:^|})\s*)(?:catch|finally)\b/,
  896. lookbehind: true
  897. },
  898. {
  899. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|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)\b/,
  900. lookbehind: true
  901. }
  902. ],
  903. 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
  904. 'function': /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  905. 'operator': /--|\+\+|\*\*=?|=>|&&|\|\||[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?[.?]?|[~:]/
  906. });
  907. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
  908. Prism.languages.insertBefore('javascript', 'keyword', {
  909. 'regex': {
  910. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*[\s\S]*?\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
  911. lookbehind: true,
  912. greedy: true
  913. },
  914. 'function-variable': {
  915. pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,
  916. alias: 'function'
  917. },
  918. 'parameter': [
  919. {
  920. pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
  921. lookbehind: true,
  922. inside: Prism.languages.javascript
  923. },
  924. {
  925. pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,
  926. inside: Prism.languages.javascript
  927. },
  928. {
  929. pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
  930. lookbehind: true,
  931. inside: Prism.languages.javascript
  932. },
  933. {
  934. 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]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
  935. lookbehind: true,
  936. inside: Prism.languages.javascript
  937. }
  938. ],
  939. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  940. });
  941. Prism.languages.insertBefore('javascript', 'string', {
  942. 'template-string': {
  943. pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
  944. greedy: true,
  945. inside: {
  946. 'template-punctuation': {
  947. pattern: /^`|`$/,
  948. alias: 'string'
  949. },
  950. 'interpolation': {
  951. pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
  952. lookbehind: true,
  953. inside: {
  954. 'interpolation-punctuation': {
  955. pattern: /^\${|}$/,
  956. alias: 'punctuation'
  957. },
  958. rest: Prism.languages.javascript
  959. }
  960. },
  961. 'string': /[\s\S]+/
  962. }
  963. }
  964. });
  965. if (Prism.languages.markup) {
  966. Prism.languages.markup.tag.addInlined('script', 'javascript');
  967. }
  968. Prism.languages.js = Prism.languages.javascript;
  969. },
  970. {}
  971. ],
  972. 9: [
  973. function (require, module, exports) {
  974. (function (Prism) {
  975. function getPlaceholder(language, index) {
  976. return '___' + language.toUpperCase() + index + '___';
  977. }
  978. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  979. buildPlaceholders: {
  980. value: function (env, language, placeholderPattern, replaceFilter) {
  981. if (env.language !== language) {
  982. return;
  983. }
  984. var tokenStack = env.tokenStack = [];
  985. env.code = env.code.replace(placeholderPattern, function (match) {
  986. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  987. return match;
  988. }
  989. var i = tokenStack.length;
  990. var placeholder;
  991. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
  992. ++i;
  993. tokenStack[i] = match;
  994. return placeholder;
  995. });
  996. env.grammar = Prism.languages.markup;
  997. }
  998. },
  999. tokenizePlaceholders: {
  1000. value: function (env, language) {
  1001. if (env.language !== language || !env.tokenStack) {
  1002. return;
  1003. }
  1004. env.grammar = Prism.languages[language];
  1005. var j = 0;
  1006. var keys = Object.keys(env.tokenStack);
  1007. function walkTokens(tokens) {
  1008. for (var i = 0; i < tokens.length; i++) {
  1009. if (j >= keys.length) {
  1010. break;
  1011. }
  1012. var token = tokens[i];
  1013. if (typeof token === 'string' || token.content && typeof token.content === 'string') {
  1014. var k = keys[j];
  1015. var t = env.tokenStack[k];
  1016. var s = typeof token === 'string' ? token : token.content;
  1017. var placeholder = getPlaceholder(language, k);
  1018. var index = s.indexOf(placeholder);
  1019. if (index > -1) {
  1020. ++j;
  1021. var before = s.substring(0, index);
  1022. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  1023. var after = s.substring(index + placeholder.length);
  1024. var replacement = [];
  1025. if (before) {
  1026. replacement.push.apply(replacement, walkTokens([before]));
  1027. }
  1028. replacement.push(middle);
  1029. if (after) {
  1030. replacement.push.apply(replacement, walkTokens([after]));
  1031. }
  1032. if (typeof token === 'string') {
  1033. tokens.splice.apply(tokens, [
  1034. i,
  1035. 1
  1036. ].concat(replacement));
  1037. } else {
  1038. token.content = replacement;
  1039. }
  1040. }
  1041. } else if (token.content) {
  1042. walkTokens(token.content);
  1043. }
  1044. }
  1045. return tokens;
  1046. }
  1047. walkTokens(env.tokens);
  1048. }
  1049. }
  1050. });
  1051. }(Prism));
  1052. },
  1053. {}
  1054. ],
  1055. 10: [
  1056. function (require, module, exports) {
  1057. Prism.languages.markup = {
  1058. 'comment': /<!--[\s\S]*?-->/,
  1059. 'prolog': /<\?[\s\S]+?\?>/,
  1060. 'doctype': {
  1061. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:(?!<!--)[^"'\]]|"[^"]*"|'[^']*'|<!--[\s\S]*?-->)*\]\s*)?>/i,
  1062. greedy: true
  1063. },
  1064. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  1065. 'tag': {
  1066. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i,
  1067. greedy: true,
  1068. inside: {
  1069. 'tag': {
  1070. pattern: /^<\/?[^\s>\/]+/i,
  1071. inside: {
  1072. 'punctuation': /^<\/?/,
  1073. 'namespace': /^[^\s>\/:]+:/
  1074. }
  1075. },
  1076. 'attr-value': {
  1077. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i,
  1078. inside: {
  1079. 'punctuation': [
  1080. /^=/,
  1081. {
  1082. pattern: /^(\s*)["']|["']$/,
  1083. lookbehind: true
  1084. }
  1085. ]
  1086. }
  1087. },
  1088. 'punctuation': /\/?>/,
  1089. 'attr-name': {
  1090. pattern: /[^\s>\/]+/,
  1091. inside: { 'namespace': /^[^\s>\/:]+:/ }
  1092. }
  1093. }
  1094. },
  1095. 'entity': /&#?[\da-z]{1,8};/i
  1096. };
  1097. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity'];
  1098. Prism.hooks.add('wrap', function (env) {
  1099. if (env.type === 'entity') {
  1100. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1101. }
  1102. });
  1103. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1104. value: function addInlined(tagName, lang) {
  1105. var includedCdataInside = {};
  1106. includedCdataInside['language-' + lang] = {
  1107. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1108. lookbehind: true,
  1109. inside: Prism.languages[lang]
  1110. };
  1111. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1112. var inside = {
  1113. 'included-cdata': {
  1114. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1115. inside: includedCdataInside
  1116. }
  1117. };
  1118. inside['language-' + lang] = {
  1119. pattern: /[\s\S]+/,
  1120. inside: Prism.languages[lang]
  1121. };
  1122. var def = {};
  1123. def[tagName] = {
  1124. pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[[\s\S]*?\]\]>\s*|[\s\S])*?(?=<\/__>)/.source.replace(/__/g, tagName), 'i'),
  1125. lookbehind: true,
  1126. greedy: true,
  1127. inside: inside
  1128. };
  1129. Prism.languages.insertBefore('markup', 'cdata', def);
  1130. }
  1131. });
  1132. Prism.languages.xml = Prism.languages.extend('markup', {});
  1133. Prism.languages.html = Prism.languages.markup;
  1134. Prism.languages.mathml = Prism.languages.markup;
  1135. Prism.languages.svg = Prism.languages.markup;
  1136. },
  1137. {}
  1138. ],
  1139. 11: [
  1140. function (require, module, exports) {
  1141. (function (Prism) {
  1142. Prism.languages.php = Prism.languages.extend('clike', {
  1143. 'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
  1144. 'boolean': {
  1145. pattern: /\b(?:false|true)\b/i,
  1146. alias: 'constant'
  1147. },
  1148. 'constant': [
  1149. /\b[A-Z_][A-Z0-9_]*\b/,
  1150. /\b(?:null)\b/i
  1151. ],
  1152. 'comment': {
  1153. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1154. lookbehind: true
  1155. }
  1156. });
  1157. Prism.languages.insertBefore('php', 'string', {
  1158. 'shell-comment': {
  1159. pattern: /(^|[^\\])#.*/,
  1160. lookbehind: true,
  1161. alias: 'comment'
  1162. }
  1163. });
  1164. Prism.languages.insertBefore('php', 'comment', {
  1165. 'delimiter': {
  1166. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  1167. alias: 'important'
  1168. }
  1169. });
  1170. Prism.languages.insertBefore('php', 'keyword', {
  1171. 'variable': /\$+(?:\w+\b|(?={))/i,
  1172. 'package': {
  1173. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1174. lookbehind: true,
  1175. inside: { punctuation: /\\/ }
  1176. }
  1177. });
  1178. Prism.languages.insertBefore('php', 'operator', {
  1179. 'property': {
  1180. pattern: /(->)[\w]+/,
  1181. lookbehind: true
  1182. }
  1183. });
  1184. var string_interpolation = {
  1185. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
  1186. lookbehind: true,
  1187. inside: Prism.languages.php
  1188. };
  1189. Prism.languages.insertBefore('php', 'string', {
  1190. 'nowdoc-string': {
  1191. pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
  1192. greedy: true,
  1193. alias: 'string',
  1194. inside: {
  1195. 'delimiter': {
  1196. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  1197. alias: 'symbol',
  1198. inside: { 'punctuation': /^<<<'?|[';]$/ }
  1199. }
  1200. }
  1201. },
  1202. 'heredoc-string': {
  1203. pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
  1204. greedy: true,
  1205. alias: 'string',
  1206. inside: {
  1207. 'delimiter': {
  1208. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  1209. alias: 'symbol',
  1210. inside: { 'punctuation': /^<<<"?|[";]$/ }
  1211. },
  1212. 'interpolation': string_interpolation
  1213. }
  1214. },
  1215. 'single-quoted-string': {
  1216. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1217. greedy: true,
  1218. alias: 'string'
  1219. },
  1220. 'double-quoted-string': {
  1221. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1222. greedy: true,
  1223. alias: 'string',
  1224. inside: { 'interpolation': string_interpolation }
  1225. }
  1226. });
  1227. delete Prism.languages.php['string'];
  1228. Prism.hooks.add('before-tokenize', function (env) {
  1229. if (!/<\?/.test(env.code)) {
  1230. return;
  1231. }
  1232. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
  1233. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  1234. });
  1235. Prism.hooks.add('after-tokenize', function (env) {
  1236. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  1237. });
  1238. }(Prism));
  1239. },
  1240. {}
  1241. ],
  1242. 12: [
  1243. function (require, module, exports) {
  1244. Prism.languages.python = {
  1245. 'comment': {
  1246. pattern: /(^|[^\\])#.*/,
  1247. lookbehind: true
  1248. },
  1249. 'string-interpolation': {
  1250. pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  1251. greedy: true,
  1252. inside: {
  1253. 'interpolation': {
  1254. pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
  1255. lookbehind: true,
  1256. inside: {
  1257. 'format-spec': {
  1258. pattern: /(:)[^:(){}]+(?=}$)/,
  1259. lookbehind: true
  1260. },
  1261. 'conversion-option': {
  1262. pattern: /![sra](?=[:}]$)/,
  1263. alias: 'punctuation'
  1264. },
  1265. rest: null
  1266. }
  1267. },
  1268. 'string': /[\s\S]+/
  1269. }
  1270. },
  1271. 'triple-quoted-string': {
  1272. pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]+?\1/i,
  1273. greedy: true,
  1274. alias: 'string'
  1275. },
  1276. 'string': {
  1277. pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  1278. greedy: true
  1279. },
  1280. 'function': {
  1281. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  1282. lookbehind: true
  1283. },
  1284. 'class-name': {
  1285. pattern: /(\bclass\s+)\w+/i,
  1286. lookbehind: true
  1287. },
  1288. 'decorator': {
  1289. pattern: /(^\s*)@\w+(?:\.\w+)*/im,
  1290. lookbehind: true,
  1291. alias: [
  1292. 'annotation',
  1293. 'punctuation'
  1294. ],
  1295. inside: { 'punctuation': /\./ }
  1296. },
  1297. 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  1298. 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
  1299. 'boolean': /\b(?:True|False|None)\b/,
  1300. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1301. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  1302. 'punctuation': /[{}[\];(),.:]/
  1303. };
  1304. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  1305. Prism.languages.py = Prism.languages.python;
  1306. },
  1307. {}
  1308. ],
  1309. 13: [
  1310. function (require, module, exports) {
  1311. (function (Prism) {
  1312. Prism.languages.ruby = Prism.languages.extend('clike', {
  1313. 'comment': [
  1314. /#.*/,
  1315. {
  1316. pattern: /^=begin\s[\s\S]*?^=end/m,
  1317. greedy: true
  1318. }
  1319. ],
  1320. 'class-name': {
  1321. pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
  1322. lookbehind: true,
  1323. inside: { 'punctuation': /[.\\]/ }
  1324. },
  1325. 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
  1326. });
  1327. var interpolation = {
  1328. pattern: /#\{[^}]+\}/,
  1329. inside: {
  1330. 'delimiter': {
  1331. pattern: /^#\{|\}$/,
  1332. alias: 'tag'
  1333. },
  1334. rest: Prism.languages.ruby
  1335. }
  1336. };
  1337. delete Prism.languages.ruby.function;
  1338. Prism.languages.insertBefore('ruby', 'keyword', {
  1339. 'regex': [
  1340. {
  1341. pattern: /%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/,
  1342. greedy: true,
  1343. inside: { 'interpolation': interpolation }
  1344. },
  1345. {
  1346. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  1347. greedy: true,
  1348. inside: { 'interpolation': interpolation }
  1349. },
  1350. {
  1351. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  1352. greedy: true,
  1353. inside: { 'interpolation': interpolation }
  1354. },
  1355. {
  1356. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  1357. greedy: true,
  1358. inside: { 'interpolation': interpolation }
  1359. },
  1360. {
  1361. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  1362. greedy: true,
  1363. inside: { 'interpolation': interpolation }
  1364. },
  1365. {
  1366. pattern: /(^|[^/])\/(?!\/)(?:\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})]))/,
  1367. lookbehind: true,
  1368. greedy: true
  1369. }
  1370. ],
  1371. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  1372. 'symbol': {
  1373. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  1374. lookbehind: true
  1375. },
  1376. 'method-definition': {
  1377. pattern: /(\bdef\s+)[\w.]+/,
  1378. lookbehind: true,
  1379. inside: {
  1380. 'function': /\w+$/,
  1381. rest: Prism.languages.ruby
  1382. }
  1383. }
  1384. });
  1385. Prism.languages.insertBefore('ruby', 'number', {
  1386. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  1387. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  1388. });
  1389. Prism.languages.ruby.string = [
  1390. {
  1391. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  1392. greedy: true,
  1393. inside: { 'interpolation': interpolation }
  1394. },
  1395. {
  1396. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  1397. greedy: true,
  1398. inside: { 'interpolation': interpolation }
  1399. },
  1400. {
  1401. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  1402. greedy: true,
  1403. inside: { 'interpolation': interpolation }
  1404. },
  1405. {
  1406. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  1407. greedy: true,
  1408. inside: { 'interpolation': interpolation }
  1409. },
  1410. {
  1411. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  1412. greedy: true,
  1413. inside: { 'interpolation': interpolation }
  1414. },
  1415. {
  1416. pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1417. greedy: true,
  1418. inside: { 'interpolation': interpolation }
  1419. }
  1420. ];
  1421. Prism.languages.rb = Prism.languages.ruby;
  1422. }(Prism));
  1423. },
  1424. {}
  1425. ],
  1426. 14: [
  1427. function (require, module, exports) {
  1428. var Prism = require('prismjs/components/prism-core');
  1429. require('prismjs/components/prism-clike');
  1430. require('prismjs/components/prism-markup-templating');
  1431. require('prismjs/components/prism-c');
  1432. require('prismjs/components/prism-cpp');
  1433. require('prismjs/components/prism-csharp');
  1434. require('prismjs/components/prism-css');
  1435. require('prismjs/components/prism-java');
  1436. require('prismjs/components/prism-javascript');
  1437. require('prismjs/components/prism-markup');
  1438. require('prismjs/components/prism-php');
  1439. require('prismjs/components/prism-python');
  1440. require('prismjs/components/prism-ruby');
  1441. module.exports = { boltExport: Prism };
  1442. },
  1443. {
  1444. 'prismjs/components/prism-c': 1,
  1445. 'prismjs/components/prism-clike': 2,
  1446. 'prismjs/components/prism-core': 3,
  1447. 'prismjs/components/prism-cpp': 4,
  1448. 'prismjs/components/prism-csharp': 5,
  1449. 'prismjs/components/prism-css': 6,
  1450. 'prismjs/components/prism-java': 7,
  1451. 'prismjs/components/prism-javascript': 8,
  1452. 'prismjs/components/prism-markup': 10,
  1453. 'prismjs/components/prism-markup-templating': 9,
  1454. 'prismjs/components/prism-php': 11,
  1455. 'prismjs/components/prism-python': 12,
  1456. 'prismjs/components/prism-ruby': 13
  1457. }
  1458. ]
  1459. }, {}, [14])(14);
  1460. }));
  1461. var prism = window.Prism;
  1462. window.Prism = oldprism;
  1463. return prism;
  1464. }(undefined, exports$1, module, undefined));
  1465. var Prism$1 = module.exports.boltExport;
  1466. var getLanguages = function (editor) {
  1467. return editor.getParam('codesample_languages');
  1468. };
  1469. var useGlobalPrismJS = function (editor) {
  1470. return editor.getParam('codesample_global_prismjs', false, 'boolean');
  1471. };
  1472. var get = function (editor) {
  1473. return Global.Prism && useGlobalPrismJS(editor) ? Global.Prism : Prism$1;
  1474. };
  1475. var getSelectedCodeSample = function (editor) {
  1476. var node = editor.selection ? editor.selection.getNode() : null;
  1477. if (isCodeSample(node)) {
  1478. return Option.some(node);
  1479. }
  1480. return Option.none();
  1481. };
  1482. var insertCodeSample = function (editor, language, code) {
  1483. editor.undoManager.transact(function () {
  1484. var node = getSelectedCodeSample(editor);
  1485. code = global$1.DOM.encode(code);
  1486. return node.fold(function () {
  1487. editor.insertContent('<pre id="__new" class="language-' + language + '">' + code + '</pre>');
  1488. editor.selection.select(editor.$('#__new').removeAttr('id')[0]);
  1489. }, function (n) {
  1490. editor.dom.setAttrib(n, 'class', 'language-' + language);
  1491. n.innerHTML = code;
  1492. get(editor).highlightElement(n);
  1493. editor.selection.select(n);
  1494. });
  1495. });
  1496. };
  1497. var getCurrentCode = function (editor) {
  1498. var node = getSelectedCodeSample(editor);
  1499. return node.fold(function () {
  1500. return '';
  1501. }, function (n) {
  1502. return n.textContent;
  1503. });
  1504. };
  1505. var getLanguages$1 = function (editor) {
  1506. var defaultLanguages = [
  1507. {
  1508. text: 'HTML/XML',
  1509. value: 'markup'
  1510. },
  1511. {
  1512. text: 'JavaScript',
  1513. value: 'javascript'
  1514. },
  1515. {
  1516. text: 'CSS',
  1517. value: 'css'
  1518. },
  1519. {
  1520. text: 'PHP',
  1521. value: 'php'
  1522. },
  1523. {
  1524. text: 'Ruby',
  1525. value: 'ruby'
  1526. },
  1527. {
  1528. text: 'Python',
  1529. value: 'python'
  1530. },
  1531. {
  1532. text: 'Java',
  1533. value: 'java'
  1534. },
  1535. {
  1536. text: 'C',
  1537. value: 'c'
  1538. },
  1539. {
  1540. text: 'C#',
  1541. value: 'csharp'
  1542. },
  1543. {
  1544. text: 'C++',
  1545. value: 'cpp'
  1546. }
  1547. ];
  1548. var customLanguages = getLanguages(editor);
  1549. return customLanguages ? customLanguages : defaultLanguages;
  1550. };
  1551. var getCurrentLanguage = function (editor, fallback) {
  1552. var node = getSelectedCodeSample(editor);
  1553. return node.fold(function () {
  1554. return fallback;
  1555. }, function (n) {
  1556. var matches = n.className.match(/language-(\w+)/);
  1557. return matches ? matches[1] : fallback;
  1558. });
  1559. };
  1560. var head = function (xs) {
  1561. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  1562. };
  1563. var open = function (editor) {
  1564. var languages = getLanguages$1(editor);
  1565. var defaultLanguage = head(languages).fold(function () {
  1566. return '';
  1567. }, function (l) {
  1568. return l.value;
  1569. });
  1570. var currentLanguage = getCurrentLanguage(editor, defaultLanguage);
  1571. var currentCode = getCurrentCode(editor);
  1572. editor.windowManager.open({
  1573. title: 'Insert/Edit Code Sample',
  1574. size: 'large',
  1575. body: {
  1576. type: 'panel',
  1577. items: [
  1578. {
  1579. type: 'selectbox',
  1580. name: 'language',
  1581. label: 'Language',
  1582. items: languages
  1583. },
  1584. {
  1585. type: 'textarea',
  1586. name: 'code',
  1587. label: 'Code view'
  1588. }
  1589. ]
  1590. },
  1591. buttons: [
  1592. {
  1593. type: 'cancel',
  1594. name: 'cancel',
  1595. text: 'Cancel'
  1596. },
  1597. {
  1598. type: 'submit',
  1599. name: 'save',
  1600. text: 'Save',
  1601. primary: true
  1602. }
  1603. ],
  1604. initialData: {
  1605. language: currentLanguage,
  1606. code: currentCode
  1607. },
  1608. onSubmit: function (api) {
  1609. var data = api.getData();
  1610. insertCodeSample(editor, data.language, data.code);
  1611. api.close();
  1612. }
  1613. });
  1614. };
  1615. var register = function (editor) {
  1616. editor.addCommand('codesample', function () {
  1617. var node = editor.selection.getNode();
  1618. if (editor.selection.isCollapsed() || isCodeSample(node)) {
  1619. open(editor);
  1620. } else {
  1621. editor.formatter.toggle('code');
  1622. }
  1623. });
  1624. };
  1625. var setup = function (editor) {
  1626. var $ = editor.$;
  1627. editor.on('PreProcess', function (e) {
  1628. $('pre[contenteditable=false]', e.node).filter(trimArg(isCodeSample)).each(function (idx, elm) {
  1629. var $elm = $(elm), code = elm.textContent;
  1630. $elm.attr('class', $.trim($elm.attr('class')));
  1631. $elm.removeAttr('contentEditable');
  1632. $elm.empty().append($('<code></code>').each(function () {
  1633. this.textContent = code;
  1634. }));
  1635. });
  1636. });
  1637. editor.on('SetContent', function () {
  1638. var unprocessedCodeSamples = $('pre').filter(trimArg(isCodeSample)).filter(function (idx, elm) {
  1639. return elm.contentEditable !== 'false';
  1640. });
  1641. if (unprocessedCodeSamples.length) {
  1642. editor.undoManager.transact(function () {
  1643. unprocessedCodeSamples.each(function (idx, elm) {
  1644. $(elm).find('br').each(function (idx, elm) {
  1645. elm.parentNode.replaceChild(editor.getDoc().createTextNode('\n'), elm);
  1646. });
  1647. elm.contentEditable = 'false';
  1648. elm.innerHTML = editor.dom.encode(elm.textContent);
  1649. get(editor).highlightElement(elm);
  1650. elm.className = $.trim(elm.className);
  1651. });
  1652. });
  1653. }
  1654. });
  1655. };
  1656. var isCodeSampleSelection = function (editor) {
  1657. var node = editor.selection.getStart();
  1658. return editor.dom.is(node, 'pre[class*="language-"]');
  1659. };
  1660. var register$1 = function (editor) {
  1661. editor.ui.registry.addToggleButton('codesample', {
  1662. icon: 'code-sample',
  1663. tooltip: 'Insert/edit code sample',
  1664. onAction: function () {
  1665. return open(editor);
  1666. },
  1667. onSetup: function (api) {
  1668. var nodeChangeHandler = function () {
  1669. api.setActive(isCodeSampleSelection(editor));
  1670. };
  1671. editor.on('NodeChange', nodeChangeHandler);
  1672. return function () {
  1673. return editor.off('NodeChange', nodeChangeHandler);
  1674. };
  1675. }
  1676. });
  1677. editor.ui.registry.addMenuItem('codesample', {
  1678. text: 'Code sample...',
  1679. icon: 'code-sample',
  1680. onAction: function () {
  1681. return open(editor);
  1682. }
  1683. });
  1684. };
  1685. function Plugin () {
  1686. global.add('codesample', function (editor) {
  1687. setup(editor);
  1688. register$1(editor);
  1689. register(editor);
  1690. editor.on('dblclick', function (ev) {
  1691. if (isCodeSample(ev.target)) {
  1692. open(editor);
  1693. }
  1694. });
  1695. });
  1696. }
  1697. Plugin();
  1698. }(window));