plugin.js 75 KB

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