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.5.1 (2020-10-01)
  8. */
  9. (function () {
  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 Optional = {
  122. some: some,
  123. none: none,
  124. from: from
  125. };
  126. var head = function (xs) {
  127. return xs.length === 0 ? Optional.none() : Optional.some(xs[0]);
  128. };
  129. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  130. function isCodeSample(elm) {
  131. return elm && elm.nodeName === 'PRE' && elm.className.indexOf('language-') !== -1;
  132. }
  133. function trimArg(predicateFn) {
  134. return function (arg1, arg2) {
  135. return predicateFn(arg2);
  136. };
  137. }
  138. var Global = typeof window !== 'undefined' ? window : Function('return this;')();
  139. var exports$1 = {}, module = { exports: exports$1 }, global$2 = {};
  140. (function (define, exports, module, require) {
  141. var oldprism = window.Prism;
  142. window.Prism = { manual: true };
  143. (function (f) {
  144. if (typeof exports === 'object' && typeof module !== 'undefined') {
  145. module.exports = f();
  146. } else if (typeof define === 'function' && define.amd) {
  147. define([], f);
  148. } else {
  149. var g;
  150. if (typeof window !== 'undefined') {
  151. g = window;
  152. } else if (typeof global$2 !== 'undefined') {
  153. g = global$2;
  154. } else if (typeof self !== 'undefined') {
  155. g = self;
  156. } else {
  157. g = this;
  158. }
  159. g.EphoxContactWrapper = f();
  160. }
  161. }(function () {
  162. return function () {
  163. function r(e, n, t) {
  164. function o(i, f) {
  165. if (!n[i]) {
  166. if (!e[i]) {
  167. var c = 'function' == typeof require && require;
  168. if (!f && c)
  169. return c(i, !0);
  170. if (u)
  171. return u(i, !0);
  172. var a = new Error('Cannot find module \'' + i + '\'');
  173. throw a.code = 'MODULE_NOT_FOUND', a;
  174. }
  175. var p = n[i] = { exports: {} };
  176. e[i][0].call(p.exports, function (r) {
  177. var n = e[i][1][r];
  178. return o(n || r);
  179. }, p, p.exports, r, e, n, t);
  180. }
  181. return n[i].exports;
  182. }
  183. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  184. o(t[i]);
  185. return o;
  186. }
  187. return r;
  188. }()({
  189. 1: [
  190. function (require, module, exports) {
  191. Prism.languages.c = Prism.languages.extend('clike', {
  192. 'class-name': {
  193. pattern: /(\b(?:enum|struct)\s+)\w+/,
  194. lookbehind: true
  195. },
  196. '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/,
  197. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/,
  198. 'number': /(?:\b0x(?:[\da-f]+\.?[\da-f]*|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i
  199. });
  200. Prism.languages.insertBefore('c', 'string', {
  201. 'macro': {
  202. pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,
  203. lookbehind: true,
  204. alias: 'property',
  205. inside: {
  206. 'string': {
  207. pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,
  208. lookbehind: true
  209. },
  210. 'directive': {
  211. pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  212. lookbehind: true,
  213. alias: 'keyword'
  214. }
  215. }
  216. },
  217. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  218. });
  219. delete Prism.languages.c['boolean'];
  220. },
  221. {}
  222. ],
  223. 2: [
  224. function (require, module, exports) {
  225. Prism.languages.clike = {
  226. 'comment': [
  227. {
  228. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  229. lookbehind: true
  230. },
  231. {
  232. pattern: /(^|[^\\:])\/\/.*/,
  233. lookbehind: true,
  234. greedy: true
  235. }
  236. ],
  237. 'string': {
  238. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  239. greedy: true
  240. },
  241. 'class-name': {
  242. pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
  243. lookbehind: true,
  244. inside: { 'punctuation': /[.\\]/ }
  245. },
  246. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  247. 'boolean': /\b(?:true|false)\b/,
  248. 'function': /\w+(?=\()/,
  249. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  250. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  251. 'punctuation': /[{}[\];(),.:]/
  252. };
  253. },
  254. {}
  255. ],
  256. 3: [
  257. function (require, module, exports) {
  258. (function (global) {
  259. var _self = typeof window !== 'undefined' ? window : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : {};
  260. var Prism = function (_self) {
  261. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  262. var uniqueId = 0;
  263. var _ = {
  264. manual: _self.Prism && _self.Prism.manual,
  265. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  266. util: {
  267. encode: function (tokens) {
  268. if (tokens instanceof Token) {
  269. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  270. } else if (Array.isArray(tokens)) {
  271. return tokens.map(_.util.encode);
  272. } else {
  273. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  274. }
  275. },
  276. type: function (o) {
  277. return Object.prototype.toString.call(o).slice(8, -1);
  278. },
  279. objId: function (obj) {
  280. if (!obj['__id']) {
  281. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  282. }
  283. return obj['__id'];
  284. },
  285. clone: function deepClone(o, visited) {
  286. var clone, id, type = _.util.type(o);
  287. visited = visited || {};
  288. switch (type) {
  289. case 'Object':
  290. id = _.util.objId(o);
  291. if (visited[id]) {
  292. return visited[id];
  293. }
  294. clone = {};
  295. visited[id] = clone;
  296. for (var key in o) {
  297. if (o.hasOwnProperty(key)) {
  298. clone[key] = deepClone(o[key], visited);
  299. }
  300. }
  301. return clone;
  302. case 'Array':
  303. id = _.util.objId(o);
  304. if (visited[id]) {
  305. return visited[id];
  306. }
  307. clone = [];
  308. visited[id] = clone;
  309. o.forEach(function (v, i) {
  310. clone[i] = deepClone(v, visited);
  311. });
  312. return clone;
  313. default:
  314. return o;
  315. }
  316. },
  317. getLanguage: function (element) {
  318. while (element && !lang.test(element.className)) {
  319. element = element.parentElement;
  320. }
  321. if (element) {
  322. return (element.className.match(lang) || [
  323. ,
  324. 'none'
  325. ])[1].toLowerCase();
  326. }
  327. return 'none';
  328. },
  329. currentScript: function () {
  330. if (typeof document === 'undefined') {
  331. return null;
  332. }
  333. if ('currentScript' in document) {
  334. return document.currentScript;
  335. }
  336. try {
  337. throw new Error();
  338. } catch (err) {
  339. var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
  340. if (src) {
  341. var scripts = document.getElementsByTagName('script');
  342. for (var i in scripts) {
  343. if (scripts[i].src == src) {
  344. return scripts[i];
  345. }
  346. }
  347. }
  348. return null;
  349. }
  350. }
  351. },
  352. languages: {
  353. extend: function (id, redef) {
  354. var lang = _.util.clone(_.languages[id]);
  355. for (var key in redef) {
  356. lang[key] = redef[key];
  357. }
  358. return lang;
  359. },
  360. insertBefore: function (inside, before, insert, root) {
  361. root = root || _.languages;
  362. var grammar = root[inside];
  363. var ret = {};
  364. for (var token in grammar) {
  365. if (grammar.hasOwnProperty(token)) {
  366. if (token == before) {
  367. for (var newToken in insert) {
  368. if (insert.hasOwnProperty(newToken)) {
  369. ret[newToken] = insert[newToken];
  370. }
  371. }
  372. }
  373. if (!insert.hasOwnProperty(token)) {
  374. ret[token] = grammar[token];
  375. }
  376. }
  377. }
  378. var old = root[inside];
  379. root[inside] = ret;
  380. _.languages.DFS(_.languages, function (key, value) {
  381. if (value === old && key != inside) {
  382. this[key] = ret;
  383. }
  384. });
  385. return ret;
  386. },
  387. DFS: function DFS(o, callback, type, visited) {
  388. visited = visited || {};
  389. var objId = _.util.objId;
  390. for (var i in o) {
  391. if (o.hasOwnProperty(i)) {
  392. callback.call(o, i, o[i], type || i);
  393. var property = o[i], propertyType = _.util.type(property);
  394. if (propertyType === 'Object' && !visited[objId(property)]) {
  395. visited[objId(property)] = true;
  396. DFS(property, callback, null, visited);
  397. } else if (propertyType === 'Array' && !visited[objId(property)]) {
  398. visited[objId(property)] = true;
  399. DFS(property, callback, i, visited);
  400. }
  401. }
  402. }
  403. }
  404. },
  405. plugins: {},
  406. highlightAll: function (async, callback) {
  407. _.highlightAllUnder(document, async, callback);
  408. },
  409. highlightAllUnder: function (container, async, callback) {
  410. var env = {
  411. callback: callback,
  412. container: container,
  413. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  414. };
  415. _.hooks.run('before-highlightall', env);
  416. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  417. _.hooks.run('before-all-elements-highlight', env);
  418. for (var i = 0, element; element = env.elements[i++];) {
  419. _.highlightElement(element, async === true, env.callback);
  420. }
  421. },
  422. highlightElement: function (element, async, callback) {
  423. var language = _.util.getLanguage(element);
  424. var grammar = _.languages[language];
  425. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  426. var parent = element.parentNode;
  427. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  428. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  429. }
  430. var code = element.textContent;
  431. var env = {
  432. element: element,
  433. language: language,
  434. grammar: grammar,
  435. code: code
  436. };
  437. function insertHighlightedCode(highlightedCode) {
  438. env.highlightedCode = highlightedCode;
  439. _.hooks.run('before-insert', env);
  440. env.element.innerHTML = env.highlightedCode;
  441. _.hooks.run('after-highlight', env);
  442. _.hooks.run('complete', env);
  443. callback && callback.call(env.element);
  444. }
  445. _.hooks.run('before-sanity-check', env);
  446. if (!env.code) {
  447. _.hooks.run('complete', env);
  448. callback && callback.call(env.element);
  449. return;
  450. }
  451. _.hooks.run('before-highlight', env);
  452. if (!env.grammar) {
  453. insertHighlightedCode(_.util.encode(env.code));
  454. return;
  455. }
  456. if (async && _self.Worker) {
  457. var worker = new Worker(_.filename);
  458. worker.onmessage = function (evt) {
  459. insertHighlightedCode(evt.data);
  460. };
  461. worker.postMessage(JSON.stringify({
  462. language: env.language,
  463. code: env.code,
  464. immediateClose: true
  465. }));
  466. } else {
  467. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  468. }
  469. },
  470. highlight: function (text, grammar, language) {
  471. var env = {
  472. code: text,
  473. grammar: grammar,
  474. language: language
  475. };
  476. _.hooks.run('before-tokenize', env);
  477. env.tokens = _.tokenize(env.code, env.grammar);
  478. _.hooks.run('after-tokenize', env);
  479. return Token.stringify(_.util.encode(env.tokens), env.language);
  480. },
  481. matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
  482. for (var token in grammar) {
  483. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  484. continue;
  485. }
  486. var patterns = grammar[token];
  487. patterns = Array.isArray(patterns) ? patterns : [patterns];
  488. for (var j = 0; j < patterns.length; ++j) {
  489. if (target && target == token + ',' + j) {
  490. return;
  491. }
  492. var pattern = patterns[j], inside = pattern.inside, lookbehind = !!pattern.lookbehind, greedy = !!pattern.greedy, lookbehindLength = 0, alias = pattern.alias;
  493. if (greedy && !pattern.pattern.global) {
  494. var flags = pattern.pattern.toString().match(/[imsuy]*$/)[0];
  495. pattern.pattern = RegExp(pattern.pattern.source, flags + 'g');
  496. }
  497. pattern = pattern.pattern || pattern;
  498. for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
  499. var str = strarr[i];
  500. if (strarr.length > text.length) {
  501. return;
  502. }
  503. if (str instanceof Token) {
  504. continue;
  505. }
  506. if (greedy && i != strarr.length - 1) {
  507. pattern.lastIndex = pos;
  508. var match = pattern.exec(text);
  509. if (!match) {
  510. break;
  511. }
  512. var from = match.index + (lookbehind && match[1] ? match[1].length : 0), to = match.index + match[0].length, k = i, p = pos;
  513. for (var len = strarr.length; k < len && (p < to || !strarr[k].type && !strarr[k - 1].greedy); ++k) {
  514. p += strarr[k].length;
  515. if (from >= p) {
  516. ++i;
  517. pos = p;
  518. }
  519. }
  520. if (strarr[i] instanceof Token) {
  521. continue;
  522. }
  523. delNum = k - i;
  524. str = text.slice(pos, p);
  525. match.index -= pos;
  526. } else {
  527. pattern.lastIndex = 0;
  528. var match = pattern.exec(str), delNum = 1;
  529. }
  530. if (!match) {
  531. if (oneshot) {
  532. break;
  533. }
  534. continue;
  535. }
  536. if (lookbehind) {
  537. lookbehindLength = match[1] ? match[1].length : 0;
  538. }
  539. var from = match.index + lookbehindLength, match = match[0].slice(lookbehindLength), to = from + match.length, before = str.slice(0, from), after = str.slice(to);
  540. var args = [
  541. i,
  542. delNum
  543. ];
  544. if (before) {
  545. ++i;
  546. pos += before.length;
  547. args.push(before);
  548. }
  549. var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy);
  550. args.push(wrapped);
  551. if (after) {
  552. args.push(after);
  553. }
  554. Array.prototype.splice.apply(strarr, args);
  555. if (delNum != 1)
  556. _.matchGrammar(text, strarr, grammar, i, pos, true, token + ',' + j);
  557. if (oneshot)
  558. break;
  559. }
  560. }
  561. }
  562. },
  563. tokenize: function (text, grammar) {
  564. var strarr = [text];
  565. var rest = grammar.rest;
  566. if (rest) {
  567. for (var token in rest) {
  568. grammar[token] = rest[token];
  569. }
  570. delete grammar.rest;
  571. }
  572. _.matchGrammar(text, strarr, grammar, 0, 0, false);
  573. return strarr;
  574. },
  575. hooks: {
  576. all: {},
  577. add: function (name, callback) {
  578. var hooks = _.hooks.all;
  579. hooks[name] = hooks[name] || [];
  580. hooks[name].push(callback);
  581. },
  582. run: function (name, env) {
  583. var callbacks = _.hooks.all[name];
  584. if (!callbacks || !callbacks.length) {
  585. return;
  586. }
  587. for (var i = 0, callback; callback = callbacks[i++];) {
  588. callback(env);
  589. }
  590. }
  591. },
  592. Token: Token
  593. };
  594. _self.Prism = _;
  595. function Token(type, content, alias, matchedStr, greedy) {
  596. this.type = type;
  597. this.content = content;
  598. this.alias = alias;
  599. this.length = (matchedStr || '').length | 0;
  600. this.greedy = !!greedy;
  601. }
  602. Token.stringify = function (o, language) {
  603. if (typeof o == 'string') {
  604. return o;
  605. }
  606. if (Array.isArray(o)) {
  607. return o.map(function (element) {
  608. return Token.stringify(element, language);
  609. }).join('');
  610. }
  611. var env = {
  612. type: o.type,
  613. content: Token.stringify(o.content, language),
  614. tag: 'span',
  615. classes: [
  616. 'token',
  617. o.type
  618. ],
  619. attributes: {},
  620. language: language
  621. };
  622. if (o.alias) {
  623. var aliases = Array.isArray(o.alias) ? o.alias : [o.alias];
  624. Array.prototype.push.apply(env.classes, aliases);
  625. }
  626. _.hooks.run('wrap', env);
  627. var attributes = Object.keys(env.attributes).map(function (name) {
  628. return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  629. }).join(' ');
  630. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
  631. };
  632. if (!_self.document) {
  633. if (!_self.addEventListener) {
  634. return _;
  635. }
  636. if (!_.disableWorkerMessageHandler) {
  637. _self.addEventListener('message', function (evt) {
  638. var message = JSON.parse(evt.data), lang = message.language, code = message.code, immediateClose = message.immediateClose;
  639. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  640. if (immediateClose) {
  641. _self.close();
  642. }
  643. }, false);
  644. }
  645. return _;
  646. }
  647. var script = _.util.currentScript();
  648. if (script) {
  649. _.filename = script.src;
  650. if (script.hasAttribute('data-manual')) {
  651. _.manual = true;
  652. }
  653. }
  654. if (!_.manual) {
  655. var highlightAutomaticallyCallback = function () {
  656. if (!_.manual) {
  657. _.highlightAll();
  658. }
  659. };
  660. var readyState = document.readyState;
  661. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  662. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  663. } else {
  664. if (window.requestAnimationFrame) {
  665. window.requestAnimationFrame(highlightAutomaticallyCallback);
  666. } else {
  667. window.setTimeout(highlightAutomaticallyCallback, 16);
  668. }
  669. }
  670. }
  671. return _;
  672. }(_self);
  673. if (typeof module !== 'undefined' && module.exports) {
  674. module.exports = Prism;
  675. }
  676. if (typeof global !== 'undefined') {
  677. global.Prism = Prism;
  678. }
  679. }.call(this, typeof global$2 !== 'undefined' ? global$2 : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {}));
  680. },
  681. {}
  682. ],
  683. 4: [
  684. function (require, module, exports) {
  685. Prism.languages.cpp = Prism.languages.extend('c', {
  686. 'class-name': {
  687. pattern: /(\b(?:class|enum|struct)\s+)\w+/,
  688. lookbehind: true
  689. },
  690. '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/,
  691. 'number': {
  692. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,
  693. greedy: true
  694. },
  695. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  696. 'boolean': /\b(?:true|false)\b/
  697. });
  698. Prism.languages.insertBefore('cpp', 'string', {
  699. 'raw-string': {
  700. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  701. alias: 'string',
  702. greedy: true
  703. }
  704. });
  705. },
  706. {}
  707. ],
  708. 5: [
  709. function (require, module, exports) {
  710. Prism.languages.csharp = Prism.languages.extend('clike', {
  711. '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/,
  712. 'string': [
  713. {
  714. pattern: /@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,
  715. greedy: true
  716. },
  717. {
  718. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,
  719. greedy: true
  720. }
  721. ],
  722. 'class-name': [
  723. {
  724. pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=\s+\w+)/,
  725. inside: { punctuation: /\./ }
  726. },
  727. {
  728. pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
  729. lookbehind: true,
  730. inside: { punctuation: /\./ }
  731. },
  732. {
  733. pattern: /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
  734. lookbehind: true,
  735. inside: { punctuation: /\./ }
  736. },
  737. {
  738. pattern: /((?:\b(?:class|interface|new)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
  739. lookbehind: true,
  740. inside: { punctuation: /\./ }
  741. }
  742. ],
  743. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i,
  744. 'operator': />>=?|<<=?|[-=]>|([-+&|?])\1|~|[-+*/%&|^!=<>]=?/,
  745. 'punctuation': /\?\.?|::|[{}[\];(),.:]/
  746. });
  747. Prism.languages.insertBefore('csharp', 'class-name', {
  748. 'generic-method': {
  749. pattern: /\w+\s*<[^>\r\n]+?>\s*(?=\()/,
  750. inside: {
  751. function: /^\w+/,
  752. 'class-name': {
  753. pattern: /\b[A-Z]\w*(?:\.\w+)*\b/,
  754. inside: { punctuation: /\./ }
  755. },
  756. keyword: Prism.languages.csharp.keyword,
  757. punctuation: /[<>(),.:]/
  758. }
  759. },
  760. 'preprocessor': {
  761. pattern: /(^\s*)#.*/m,
  762. lookbehind: true,
  763. alias: 'property',
  764. inside: {
  765. 'directive': {
  766. pattern: /(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
  767. lookbehind: true,
  768. alias: 'keyword'
  769. }
  770. }
  771. }
  772. });
  773. Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
  774. },
  775. {}
  776. ],
  777. 6: [
  778. function (require, module, exports) {
  779. (function (Prism) {
  780. var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
  781. Prism.languages.css = {
  782. 'comment': /\/\*[\s\S]*?\*\//,
  783. 'atrule': {
  784. pattern: /@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,
  785. inside: { 'rule': /@[\w-]+/ }
  786. },
  787. 'url': {
  788. pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
  789. inside: {
  790. 'function': /^url/i,
  791. 'punctuation': /^\(|\)$/
  792. }
  793. },
  794. 'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
  795. 'string': {
  796. pattern: string,
  797. greedy: true
  798. },
  799. 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
  800. 'important': /!important\b/i,
  801. 'function': /[-a-z0-9]+(?=\()/i,
  802. 'punctuation': /[(){};:,]/
  803. };
  804. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  805. var markup = Prism.languages.markup;
  806. if (markup) {
  807. markup.tag.addInlined('style', 'css');
  808. Prism.languages.insertBefore('inside', 'attr-value', {
  809. 'style-attr': {
  810. pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
  811. inside: {
  812. 'attr-name': {
  813. pattern: /^\s*style/i,
  814. inside: markup.tag.inside
  815. },
  816. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  817. 'attr-value': {
  818. pattern: /.+/i,
  819. inside: Prism.languages.css
  820. }
  821. },
  822. alias: 'language-css'
  823. }
  824. }, markup.tag);
  825. }
  826. }(Prism));
  827. },
  828. {}
  829. ],
  830. 7: [
  831. function (require, module, exports) {
  832. (function (Prism) {
  833. 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/;
  834. var className = /\b[A-Z](?:\w*[a-z]\w*)?\b/;
  835. Prism.languages.java = Prism.languages.extend('clike', {
  836. 'class-name': [
  837. className,
  838. /\b[A-Z]\w*(?=\s+\w+\s*[;,=())])/
  839. ],
  840. 'keyword': keywords,
  841. 'function': [
  842. Prism.languages.clike.function,
  843. {
  844. pattern: /(\:\:)[a-z_]\w*/,
  845. lookbehind: true
  846. }
  847. ],
  848. '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,
  849. 'operator': {
  850. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  851. lookbehind: true
  852. }
  853. });
  854. Prism.languages.insertBefore('java', 'string', {
  855. 'triple-quoted-string': {
  856. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  857. greedy: true,
  858. alias: 'string'
  859. }
  860. });
  861. Prism.languages.insertBefore('java', 'class-name', {
  862. 'annotation': {
  863. alias: 'punctuation',
  864. pattern: /(^|[^.])@\w+/,
  865. lookbehind: true
  866. },
  867. 'namespace': {
  868. pattern: /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(?:\.[a-z]\w*)+/,
  869. lookbehind: true,
  870. inside: { 'punctuation': /\./ }
  871. },
  872. 'generics': {
  873. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  874. inside: {
  875. 'class-name': className,
  876. 'keyword': keywords,
  877. 'punctuation': /[<>(),.:]/,
  878. 'operator': /[?&|]/
  879. }
  880. }
  881. });
  882. }(Prism));
  883. },
  884. {}
  885. ],
  886. 8: [
  887. function (require, module, exports) {
  888. Prism.languages.javascript = Prism.languages.extend('clike', {
  889. 'class-name': [
  890. Prism.languages.clike['class-name'],
  891. {
  892. pattern: /(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,
  893. lookbehind: true
  894. }
  895. ],
  896. 'keyword': [
  897. {
  898. pattern: /((?:^|})\s*)(?:catch|finally)\b/,
  899. lookbehind: true
  900. },
  901. {
  902. 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/,
  903. lookbehind: true
  904. }
  905. ],
  906. '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)?)+)?/,
  907. 'function': /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  908. 'operator': /--|\+\+|\*\*=?|=>|&&|\|\||[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?[.?]?|[~:]/
  909. });
  910. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
  911. Prism.languages.insertBefore('javascript', 'keyword', {
  912. 'regex': {
  913. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*[\s\S]*?\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
  914. lookbehind: true,
  915. greedy: true
  916. },
  917. 'function-variable': {
  918. pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,
  919. alias: 'function'
  920. },
  921. 'parameter': [
  922. {
  923. pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
  924. lookbehind: true,
  925. inside: Prism.languages.javascript
  926. },
  927. {
  928. pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,
  929. inside: Prism.languages.javascript
  930. },
  931. {
  932. pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
  933. lookbehind: true,
  934. inside: Prism.languages.javascript
  935. },
  936. {
  937. 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*\{)/,
  938. lookbehind: true,
  939. inside: Prism.languages.javascript
  940. }
  941. ],
  942. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  943. });
  944. Prism.languages.insertBefore('javascript', 'string', {
  945. 'template-string': {
  946. pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
  947. greedy: true,
  948. inside: {
  949. 'template-punctuation': {
  950. pattern: /^`|`$/,
  951. alias: 'string'
  952. },
  953. 'interpolation': {
  954. pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
  955. lookbehind: true,
  956. inside: {
  957. 'interpolation-punctuation': {
  958. pattern: /^\${|}$/,
  959. alias: 'punctuation'
  960. },
  961. rest: Prism.languages.javascript
  962. }
  963. },
  964. 'string': /[\s\S]+/
  965. }
  966. }
  967. });
  968. if (Prism.languages.markup) {
  969. Prism.languages.markup.tag.addInlined('script', 'javascript');
  970. }
  971. Prism.languages.js = Prism.languages.javascript;
  972. },
  973. {}
  974. ],
  975. 9: [
  976. function (require, module, exports) {
  977. (function (Prism) {
  978. function getPlaceholder(language, index) {
  979. return '___' + language.toUpperCase() + index + '___';
  980. }
  981. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  982. buildPlaceholders: {
  983. value: function (env, language, placeholderPattern, replaceFilter) {
  984. if (env.language !== language) {
  985. return;
  986. }
  987. var tokenStack = env.tokenStack = [];
  988. env.code = env.code.replace(placeholderPattern, function (match) {
  989. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  990. return match;
  991. }
  992. var i = tokenStack.length;
  993. var placeholder;
  994. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
  995. ++i;
  996. tokenStack[i] = match;
  997. return placeholder;
  998. });
  999. env.grammar = Prism.languages.markup;
  1000. }
  1001. },
  1002. tokenizePlaceholders: {
  1003. value: function (env, language) {
  1004. if (env.language !== language || !env.tokenStack) {
  1005. return;
  1006. }
  1007. env.grammar = Prism.languages[language];
  1008. var j = 0;
  1009. var keys = Object.keys(env.tokenStack);
  1010. function walkTokens(tokens) {
  1011. for (var i = 0; i < tokens.length; i++) {
  1012. if (j >= keys.length) {
  1013. break;
  1014. }
  1015. var token = tokens[i];
  1016. if (typeof token === 'string' || token.content && typeof token.content === 'string') {
  1017. var k = keys[j];
  1018. var t = env.tokenStack[k];
  1019. var s = typeof token === 'string' ? token : token.content;
  1020. var placeholder = getPlaceholder(language, k);
  1021. var index = s.indexOf(placeholder);
  1022. if (index > -1) {
  1023. ++j;
  1024. var before = s.substring(0, index);
  1025. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  1026. var after = s.substring(index + placeholder.length);
  1027. var replacement = [];
  1028. if (before) {
  1029. replacement.push.apply(replacement, walkTokens([before]));
  1030. }
  1031. replacement.push(middle);
  1032. if (after) {
  1033. replacement.push.apply(replacement, walkTokens([after]));
  1034. }
  1035. if (typeof token === 'string') {
  1036. tokens.splice.apply(tokens, [
  1037. i,
  1038. 1
  1039. ].concat(replacement));
  1040. } else {
  1041. token.content = replacement;
  1042. }
  1043. }
  1044. } else if (token.content) {
  1045. walkTokens(token.content);
  1046. }
  1047. }
  1048. return tokens;
  1049. }
  1050. walkTokens(env.tokens);
  1051. }
  1052. }
  1053. });
  1054. }(Prism));
  1055. },
  1056. {}
  1057. ],
  1058. 10: [
  1059. function (require, module, exports) {
  1060. Prism.languages.markup = {
  1061. 'comment': /<!--[\s\S]*?-->/,
  1062. 'prolog': /<\?[\s\S]+?\?>/,
  1063. 'doctype': {
  1064. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:(?!<!--)[^"'\]]|"[^"]*"|'[^']*'|<!--[\s\S]*?-->)*\]\s*)?>/i,
  1065. greedy: true
  1066. },
  1067. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  1068. 'tag': {
  1069. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i,
  1070. greedy: true,
  1071. inside: {
  1072. 'tag': {
  1073. pattern: /^<\/?[^\s>\/]+/i,
  1074. inside: {
  1075. 'punctuation': /^<\/?/,
  1076. 'namespace': /^[^\s>\/:]+:/
  1077. }
  1078. },
  1079. 'attr-value': {
  1080. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i,
  1081. inside: {
  1082. 'punctuation': [
  1083. /^=/,
  1084. {
  1085. pattern: /^(\s*)["']|["']$/,
  1086. lookbehind: true
  1087. }
  1088. ]
  1089. }
  1090. },
  1091. 'punctuation': /\/?>/,
  1092. 'attr-name': {
  1093. pattern: /[^\s>\/]+/,
  1094. inside: { 'namespace': /^[^\s>\/:]+:/ }
  1095. }
  1096. }
  1097. },
  1098. 'entity': /&#?[\da-z]{1,8};/i
  1099. };
  1100. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity'];
  1101. Prism.hooks.add('wrap', function (env) {
  1102. if (env.type === 'entity') {
  1103. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1104. }
  1105. });
  1106. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1107. value: function addInlined(tagName, lang) {
  1108. var includedCdataInside = {};
  1109. includedCdataInside['language-' + lang] = {
  1110. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1111. lookbehind: true,
  1112. inside: Prism.languages[lang]
  1113. };
  1114. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1115. var inside = {
  1116. 'included-cdata': {
  1117. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1118. inside: includedCdataInside
  1119. }
  1120. };
  1121. inside['language-' + lang] = {
  1122. pattern: /[\s\S]+/,
  1123. inside: Prism.languages[lang]
  1124. };
  1125. var def = {};
  1126. def[tagName] = {
  1127. pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[[\s\S]*?\]\]>\s*|[\s\S])*?(?=<\/__>)/.source.replace(/__/g, tagName), 'i'),
  1128. lookbehind: true,
  1129. greedy: true,
  1130. inside: inside
  1131. };
  1132. Prism.languages.insertBefore('markup', 'cdata', def);
  1133. }
  1134. });
  1135. Prism.languages.xml = Prism.languages.extend('markup', {});
  1136. Prism.languages.html = Prism.languages.markup;
  1137. Prism.languages.mathml = Prism.languages.markup;
  1138. Prism.languages.svg = Prism.languages.markup;
  1139. },
  1140. {}
  1141. ],
  1142. 11: [
  1143. function (require, module, exports) {
  1144. (function (Prism) {
  1145. Prism.languages.php = Prism.languages.extend('clike', {
  1146. '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,
  1147. 'boolean': {
  1148. pattern: /\b(?:false|true)\b/i,
  1149. alias: 'constant'
  1150. },
  1151. 'constant': [
  1152. /\b[A-Z_][A-Z0-9_]*\b/,
  1153. /\b(?:null)\b/i
  1154. ],
  1155. 'comment': {
  1156. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1157. lookbehind: true
  1158. }
  1159. });
  1160. Prism.languages.insertBefore('php', 'string', {
  1161. 'shell-comment': {
  1162. pattern: /(^|[^\\])#.*/,
  1163. lookbehind: true,
  1164. alias: 'comment'
  1165. }
  1166. });
  1167. Prism.languages.insertBefore('php', 'comment', {
  1168. 'delimiter': {
  1169. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  1170. alias: 'important'
  1171. }
  1172. });
  1173. Prism.languages.insertBefore('php', 'keyword', {
  1174. 'variable': /\$+(?:\w+\b|(?={))/i,
  1175. 'package': {
  1176. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1177. lookbehind: true,
  1178. inside: { punctuation: /\\/ }
  1179. }
  1180. });
  1181. Prism.languages.insertBefore('php', 'operator', {
  1182. 'property': {
  1183. pattern: /(->)[\w]+/,
  1184. lookbehind: true
  1185. }
  1186. });
  1187. var string_interpolation = {
  1188. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
  1189. lookbehind: true,
  1190. inside: Prism.languages.php
  1191. };
  1192. Prism.languages.insertBefore('php', 'string', {
  1193. 'nowdoc-string': {
  1194. pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
  1195. greedy: true,
  1196. alias: 'string',
  1197. inside: {
  1198. 'delimiter': {
  1199. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  1200. alias: 'symbol',
  1201. inside: { 'punctuation': /^<<<'?|[';]$/ }
  1202. }
  1203. }
  1204. },
  1205. 'heredoc-string': {
  1206. pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
  1207. greedy: true,
  1208. alias: 'string',
  1209. inside: {
  1210. 'delimiter': {
  1211. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  1212. alias: 'symbol',
  1213. inside: { 'punctuation': /^<<<"?|[";]$/ }
  1214. },
  1215. 'interpolation': string_interpolation
  1216. }
  1217. },
  1218. 'single-quoted-string': {
  1219. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1220. greedy: true,
  1221. alias: 'string'
  1222. },
  1223. 'double-quoted-string': {
  1224. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1225. greedy: true,
  1226. alias: 'string',
  1227. inside: { 'interpolation': string_interpolation }
  1228. }
  1229. });
  1230. delete Prism.languages.php['string'];
  1231. Prism.hooks.add('before-tokenize', function (env) {
  1232. if (!/<\?/.test(env.code)) {
  1233. return;
  1234. }
  1235. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
  1236. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  1237. });
  1238. Prism.hooks.add('after-tokenize', function (env) {
  1239. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  1240. });
  1241. }(Prism));
  1242. },
  1243. {}
  1244. ],
  1245. 12: [
  1246. function (require, module, exports) {
  1247. Prism.languages.python = {
  1248. 'comment': {
  1249. pattern: /(^|[^\\])#.*/,
  1250. lookbehind: true
  1251. },
  1252. 'string-interpolation': {
  1253. pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  1254. greedy: true,
  1255. inside: {
  1256. 'interpolation': {
  1257. pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
  1258. lookbehind: true,
  1259. inside: {
  1260. 'format-spec': {
  1261. pattern: /(:)[^:(){}]+(?=}$)/,
  1262. lookbehind: true
  1263. },
  1264. 'conversion-option': {
  1265. pattern: /![sra](?=[:}]$)/,
  1266. alias: 'punctuation'
  1267. },
  1268. rest: null
  1269. }
  1270. },
  1271. 'string': /[\s\S]+/
  1272. }
  1273. },
  1274. 'triple-quoted-string': {
  1275. pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]+?\1/i,
  1276. greedy: true,
  1277. alias: 'string'
  1278. },
  1279. 'string': {
  1280. pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  1281. greedy: true
  1282. },
  1283. 'function': {
  1284. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  1285. lookbehind: true
  1286. },
  1287. 'class-name': {
  1288. pattern: /(\bclass\s+)\w+/i,
  1289. lookbehind: true
  1290. },
  1291. 'decorator': {
  1292. pattern: /(^\s*)@\w+(?:\.\w+)*/im,
  1293. lookbehind: true,
  1294. alias: [
  1295. 'annotation',
  1296. 'punctuation'
  1297. ],
  1298. inside: { 'punctuation': /\./ }
  1299. },
  1300. '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/,
  1301. '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/,
  1302. 'boolean': /\b(?:True|False|None)\b/,
  1303. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1304. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  1305. 'punctuation': /[{}[\];(),.:]/
  1306. };
  1307. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  1308. Prism.languages.py = Prism.languages.python;
  1309. },
  1310. {}
  1311. ],
  1312. 13: [
  1313. function (require, module, exports) {
  1314. (function (Prism) {
  1315. Prism.languages.ruby = Prism.languages.extend('clike', {
  1316. 'comment': [
  1317. /#.*/,
  1318. {
  1319. pattern: /^=begin\s[\s\S]*?^=end/m,
  1320. greedy: true
  1321. }
  1322. ],
  1323. 'class-name': {
  1324. pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
  1325. lookbehind: true,
  1326. inside: { 'punctuation': /[.\\]/ }
  1327. },
  1328. '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/
  1329. });
  1330. var interpolation = {
  1331. pattern: /#\{[^}]+\}/,
  1332. inside: {
  1333. 'delimiter': {
  1334. pattern: /^#\{|\}$/,
  1335. alias: 'tag'
  1336. },
  1337. rest: Prism.languages.ruby
  1338. }
  1339. };
  1340. delete Prism.languages.ruby.function;
  1341. Prism.languages.insertBefore('ruby', 'keyword', {
  1342. 'regex': [
  1343. {
  1344. pattern: /%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/,
  1345. greedy: true,
  1346. inside: { 'interpolation': interpolation }
  1347. },
  1348. {
  1349. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  1350. greedy: true,
  1351. inside: { 'interpolation': interpolation }
  1352. },
  1353. {
  1354. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  1355. greedy: true,
  1356. inside: { 'interpolation': interpolation }
  1357. },
  1358. {
  1359. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  1360. greedy: true,
  1361. inside: { 'interpolation': interpolation }
  1362. },
  1363. {
  1364. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  1365. greedy: true,
  1366. inside: { 'interpolation': interpolation }
  1367. },
  1368. {
  1369. pattern: /(^|[^/])\/(?!\/)(?:\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})]))/,
  1370. lookbehind: true,
  1371. greedy: true
  1372. }
  1373. ],
  1374. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  1375. 'symbol': {
  1376. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  1377. lookbehind: true
  1378. },
  1379. 'method-definition': {
  1380. pattern: /(\bdef\s+)[\w.]+/,
  1381. lookbehind: true,
  1382. inside: {
  1383. 'function': /\w+$/,
  1384. rest: Prism.languages.ruby
  1385. }
  1386. }
  1387. });
  1388. Prism.languages.insertBefore('ruby', 'number', {
  1389. '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/,
  1390. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  1391. });
  1392. Prism.languages.ruby.string = [
  1393. {
  1394. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  1395. greedy: true,
  1396. inside: { 'interpolation': interpolation }
  1397. },
  1398. {
  1399. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  1400. greedy: true,
  1401. inside: { 'interpolation': interpolation }
  1402. },
  1403. {
  1404. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  1405. greedy: true,
  1406. inside: { 'interpolation': interpolation }
  1407. },
  1408. {
  1409. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  1410. greedy: true,
  1411. inside: { 'interpolation': interpolation }
  1412. },
  1413. {
  1414. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  1415. greedy: true,
  1416. inside: { 'interpolation': interpolation }
  1417. },
  1418. {
  1419. pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1420. greedy: true,
  1421. inside: { 'interpolation': interpolation }
  1422. }
  1423. ];
  1424. Prism.languages.rb = Prism.languages.ruby;
  1425. }(Prism));
  1426. },
  1427. {}
  1428. ],
  1429. 14: [
  1430. function (require, module, exports) {
  1431. var Prism = require('prismjs/components/prism-core');
  1432. require('prismjs/components/prism-clike');
  1433. require('prismjs/components/prism-markup-templating');
  1434. require('prismjs/components/prism-c');
  1435. require('prismjs/components/prism-cpp');
  1436. require('prismjs/components/prism-csharp');
  1437. require('prismjs/components/prism-css');
  1438. require('prismjs/components/prism-java');
  1439. require('prismjs/components/prism-javascript');
  1440. require('prismjs/components/prism-markup');
  1441. require('prismjs/components/prism-php');
  1442. require('prismjs/components/prism-python');
  1443. require('prismjs/components/prism-ruby');
  1444. module.exports = { boltExport: Prism };
  1445. },
  1446. {
  1447. 'prismjs/components/prism-c': 1,
  1448. 'prismjs/components/prism-clike': 2,
  1449. 'prismjs/components/prism-core': 3,
  1450. 'prismjs/components/prism-cpp': 4,
  1451. 'prismjs/components/prism-csharp': 5,
  1452. 'prismjs/components/prism-css': 6,
  1453. 'prismjs/components/prism-java': 7,
  1454. 'prismjs/components/prism-javascript': 8,
  1455. 'prismjs/components/prism-markup': 10,
  1456. 'prismjs/components/prism-markup-templating': 9,
  1457. 'prismjs/components/prism-php': 11,
  1458. 'prismjs/components/prism-python': 12,
  1459. 'prismjs/components/prism-ruby': 13
  1460. }
  1461. ]
  1462. }, {}, [14])(14);
  1463. }));
  1464. var prism = window.Prism;
  1465. window.Prism = oldprism;
  1466. return prism;
  1467. }(undefined, exports$1, module, undefined));
  1468. var Prism$1 = module.exports.boltExport;
  1469. var getLanguages = function (editor) {
  1470. return editor.getParam('codesample_languages');
  1471. };
  1472. var useGlobalPrismJS = function (editor) {
  1473. return editor.getParam('codesample_global_prismjs', false, 'boolean');
  1474. };
  1475. var get = function (editor) {
  1476. return Global.Prism && useGlobalPrismJS(editor) ? Global.Prism : Prism$1;
  1477. };
  1478. var getSelectedCodeSample = function (editor) {
  1479. var node = editor.selection ? editor.selection.getNode() : null;
  1480. if (isCodeSample(node)) {
  1481. return Optional.some(node);
  1482. }
  1483. return Optional.none();
  1484. };
  1485. var insertCodeSample = function (editor, language, code) {
  1486. editor.undoManager.transact(function () {
  1487. var node = getSelectedCodeSample(editor);
  1488. code = global$1.DOM.encode(code);
  1489. return node.fold(function () {
  1490. editor.insertContent('<pre id="__new" class="language-' + language + '">' + code + '</pre>');
  1491. editor.selection.select(editor.$('#__new').removeAttr('id')[0]);
  1492. }, function (n) {
  1493. editor.dom.setAttrib(n, 'class', 'language-' + language);
  1494. n.innerHTML = code;
  1495. get(editor).highlightElement(n);
  1496. editor.selection.select(n);
  1497. });
  1498. });
  1499. };
  1500. var getCurrentCode = function (editor) {
  1501. var node = getSelectedCodeSample(editor);
  1502. return node.fold(function () {
  1503. return '';
  1504. }, function (n) {
  1505. return n.textContent;
  1506. });
  1507. };
  1508. var getLanguages$1 = function (editor) {
  1509. var defaultLanguages = [
  1510. {
  1511. text: 'HTML/XML',
  1512. value: 'markup'
  1513. },
  1514. {
  1515. text: 'JavaScript',
  1516. value: 'javascript'
  1517. },
  1518. {
  1519. text: 'CSS',
  1520. value: 'css'
  1521. },
  1522. {
  1523. text: 'PHP',
  1524. value: 'php'
  1525. },
  1526. {
  1527. text: 'Ruby',
  1528. value: 'ruby'
  1529. },
  1530. {
  1531. text: 'Python',
  1532. value: 'python'
  1533. },
  1534. {
  1535. text: 'Java',
  1536. value: 'java'
  1537. },
  1538. {
  1539. text: 'C',
  1540. value: 'c'
  1541. },
  1542. {
  1543. text: 'C#',
  1544. value: 'csharp'
  1545. },
  1546. {
  1547. text: 'C++',
  1548. value: 'cpp'
  1549. }
  1550. ];
  1551. var customLanguages = getLanguages(editor);
  1552. return customLanguages ? customLanguages : defaultLanguages;
  1553. };
  1554. var getCurrentLanguage = function (editor, fallback) {
  1555. var node = getSelectedCodeSample(editor);
  1556. return node.fold(function () {
  1557. return fallback;
  1558. }, function (n) {
  1559. var matches = n.className.match(/language-(\w+)/);
  1560. return matches ? matches[1] : fallback;
  1561. });
  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. }());