1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | Prism.languages.php = Prism.languages.extend('clike', {
|
15 | '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,
|
16 | 'constant': /\b[A-Z0-9_]{2,}\b/,
|
17 | 'comment': {
|
18 | pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,
|
19 | lookbehind: true
|
20 | }
|
21 | });
|
22 |
|
23 |
|
24 |
|
25 | Prism.languages.insertBefore('php', 'class-name', {
|
26 | 'shell-comment': {
|
27 | pattern: /(^|[^\\])#.*?(\r?\n|$)/,
|
28 | lookbehind: true,
|
29 | alias: 'comment'
|
30 | }
|
31 | });
|
32 |
|
33 | Prism.languages.insertBefore('php', 'keyword', {
|
34 | 'delimiter': /(\?>|<\?php|<\?)/i,
|
35 | 'variable': /(\$\w+)\b/i,
|
36 | 'package': {
|
37 | pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
|
38 | lookbehind: true,
|
39 | inside: {
|
40 | punctuation: /\\/
|
41 | }
|
42 | }
|
43 | });
|
44 |
|
45 |
|
46 | Prism.languages.insertBefore('php', 'operator', {
|
47 | 'property': {
|
48 | pattern: /(->)[\w]+/,
|
49 | lookbehind: true
|
50 | }
|
51 | });
|
52 |
|
53 |
|
54 | if (Prism.languages.markup) {
|
55 |
|
56 |
|
57 |
|
58 | Prism.hooks.add('before-highlight', function(env) {
|
59 | if (env.language !== 'php') {
|
60 | return;
|
61 | }
|
62 |
|
63 | env.tokenStack = [];
|
64 |
|
65 | env.backupCode = env.code;
|
66 | env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {
|
67 | env.tokenStack.push(match);
|
68 |
|
69 | return '{{{PHP' + env.tokenStack.length + '}}}';
|
70 | });
|
71 | });
|
72 |
|
73 |
|
74 | Prism.hooks.add('before-insert', function(env) {
|
75 | if (env.language === 'php') {
|
76 | env.code = env.backupCode;
|
77 | delete env.backupCode;
|
78 | }
|
79 | });
|
80 |
|
81 |
|
82 | Prism.hooks.add('after-highlight', function(env) {
|
83 | if (env.language !== 'php') {
|
84 | return;
|
85 | }
|
86 |
|
87 | for (var i = 0, t; t = env.tokenStack[i]; i++) {
|
88 | env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php'));
|
89 | }
|
90 |
|
91 | env.element.innerHTML = env.highlightedCode;
|
92 | });
|
93 |
|
94 |
|
95 | Prism.hooks.add('wrap', function(env) {
|
96 | if (env.language === 'php' && env.type === 'markup') {
|
97 | env.content = env.content.replace(/(\{\{\{PHP[0-9]+\}\}\})/g, "<span class=\"token php\">$1</span>");
|
98 | }
|
99 | });
|
100 |
|
101 |
|
102 | Prism.languages.insertBefore('php', 'comment', {
|
103 | 'markup': {
|
104 | pattern: /<[^?]\/?(.*?)>/,
|
105 | inside: Prism.languages.markup
|
106 | },
|
107 | 'php': /\{\{\{PHP[0-9]+\}\}\}/
|
108 | });
|
109 | }
|