plugin.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. (function () {
  2. var codesample = (function () {
  3. 'use strict';
  4. var Cell = function (initial) {
  5. var value = initial;
  6. var get = function () {
  7. return value;
  8. };
  9. var set = function (v) {
  10. value = v;
  11. };
  12. var clone = function () {
  13. return Cell(get());
  14. };
  15. return {
  16. get: get,
  17. set: set,
  18. clone: clone
  19. };
  20. };
  21. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  22. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  23. var getContentCss = function (editor) {
  24. return editor.settings.codesample_content_css;
  25. };
  26. var getLanguages = function (editor) {
  27. return editor.settings.codesample_languages;
  28. };
  29. var getDialogMinWidth = function (editor) {
  30. return Math.min(global$1.DOM.getViewPort().w, editor.getParam('codesample_dialog_width', 800));
  31. };
  32. var getDialogMinHeight = function (editor) {
  33. return Math.min(global$1.DOM.getViewPort().w, editor.getParam('codesample_dialog_height', 650));
  34. };
  35. var $_fwpmvkabjkmcwo95 = {
  36. getContentCss: getContentCss,
  37. getLanguages: getLanguages,
  38. getDialogMinWidth: getDialogMinWidth,
  39. getDialogMinHeight: getDialogMinHeight
  40. };
  41. var window$$1 = {};
  42. var global$2 = window$$1;
  43. var _self = typeof window$$1 !== 'undefined' ? window$$1 : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : {};
  44. var Prism = function () {
  45. var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
  46. var _ = _self.Prism = {
  47. util: {
  48. encode: function (tokens) {
  49. if (tokens instanceof Token) {
  50. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  51. } else if (_.util.type(tokens) === 'Array') {
  52. return tokens.map(_.util.encode);
  53. } else {
  54. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  55. }
  56. },
  57. type: function (o) {
  58. return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
  59. },
  60. clone: function (o) {
  61. var type = _.util.type(o);
  62. switch (type) {
  63. case 'Object':
  64. var clone = {};
  65. for (var key in o) {
  66. if (o.hasOwnProperty(key)) {
  67. clone[key] = _.util.clone(o[key]);
  68. }
  69. }
  70. return clone;
  71. case 'Array':
  72. return o.map && o.map(function (v) {
  73. return _.util.clone(v);
  74. });
  75. }
  76. return o;
  77. }
  78. },
  79. languages: {
  80. extend: function (id, redef) {
  81. var lang = _.util.clone(_.languages[id]);
  82. for (var key in redef) {
  83. lang[key] = redef[key];
  84. }
  85. return lang;
  86. },
  87. insertBefore: function (inside, before, insert, root) {
  88. root = root || _.languages;
  89. var grammar = root[inside];
  90. if (arguments.length === 2) {
  91. insert = arguments[1];
  92. for (var newToken in insert) {
  93. if (insert.hasOwnProperty(newToken)) {
  94. grammar[newToken] = insert[newToken];
  95. }
  96. }
  97. return grammar;
  98. }
  99. var ret = {};
  100. for (var token in grammar) {
  101. if (grammar.hasOwnProperty(token)) {
  102. if (token === before) {
  103. for (var newToken in insert) {
  104. if (insert.hasOwnProperty(newToken)) {
  105. ret[newToken] = insert[newToken];
  106. }
  107. }
  108. }
  109. ret[token] = grammar[token];
  110. }
  111. }
  112. _.languages.DFS(_.languages, function (key, value) {
  113. if (value === root[inside] && key !== inside) {
  114. this[key] = ret;
  115. }
  116. });
  117. return root[inside] = ret;
  118. },
  119. DFS: function (o, callback, type) {
  120. for (var i in o) {
  121. if (o.hasOwnProperty(i)) {
  122. callback.call(o, i, o[i], type || i);
  123. if (_.util.type(o[i]) === 'Object') {
  124. _.languages.DFS(o[i], callback);
  125. } else if (_.util.type(o[i]) === 'Array') {
  126. _.languages.DFS(o[i], callback, i);
  127. }
  128. }
  129. }
  130. }
  131. },
  132. plugins: {},
  133. highlightAll: function (async, callback) {
  134. var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
  135. for (var i = 0, element = void 0; element = elements[i++];) {
  136. _.highlightElement(element, async === true, callback);
  137. }
  138. },
  139. highlightElement: function (element, async, callback) {
  140. var language, grammar, parent$$1 = element;
  141. while (parent$$1 && !lang.test(parent$$1.className)) {
  142. parent$$1 = parent$$1.parentNode;
  143. }
  144. if (parent$$1) {
  145. language = (parent$$1.className.match(lang) || [
  146. ,
  147. ''
  148. ])[1];
  149. grammar = _.languages[language];
  150. }
  151. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  152. parent$$1 = element.parentNode;
  153. if (/pre/i.test(parent$$1.nodeName)) {
  154. parent$$1.className = parent$$1.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  155. }
  156. var code = element.textContent;
  157. var env = {
  158. element: element,
  159. language: language,
  160. grammar: grammar,
  161. code: code
  162. };
  163. if (!code || !grammar) {
  164. _.hooks.run('complete', env);
  165. return;
  166. }
  167. _.hooks.run('before-highlight', env);
  168. if (async && _self.Worker) {
  169. var worker = new Worker(_.filename);
  170. worker.onmessage = function (evt) {
  171. env.highlightedCode = evt.data;
  172. _.hooks.run('before-insert', env);
  173. env.element.innerHTML = env.highlightedCode;
  174. if (callback) {
  175. callback.call(env.element);
  176. }
  177. _.hooks.run('after-highlight', env);
  178. _.hooks.run('complete', env);
  179. };
  180. worker.postMessage(JSON.stringify({
  181. language: env.language,
  182. code: env.code,
  183. immediateClose: true
  184. }));
  185. } else {
  186. env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
  187. _.hooks.run('before-insert', env);
  188. env.element.innerHTML = env.highlightedCode;
  189. if (callback) {
  190. callback.call(element);
  191. }
  192. _.hooks.run('after-highlight', env);
  193. _.hooks.run('complete', env);
  194. }
  195. },
  196. highlight: function (text, grammar, language) {
  197. var tokens = _.tokenize(text, grammar);
  198. return Token.stringify(_.util.encode(tokens), language);
  199. },
  200. tokenize: function (text, grammar, language) {
  201. var Token = _.Token;
  202. var strarr = [text];
  203. var rest = grammar.rest;
  204. if (rest) {
  205. for (var token in rest) {
  206. grammar[token] = rest[token];
  207. }
  208. delete grammar.rest;
  209. }
  210. tokenloop:
  211. for (var token in grammar) {
  212. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  213. continue;
  214. }
  215. var patterns = grammar[token];
  216. patterns = _.util.type(patterns) === 'Array' ? patterns : [patterns];
  217. for (var j = 0; j < patterns.length; ++j) {
  218. var pattern = patterns[j];
  219. var inside = pattern.inside;
  220. var lookbehind = !!pattern.lookbehind;
  221. var lookbehindLength = 0;
  222. var alias = pattern.alias;
  223. pattern = pattern.pattern || pattern;
  224. for (var i = 0; i < strarr.length; i++) {
  225. var str = strarr[i];
  226. if (strarr.length > text.length) {
  227. break tokenloop;
  228. }
  229. if (str instanceof Token) {
  230. continue;
  231. }
  232. pattern.lastIndex = 0;
  233. var match = pattern.exec(str);
  234. if (match) {
  235. if (lookbehind) {
  236. lookbehindLength = match[1].length;
  237. }
  238. var from = match.index - 1 + lookbehindLength;
  239. match = match[0].slice(lookbehindLength);
  240. var len = match.length, to = from + len, before = str.slice(0, from + 1), after = str.slice(to + 1);
  241. var args = [
  242. i,
  243. 1
  244. ];
  245. if (before) {
  246. args.push(before);
  247. }
  248. var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias);
  249. args.push(wrapped);
  250. if (after) {
  251. args.push(after);
  252. }
  253. Array.prototype.splice.apply(strarr, args);
  254. }
  255. }
  256. }
  257. }
  258. return strarr;
  259. },
  260. hooks: {
  261. all: {},
  262. add: function (name$$1, callback) {
  263. var hooks = _.hooks.all;
  264. hooks[name$$1] = hooks[name$$1] || [];
  265. hooks[name$$1].push(callback);
  266. },
  267. run: function (name$$1, env) {
  268. var callbacks = _.hooks.all[name$$1];
  269. if (!callbacks || !callbacks.length) {
  270. return;
  271. }
  272. for (var i = 0, callback = void 0; callback = callbacks[i++];) {
  273. callback(env);
  274. }
  275. }
  276. }
  277. };
  278. var Token = _.Token = function (type, content, alias) {
  279. this.type = type;
  280. this.content = content;
  281. this.alias = alias;
  282. };
  283. Token.stringify = function (o, language, parent$$1) {
  284. if (typeof o === 'string') {
  285. return o;
  286. }
  287. if (_.util.type(o) === 'Array') {
  288. return o.map(function (element) {
  289. return Token.stringify(element, language, o);
  290. }).join('');
  291. }
  292. var env = {
  293. type: o.type,
  294. content: Token.stringify(o.content, language, parent$$1),
  295. tag: 'span',
  296. classes: [
  297. 'token',
  298. o.type
  299. ],
  300. attributes: {},
  301. language: language,
  302. parent: parent$$1
  303. };
  304. if (env.type === 'comment') {
  305. env.attributes.spellcheck = 'true';
  306. }
  307. if (o.alias) {
  308. var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
  309. Array.prototype.push.apply(env.classes, aliases);
  310. }
  311. _.hooks.run('wrap', env);
  312. var attributes = '';
  313. for (var name$$1 in env.attributes) {
  314. attributes += (attributes ? ' ' : '') + name$$1 + '="' + (env.attributes[name$$1] || '') + '"';
  315. }
  316. return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + '</' + env.tag + '>';
  317. };
  318. if (!_self.document) {
  319. if (!_self.addEventListener) {
  320. return _self.Prism;
  321. }
  322. _self.addEventListener('message', function (evt) {
  323. var message = JSON.parse(evt.data), lang = message.language, code = message.code, immediateClose = message.immediateClose;
  324. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  325. if (immediateClose) {
  326. _self.close();
  327. }
  328. }, false);
  329. return _self.Prism;
  330. }
  331. }();
  332. if (typeof global$2 !== 'undefined') {
  333. global$2.Prism = Prism;
  334. }
  335. Prism.languages.markup = {
  336. comment: /<!--[\w\W]*?-->/,
  337. prolog: /<\?[\w\W]+?\?>/,
  338. doctype: /<!DOCTYPE[\w\W]+?>/,
  339. cdata: /<!\[CDATA\[[\w\W]*?]]>/i,
  340. tag: {
  341. pattern: /<\/?[^\s>\/=.]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
  342. inside: {
  343. 'tag': {
  344. pattern: /^<\/?[^\s>\/]+/i,
  345. inside: {
  346. punctuation: /^<\/?/,
  347. namespace: /^[^\s>\/:]+:/
  348. }
  349. },
  350. 'attr-value': {
  351. pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
  352. inside: { punctuation: /[=>"']/ }
  353. },
  354. 'punctuation': /\/?>/,
  355. 'attr-name': {
  356. pattern: /[^\s>\/]+/,
  357. inside: { namespace: /^[^\s>\/:]+:/ }
  358. }
  359. }
  360. },
  361. entity: /&#?[\da-z]{1,8};/i
  362. };
  363. Prism.hooks.add('wrap', function (env) {
  364. if (env.type === 'entity') {
  365. env.attributes.title = env.content.replace(/&amp;/, '&');
  366. }
  367. });
  368. Prism.languages.xml = Prism.languages.markup;
  369. Prism.languages.html = Prism.languages.markup;
  370. Prism.languages.mathml = Prism.languages.markup;
  371. Prism.languages.svg = Prism.languages.markup;
  372. Prism.languages.css = {
  373. comment: /\/\*[\w\W]*?\*\//,
  374. atrule: {
  375. pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
  376. inside: { rule: /@[\w-]+/ }
  377. },
  378. url: /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
  379. selector: /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
  380. string: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
  381. property: /(\b|\B)[\w-]+(?=\s*:)/i,
  382. important: /\B!important\b/i,
  383. function: /[-a-z0-9]+(?=\()/i,
  384. punctuation: /[(){};:]/
  385. };
  386. Prism.languages.css.atrule.inside.rest = Prism.util.clone(Prism.languages.css);
  387. if (Prism.languages.markup) {
  388. Prism.languages.insertBefore('markup', 'tag', {
  389. style: {
  390. pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
  391. inside: {
  392. tag: {
  393. pattern: /<style[\w\W]*?>|<\/style>/i,
  394. inside: Prism.languages.markup.tag.inside
  395. },
  396. rest: Prism.languages.css
  397. },
  398. alias: 'language-css'
  399. }
  400. });
  401. Prism.languages.insertBefore('inside', 'attr-value', {
  402. 'style-attr': {
  403. pattern: /\s*style=("|').*?\1/i,
  404. inside: {
  405. 'attr-name': {
  406. pattern: /^\s*style/i,
  407. inside: Prism.languages.markup.tag.inside
  408. },
  409. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  410. 'attr-value': {
  411. pattern: /.+/i,
  412. inside: Prism.languages.css
  413. }
  414. },
  415. alias: 'language-css'
  416. }
  417. }, Prism.languages.markup.tag);
  418. }
  419. Prism.languages.clike = {
  420. 'comment': [
  421. {
  422. pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
  423. lookbehind: true
  424. },
  425. {
  426. pattern: /(^|[^\\:])\/\/.*/,
  427. lookbehind: true
  428. }
  429. ],
  430. 'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  431. 'class-name': {
  432. pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
  433. lookbehind: true,
  434. inside: { punctuation: /(\.|\\)/ }
  435. },
  436. 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  437. 'boolean': /\b(true|false)\b/,
  438. 'function': /[a-z0-9_]+(?=\()/i,
  439. 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
  440. 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
  441. 'punctuation': /[{}[\];(),.:]/
  442. };
  443. Prism.languages.javascript = Prism.languages.extend('clike', {
  444. keyword: /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|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|true|try|typeof|var|void|while|with|yield)\b/,
  445. number: /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
  446. function: /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
  447. });
  448. Prism.languages.insertBefore('javascript', 'keyword', {
  449. regex: {
  450. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
  451. lookbehind: true
  452. }
  453. });
  454. Prism.languages.insertBefore('javascript', 'class-name', {
  455. 'template-string': {
  456. pattern: /`(?:\\`|\\?[^`])*`/,
  457. inside: {
  458. interpolation: {
  459. pattern: /\$\{[^}]+\}/,
  460. inside: {
  461. 'interpolation-punctuation': {
  462. pattern: /^\$\{|\}$/,
  463. alias: 'punctuation'
  464. },
  465. 'rest': Prism.languages.javascript
  466. }
  467. },
  468. string: /[\s\S]+/
  469. }
  470. }
  471. });
  472. if (Prism.languages.markup) {
  473. Prism.languages.insertBefore('markup', 'tag', {
  474. script: {
  475. pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
  476. inside: {
  477. tag: {
  478. pattern: /<script[\w\W]*?>|<\/script>/i,
  479. inside: Prism.languages.markup.tag.inside
  480. },
  481. rest: Prism.languages.javascript
  482. },
  483. alias: 'language-javascript'
  484. }
  485. });
  486. }
  487. Prism.languages.js = Prism.languages.javascript;
  488. Prism.languages.c = Prism.languages.extend('clike', {
  489. keyword: /\b(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/,
  490. operator: /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/,
  491. number: /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i
  492. });
  493. Prism.languages.insertBefore('c', 'string', {
  494. macro: {
  495. pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
  496. lookbehind: true,
  497. alias: 'property',
  498. inside: {
  499. string: {
  500. pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
  501. lookbehind: true
  502. }
  503. }
  504. }
  505. });
  506. delete Prism.languages.c['class-name'];
  507. delete Prism.languages.c.boolean;
  508. Prism.languages.csharp = Prism.languages.extend('clike', {
  509. keyword: /\b(abstract|as|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|add|alias|ascending|async|await|descending|dynamic|from|get|global|group|into|join|let|orderby|partial|remove|select|set|value|var|where|yield)\b/,
  510. string: [
  511. /@("|')(\1\1|\\\1|\\?(?!\1)[\s\S])*\1/,
  512. /("|')(\\?.)*?\1/
  513. ],
  514. number: /\b-?(0x[\da-f]+|\d*\.?\d+)\b/i
  515. });
  516. Prism.languages.insertBefore('csharp', 'keyword', {
  517. preprocessor: {
  518. pattern: /(^\s*)#.*/m,
  519. lookbehind: true
  520. }
  521. });
  522. Prism.languages.cpp = Prism.languages.extend('c', {
  523. 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|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/,
  524. boolean: /\b(true|false)\b/,
  525. operator: /[-+]{1,2}|!=?|<{1,2}=?|>{1,2}=?|\->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|?\||\?|\*|\/|\b(and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/
  526. });
  527. Prism.languages.insertBefore('cpp', 'keyword', {
  528. 'class-name': {
  529. pattern: /(class\s+)[a-z0-9_]+/i,
  530. lookbehind: true
  531. }
  532. });
  533. Prism.languages.java = Prism.languages.extend('clike', {
  534. keyword: /\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,
  535. number: /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,
  536. operator: {
  537. pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
  538. lookbehind: true
  539. }
  540. });
  541. Prism.languages.php = Prism.languages.extend('clike', {
  542. keyword: /\b(and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i,
  543. constant: /\b[A-Z0-9_]{2,}\b/,
  544. comment: {
  545. pattern: /(^|[^\\])(?:\/\*[\w\W]*?\*\/|\/\/.*)/,
  546. lookbehind: true
  547. }
  548. });
  549. Prism.languages.insertBefore('php', 'class-name', {
  550. 'shell-comment': {
  551. pattern: /(^|[^\\])#.*/,
  552. lookbehind: true,
  553. alias: 'comment'
  554. }
  555. });
  556. Prism.languages.insertBefore('php', 'keyword', {
  557. delimiter: /\?>|<\?(?:php)?/i,
  558. variable: /\$\w+\b/i,
  559. package: {
  560. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  561. lookbehind: true,
  562. inside: { punctuation: /\\/ }
  563. }
  564. });
  565. Prism.languages.insertBefore('php', 'operator', {
  566. property: {
  567. pattern: /(->)[\w]+/,
  568. lookbehind: true
  569. }
  570. });
  571. if (Prism.languages.markup) {
  572. Prism.hooks.add('before-highlight', function (env) {
  573. if (env.language !== 'php') {
  574. return;
  575. }
  576. env.tokenStack = [];
  577. env.backupCode = env.code;
  578. env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function (match) {
  579. env.tokenStack.push(match);
  580. return '{{{PHP' + env.tokenStack.length + '}}}';
  581. });
  582. });
  583. Prism.hooks.add('before-insert', function (env) {
  584. if (env.language === 'php') {
  585. env.code = env.backupCode;
  586. delete env.backupCode;
  587. }
  588. });
  589. Prism.hooks.add('after-highlight', function (env) {
  590. if (env.language !== 'php') {
  591. return;
  592. }
  593. for (var i = 0, t = void 0; t = env.tokenStack[i]; i++) {
  594. env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$'));
  595. }
  596. env.element.innerHTML = env.highlightedCode;
  597. });
  598. Prism.hooks.add('wrap', function (env) {
  599. if (env.language === 'php' && env.type === 'markup') {
  600. env.content = env.content.replace(/(\{\{\{PHP[0-9]+\}\}\})/g, '<span class="token php">$1</span>');
  601. }
  602. });
  603. Prism.languages.insertBefore('php', 'comment', {
  604. markup: {
  605. pattern: /<[^?]\/?(.*?)>/,
  606. inside: Prism.languages.markup
  607. },
  608. php: /\{\{\{PHP[0-9]+\}\}\}/
  609. });
  610. }
  611. Prism.languages.python = {
  612. 'comment': {
  613. pattern: /(^|[^\\])#.*/,
  614. lookbehind: true
  615. },
  616. 'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(?:\\?.)*?\1/,
  617. 'function': {
  618. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,
  619. lookbehind: true
  620. },
  621. 'class-name': {
  622. pattern: /(\bclass\s+)[a-z0-9_]+/i,
  623. lookbehind: true
  624. },
  625. 'keyword': /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,
  626. 'boolean': /\b(?:True|False)\b/,
  627. 'number': /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  628. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  629. 'punctuation': /[{}[\];(),.:]/
  630. };
  631. (function (Prism) {
  632. Prism.languages.ruby = Prism.languages.extend('clike', {
  633. comment: /#(?!\{[^\r\n]*?\}).*/,
  634. keyword: /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
  635. });
  636. var interpolation = {
  637. pattern: /#\{[^}]+\}/,
  638. inside: {
  639. delimiter: {
  640. pattern: /^#\{|\}$/,
  641. alias: 'tag'
  642. },
  643. rest: Prism.util.clone(Prism.languages.ruby)
  644. }
  645. };
  646. Prism.languages.insertBefore('ruby', 'keyword', {
  647. regex: [
  648. {
  649. pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
  650. inside: { interpolation: interpolation }
  651. },
  652. {
  653. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  654. inside: { interpolation: interpolation }
  655. },
  656. {
  657. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  658. inside: { interpolation: interpolation }
  659. },
  660. {
  661. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  662. inside: { interpolation: interpolation }
  663. },
  664. {
  665. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  666. inside: { interpolation: interpolation }
  667. },
  668. {
  669. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
  670. lookbehind: true
  671. }
  672. ],
  673. variable: /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
  674. symbol: /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
  675. });
  676. Prism.languages.insertBefore('ruby', 'number', {
  677. builtin: /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  678. constant: /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
  679. });
  680. Prism.languages.ruby.string = [
  681. {
  682. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
  683. inside: { interpolation: interpolation }
  684. },
  685. {
  686. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  687. inside: { interpolation: interpolation }
  688. },
  689. {
  690. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  691. inside: { interpolation: interpolation }
  692. },
  693. {
  694. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  695. inside: { interpolation: interpolation }
  696. },
  697. {
  698. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  699. inside: { interpolation: interpolation }
  700. },
  701. {
  702. pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
  703. inside: { interpolation: interpolation }
  704. }
  705. ];
  706. }(Prism));
  707. function isCodeSample(elm) {
  708. return elm && elm.nodeName === 'PRE' && elm.className.indexOf('language-') !== -1;
  709. }
  710. function trimArg(predicateFn) {
  711. return function (arg1, arg2) {
  712. return predicateFn(arg2);
  713. };
  714. }
  715. var $_45zyxsagjkmcwoas = {
  716. isCodeSample: isCodeSample,
  717. trimArg: trimArg
  718. };
  719. var getSelectedCodeSample = function (editor) {
  720. var node = editor.selection.getNode();
  721. if ($_45zyxsagjkmcwoas.isCodeSample(node)) {
  722. return node;
  723. }
  724. return null;
  725. };
  726. var insertCodeSample = function (editor, language, code) {
  727. editor.undoManager.transact(function () {
  728. var node = getSelectedCodeSample(editor);
  729. code = global$1.DOM.encode(code);
  730. if (node) {
  731. editor.dom.setAttrib(node, 'class', 'language-' + language);
  732. node.innerHTML = code;
  733. Prism.highlightElement(node);
  734. editor.selection.select(node);
  735. } else {
  736. editor.insertContent('<pre id="__new" class="language-' + language + '">' + code + '</pre>');
  737. editor.selection.select(editor.$('#__new').removeAttr('id')[0]);
  738. }
  739. });
  740. };
  741. var getCurrentCode = function (editor) {
  742. var node = getSelectedCodeSample(editor);
  743. if (node) {
  744. return node.textContent;
  745. }
  746. return '';
  747. };
  748. var $_7llv6ladjkmcwo9b = {
  749. getSelectedCodeSample: getSelectedCodeSample,
  750. insertCodeSample: insertCodeSample,
  751. getCurrentCode: getCurrentCode
  752. };
  753. var getLanguages$1 = function (editor) {
  754. var defaultLanguages = [
  755. {
  756. text: 'HTML/XML',
  757. value: 'markup'
  758. },
  759. {
  760. text: 'JavaScript',
  761. value: 'javascript'
  762. },
  763. {
  764. text: 'CSS',
  765. value: 'css'
  766. },
  767. {
  768. text: 'PHP',
  769. value: 'php'
  770. },
  771. {
  772. text: 'Ruby',
  773. value: 'ruby'
  774. },
  775. {
  776. text: 'Python',
  777. value: 'python'
  778. },
  779. {
  780. text: 'Java',
  781. value: 'java'
  782. },
  783. {
  784. text: 'C',
  785. value: 'c'
  786. },
  787. {
  788. text: 'C#',
  789. value: 'csharp'
  790. },
  791. {
  792. text: 'C++',
  793. value: 'cpp'
  794. }
  795. ];
  796. var customLanguages = $_fwpmvkabjkmcwo95.getLanguages(editor);
  797. return customLanguages ? customLanguages : defaultLanguages;
  798. };
  799. var getCurrentLanguage = function (editor) {
  800. var matches;
  801. var node = $_7llv6ladjkmcwo9b.getSelectedCodeSample(editor);
  802. if (node) {
  803. matches = node.className.match(/language-(\w+)/);
  804. return matches ? matches[1] : '';
  805. }
  806. return '';
  807. };
  808. var $_ehme9lahjkmcwoat = {
  809. getLanguages: getLanguages$1,
  810. getCurrentLanguage: getCurrentLanguage
  811. };
  812. var $_7apbbvaajkmcwo93 = {
  813. open: function (editor) {
  814. var minWidth = $_fwpmvkabjkmcwo95.getDialogMinWidth(editor);
  815. var minHeight = $_fwpmvkabjkmcwo95.getDialogMinHeight(editor);
  816. var currentLanguage = $_ehme9lahjkmcwoat.getCurrentLanguage(editor);
  817. var currentLanguages = $_ehme9lahjkmcwoat.getLanguages(editor);
  818. var currentCode = $_7llv6ladjkmcwo9b.getCurrentCode(editor);
  819. editor.windowManager.open({
  820. title: 'Insert/Edit code sample',
  821. minWidth: minWidth,
  822. minHeight: minHeight,
  823. layout: 'flex',
  824. direction: 'column',
  825. align: 'stretch',
  826. body: [
  827. {
  828. type: 'listbox',
  829. name: 'language',
  830. label: 'Language',
  831. maxWidth: 200,
  832. value: currentLanguage,
  833. values: currentLanguages
  834. },
  835. {
  836. type: 'textbox',
  837. name: 'code',
  838. multiline: true,
  839. spellcheck: false,
  840. ariaLabel: 'Code view',
  841. flex: 1,
  842. style: 'direction: ltr; text-align: left',
  843. classes: 'monospace',
  844. value: currentCode,
  845. autofocus: true
  846. }
  847. ],
  848. onSubmit: function (e) {
  849. $_7llv6ladjkmcwo9b.insertCodeSample(editor, e.data.language, e.data.code);
  850. }
  851. });
  852. }
  853. };
  854. var register = function (editor) {
  855. editor.addCommand('codesample', function () {
  856. var node = editor.selection.getNode();
  857. if (editor.selection.isCollapsed() || $_45zyxsagjkmcwoas.isCodeSample(node)) {
  858. $_7apbbvaajkmcwo93.open(editor);
  859. } else {
  860. editor.formatter.toggle('code');
  861. }
  862. });
  863. };
  864. var $_3nzffua9jkmcwo92 = { register: register };
  865. var setup = function (editor) {
  866. var $ = editor.$;
  867. editor.on('PreProcess', function (e) {
  868. $('pre[contenteditable=false]', e.node).filter($_45zyxsagjkmcwoas.trimArg($_45zyxsagjkmcwoas.isCodeSample)).each(function (idx, elm) {
  869. var $elm = $(elm), code = elm.textContent;
  870. $elm.attr('class', $.trim($elm.attr('class')));
  871. $elm.removeAttr('contentEditable');
  872. $elm.empty().append($('<code></code>').each(function () {
  873. this.textContent = code;
  874. }));
  875. });
  876. });
  877. editor.on('SetContent', function () {
  878. var unprocessedCodeSamples = $('pre').filter($_45zyxsagjkmcwoas.trimArg($_45zyxsagjkmcwoas.isCodeSample)).filter(function (idx, elm) {
  879. return elm.contentEditable !== 'false';
  880. });
  881. if (unprocessedCodeSamples.length) {
  882. editor.undoManager.transact(function () {
  883. unprocessedCodeSamples.each(function (idx, elm) {
  884. $(elm).find('br').each(function (idx, elm) {
  885. elm.parentNode.replaceChild(editor.getDoc().createTextNode('\n'), elm);
  886. });
  887. elm.contentEditable = false;
  888. elm.innerHTML = editor.dom.encode(elm.textContent);
  889. Prism.highlightElement(elm);
  890. elm.className = $.trim(elm.className);
  891. });
  892. });
  893. }
  894. });
  895. };
  896. var $_cywqvhaijkmcwoav = { setup: setup };
  897. var loadCss = function (editor, pluginUrl, addedInlineCss, addedCss) {
  898. var linkElm;
  899. var contentCss = $_fwpmvkabjkmcwo95.getContentCss(editor);
  900. if (editor.inline && addedInlineCss.get()) {
  901. return;
  902. }
  903. if (!editor.inline && addedCss.get()) {
  904. return;
  905. }
  906. if (editor.inline) {
  907. addedInlineCss.set(true);
  908. } else {
  909. addedCss.set(true);
  910. }
  911. if (contentCss !== false) {
  912. linkElm = editor.dom.create('link', {
  913. rel: 'stylesheet',
  914. href: contentCss ? contentCss : pluginUrl + '/css/prism.css'
  915. });
  916. editor.getDoc().getElementsByTagName('head')[0].appendChild(linkElm);
  917. }
  918. };
  919. var $_8uv0xyajjkmcwoax = { loadCss: loadCss };
  920. var register$1 = function (editor) {
  921. editor.addButton('codesample', {
  922. cmd: 'codesample',
  923. title: 'Insert/Edit code sample'
  924. });
  925. editor.addMenuItem('codesample', {
  926. cmd: 'codesample',
  927. text: 'Code sample',
  928. icon: 'codesample'
  929. });
  930. };
  931. var $_91sx9bakjkmcwoaz = { register: register$1 };
  932. var addedInlineCss = Cell(false);
  933. global.add('codesample', function (editor, pluginUrl) {
  934. var addedCss = Cell(false);
  935. $_cywqvhaijkmcwoav.setup(editor);
  936. $_91sx9bakjkmcwoaz.register(editor);
  937. $_3nzffua9jkmcwo92.register(editor);
  938. editor.on('init', function () {
  939. $_8uv0xyajjkmcwoax.loadCss(editor, pluginUrl, addedInlineCss, addedCss);
  940. });
  941. editor.on('dblclick', function (ev) {
  942. if ($_45zyxsagjkmcwoas.isCodeSample(ev.target)) {
  943. $_7apbbvaajkmcwo93.open(editor);
  944. }
  945. });
  946. });
  947. function Plugin () {
  948. }
  949. return Plugin;
  950. }());
  951. })();