Skip to content

Commit cce77e1

Browse files
committed
Move language name definitions to PHP
1 parent db0046d commit cce77e1

File tree

7 files changed

+216
-211
lines changed

7 files changed

+216
-211
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = function (grunt) {
4848

4949
const paths = [
5050
'syntax-highlighting-code-block.php',
51+
'language-names.php',
5152
'editor-styles.css',
5253
'style.css',
5354
'readme.txt',

bin/generate-language-names.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
exit( 1 );
99
}
1010

11-
$output_file = dirname( __DIR__ ) . '/src/language-names.js';
11+
$output_file_php = dirname( __DIR__ ) . '/language-names.php';
1212

1313
$language_names = [];
1414

@@ -25,22 +25,21 @@
2525
$language_names[ $slug ] = $matches[1];
2626
}
2727

28-
$js = "/* eslint-disable */\n";
29-
$js .= sprintf( "// File generated by %s. Do not edit directly.\n", basename( __DIR__ ) . '/' . basename( __FILE__ ) );
30-
$js .= "import { __ } from '@wordpress/i18n';\n";
31-
$js .= "\n";
32-
$js .= "const LANGUAGE_NAMES = {\n";
33-
28+
$php = "<?php\n// phpcs:ignoreFile\n";
29+
$php .= sprintf( "// File generated by %s. Do not edit directly.\n", basename( __DIR__ ) . '/' . basename( __FILE__ ) );
30+
$php .= "return [\n";
3431
foreach ( $language_names as $slug => $name ) {
35-
$js .= sprintf( "\t%s: __( %s, 'syntax-highlighting-code-block' ),\n", json_encode( $slug ), json_encode( $name, JSON_UNESCAPED_UNICODE ) );
32+
$php .= sprintf(
33+
"\t%s => __( %s, 'syntax-highlighting-code-block' ),\n",
34+
var_export( $slug, true ),
35+
var_export( $name, true )
36+
);
3637
}
37-
$js .= "};\n";
38-
$js .= "\n";
39-
$js .= "export default LANGUAGE_NAMES;\n";
38+
$php .= "];\n";
4039

41-
if ( ! file_put_contents( $output_file, $js ) ) {
42-
echo "Unable to write to $output_file\n";
40+
if ( ! file_put_contents( $output_file_php, $php ) ) {
41+
echo "Unable to write to $output_file_php\n";
4342
exit( 1 );
4443
}
4544

46-
echo "Done. Wrote to $output_file.\n";
45+
echo "Done. Wrote to $output_file_php.\n";

bin/update-highlight-libs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install --save-dev "highlightjs/highlight.js#$current_highlight_js_version"
2222

2323
php bin/generate-language-names.php
2424

25-
git add composer.json composer.lock package-lock.json package.json src/language-names.js
25+
git add composer.json composer.lock package-lock.json package.json language-names.php
2626

2727
git status
2828

language-names.php

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
// phpcs:ignoreFile
3+
// File generated by bin/generate-language-names.php. Do not edit directly.
4+
return [
5+
'1c' => __( '1C:Enterprise (v7, v8)', 'syntax-highlighting-code-block' ),
6+
'abnf' => __( 'Augmented Backus-Naur Form', 'syntax-highlighting-code-block' ),
7+
'accesslog' => __( 'Access log', 'syntax-highlighting-code-block' ),
8+
'actionscript' => __( 'ActionScript', 'syntax-highlighting-code-block' ),
9+
'ada' => __( 'Ada', 'syntax-highlighting-code-block' ),
10+
'angelscript' => __( 'AngelScript', 'syntax-highlighting-code-block' ),
11+
'apache' => __( 'Apache', 'syntax-highlighting-code-block' ),
12+
'applescript' => __( 'AppleScript', 'syntax-highlighting-code-block' ),
13+
'arcade' => __( 'ArcGIS Arcade', 'syntax-highlighting-code-block' ),
14+
'arduino' => __( 'Arduino', 'syntax-highlighting-code-block' ),
15+
'armasm' => __( 'ARM Assembly', 'syntax-highlighting-code-block' ),
16+
'asciidoc' => __( 'AsciiDoc', 'syntax-highlighting-code-block' ),
17+
'aspectj' => __( 'AspectJ', 'syntax-highlighting-code-block' ),
18+
'autohotkey' => __( 'AutoHotkey', 'syntax-highlighting-code-block' ),
19+
'autoit' => __( 'AutoIt', 'syntax-highlighting-code-block' ),
20+
'avrasm' => __( 'AVR Assembler', 'syntax-highlighting-code-block' ),
21+
'awk' => __( 'Awk', 'syntax-highlighting-code-block' ),
22+
'axapta' => __( 'Microsoft Axapta (now Dynamics 365)', 'syntax-highlighting-code-block' ),
23+
'bash' => __( 'Bash', 'syntax-highlighting-code-block' ),
24+
'basic' => __( 'Basic', 'syntax-highlighting-code-block' ),
25+
'bnf' => __( 'Backus–Naur Form', 'syntax-highlighting-code-block' ),
26+
'brainfuck' => __( 'Brainfuck', 'syntax-highlighting-code-block' ),
27+
'cal' => __( 'C/AL', 'syntax-highlighting-code-block' ),
28+
'capnproto' => __( 'Cap’n Proto', 'syntax-highlighting-code-block' ),
29+
'ceylon' => __( 'Ceylon', 'syntax-highlighting-code-block' ),
30+
'clean' => __( 'Clean', 'syntax-highlighting-code-block' ),
31+
'clojure-repl' => __( 'Clojure REPL', 'syntax-highlighting-code-block' ),
32+
'clojure' => __( 'Clojure', 'syntax-highlighting-code-block' ),
33+
'cmake' => __( 'CMake', 'syntax-highlighting-code-block' ),
34+
'coffeescript' => __( 'CoffeeScript', 'syntax-highlighting-code-block' ),
35+
'coq' => __( 'Coq', 'syntax-highlighting-code-block' ),
36+
'cos' => __( 'Caché Object Script', 'syntax-highlighting-code-block' ),
37+
'cpp' => __( 'C++', 'syntax-highlighting-code-block' ),
38+
'crmsh' => __( 'crmsh', 'syntax-highlighting-code-block' ),
39+
'crystal' => __( 'Crystal', 'syntax-highlighting-code-block' ),
40+
'cs' => __( 'C#', 'syntax-highlighting-code-block' ),
41+
'csp' => __( 'CSP', 'syntax-highlighting-code-block' ),
42+
'css' => __( 'CSS', 'syntax-highlighting-code-block' ),
43+
'd' => __( 'D', 'syntax-highlighting-code-block' ),
44+
'dart' => __( 'Dart', 'syntax-highlighting-code-block' ),
45+
'delphi' => __( 'Delphi', 'syntax-highlighting-code-block' ),
46+
'diff' => __( 'Diff', 'syntax-highlighting-code-block' ),
47+
'django' => __( 'Django', 'syntax-highlighting-code-block' ),
48+
'dns' => __( 'DNS Zone file', 'syntax-highlighting-code-block' ),
49+
'dockerfile' => __( 'Dockerfile', 'syntax-highlighting-code-block' ),
50+
'dos' => __( 'DOS .bat', 'syntax-highlighting-code-block' ),
51+
'dsconfig' => __( 'dsconfig', 'syntax-highlighting-code-block' ),
52+
'dts' => __( 'Device Tree', 'syntax-highlighting-code-block' ),
53+
'dust' => __( 'Dust', 'syntax-highlighting-code-block' ),
54+
'ebnf' => __( 'Extended Backus-Naur Form', 'syntax-highlighting-code-block' ),
55+
'elixir' => __( 'Elixir', 'syntax-highlighting-code-block' ),
56+
'elm' => __( 'Elm', 'syntax-highlighting-code-block' ),
57+
'erb' => __( 'ERB (Embedded Ruby)', 'syntax-highlighting-code-block' ),
58+
'erlang-repl' => __( 'Erlang REPL', 'syntax-highlighting-code-block' ),
59+
'erlang' => __( 'Erlang', 'syntax-highlighting-code-block' ),
60+
'excel' => __( 'Excel', 'syntax-highlighting-code-block' ),
61+
'fix' => __( 'FIX', 'syntax-highlighting-code-block' ),
62+
'flix' => __( 'Flix', 'syntax-highlighting-code-block' ),
63+
'fortran' => __( 'Fortran', 'syntax-highlighting-code-block' ),
64+
'fsharp' => __( 'F#', 'syntax-highlighting-code-block' ),
65+
'gams' => __( 'GAMS', 'syntax-highlighting-code-block' ),
66+
'gauss' => __( 'GAUSS', 'syntax-highlighting-code-block' ),
67+
'gcode' => __( 'G-code (ISO 6983)', 'syntax-highlighting-code-block' ),
68+
'gherkin' => __( 'Gherkin', 'syntax-highlighting-code-block' ),
69+
'glsl' => __( 'GLSL', 'syntax-highlighting-code-block' ),
70+
'gml' => __( 'GML', 'syntax-highlighting-code-block' ),
71+
'go' => __( 'Go', 'syntax-highlighting-code-block' ),
72+
'golo' => __( 'Golo', 'syntax-highlighting-code-block' ),
73+
'gradle' => __( 'Gradle', 'syntax-highlighting-code-block' ),
74+
'groovy' => __( 'Groovy', 'syntax-highlighting-code-block' ),
75+
'haml' => __( 'Haml', 'syntax-highlighting-code-block' ),
76+
'handlebars' => __( 'Handlebars', 'syntax-highlighting-code-block' ),
77+
'haskell' => __( 'Haskell', 'syntax-highlighting-code-block' ),
78+
'haxe' => __( 'Haxe', 'syntax-highlighting-code-block' ),
79+
'hsp' => __( 'HSP', 'syntax-highlighting-code-block' ),
80+
'htmlbars' => __( 'HTMLBars', 'syntax-highlighting-code-block' ),
81+
'http' => __( 'HTTP', 'syntax-highlighting-code-block' ),
82+
'hy' => __( 'Hy', 'syntax-highlighting-code-block' ),
83+
'inform7' => __( 'Inform 7', 'syntax-highlighting-code-block' ),
84+
'ini' => __( 'TOML, also INI', 'syntax-highlighting-code-block' ),
85+
'irpf90' => __( 'IRPF90', 'syntax-highlighting-code-block' ),
86+
'isbl' => __( 'ISBL', 'syntax-highlighting-code-block' ),
87+
'java' => __( 'Java', 'syntax-highlighting-code-block' ),
88+
'javascript' => __( 'JavaScript', 'syntax-highlighting-code-block' ),
89+
'jboss-cli' => __( 'jboss-cli', 'syntax-highlighting-code-block' ),
90+
'json' => __( 'JSON / JSON with Comments', 'syntax-highlighting-code-block' ),
91+
'julia-repl' => __( 'Julia REPL', 'syntax-highlighting-code-block' ),
92+
'julia' => __( 'Julia', 'syntax-highlighting-code-block' ),
93+
'kotlin' => __( 'Kotlin', 'syntax-highlighting-code-block' ),
94+
'lasso' => __( 'Lasso', 'syntax-highlighting-code-block' ),
95+
'ldif' => __( 'LDIF', 'syntax-highlighting-code-block' ),
96+
'leaf' => __( 'Leaf', 'syntax-highlighting-code-block' ),
97+
'less' => __( 'Less', 'syntax-highlighting-code-block' ),
98+
'lisp' => __( 'Lisp', 'syntax-highlighting-code-block' ),
99+
'livecodeserver' => __( 'LiveCode', 'syntax-highlighting-code-block' ),
100+
'livescript' => __( 'LiveScript', 'syntax-highlighting-code-block' ),
101+
'llvm' => __( 'LLVM IR', 'syntax-highlighting-code-block' ),
102+
'lsl' => __( 'LSL (Linden Scripting Language)', 'syntax-highlighting-code-block' ),
103+
'lua' => __( 'Lua', 'syntax-highlighting-code-block' ),
104+
'makefile' => __( 'Makefile', 'syntax-highlighting-code-block' ),
105+
'markdown' => __( 'Markdown', 'syntax-highlighting-code-block' ),
106+
'mathematica' => __( 'Mathematica', 'syntax-highlighting-code-block' ),
107+
'matlab' => __( 'Matlab', 'syntax-highlighting-code-block' ),
108+
'maxima' => __( 'Maxima', 'syntax-highlighting-code-block' ),
109+
'mel' => __( 'MEL', 'syntax-highlighting-code-block' ),
110+
'mercury' => __( 'Mercury', 'syntax-highlighting-code-block' ),
111+
'mipsasm' => __( 'MIPS Assembly', 'syntax-highlighting-code-block' ),
112+
'mizar' => __( 'Mizar', 'syntax-highlighting-code-block' ),
113+
'mojolicious' => __( 'Mojolicious', 'syntax-highlighting-code-block' ),
114+
'monkey' => __( 'Monkey', 'syntax-highlighting-code-block' ),
115+
'moonscript' => __( 'MoonScript', 'syntax-highlighting-code-block' ),
116+
'n1ql' => __( 'N1QL', 'syntax-highlighting-code-block' ),
117+
'nginx' => __( 'Nginx', 'syntax-highlighting-code-block' ),
118+
'nimrod' => __( 'Nim (formerly Nimrod)', 'syntax-highlighting-code-block' ),
119+
'nix' => __( 'Nix', 'syntax-highlighting-code-block' ),
120+
'nsis' => __( 'NSIS', 'syntax-highlighting-code-block' ),
121+
'objectivec' => __( 'Objective-C', 'syntax-highlighting-code-block' ),
122+
'ocaml' => __( 'OCaml', 'syntax-highlighting-code-block' ),
123+
'openscad' => __( 'OpenSCAD', 'syntax-highlighting-code-block' ),
124+
'oxygene' => __( 'Oxygene', 'syntax-highlighting-code-block' ),
125+
'parser3' => __( 'Parser3', 'syntax-highlighting-code-block' ),
126+
'perl' => __( 'Perl', 'syntax-highlighting-code-block' ),
127+
'pf' => __( 'pf.conf', 'syntax-highlighting-code-block' ),
128+
'pgsql' => __( 'PostgreSQL SQL dialect and PL/pgSQL', 'syntax-highlighting-code-block' ),
129+
'php' => __( 'PHP', 'syntax-highlighting-code-block' ),
130+
'plaintext' => __( 'plaintext', 'syntax-highlighting-code-block' ),
131+
'pony' => __( 'Pony', 'syntax-highlighting-code-block' ),
132+
'powershell' => __( 'PowerShell', 'syntax-highlighting-code-block' ),
133+
'processing' => __( 'Processing', 'syntax-highlighting-code-block' ),
134+
'profile' => __( 'Python profile', 'syntax-highlighting-code-block' ),
135+
'prolog' => __( 'Prolog', 'syntax-highlighting-code-block' ),
136+
'properties' => __( 'Properties', 'syntax-highlighting-code-block' ),
137+
'protobuf' => __( 'Protocol Buffers', 'syntax-highlighting-code-block' ),
138+
'puppet' => __( 'Puppet', 'syntax-highlighting-code-block' ),
139+
'purebasic' => __( 'PureBASIC', 'syntax-highlighting-code-block' ),
140+
'python' => __( 'Python', 'syntax-highlighting-code-block' ),
141+
'q' => __( 'Q', 'syntax-highlighting-code-block' ),
142+
'qml' => __( 'QML', 'syntax-highlighting-code-block' ),
143+
'r' => __( 'R', 'syntax-highlighting-code-block' ),
144+
'reasonml' => __( 'ReasonML', 'syntax-highlighting-code-block' ),
145+
'rib' => __( 'RenderMan RIB', 'syntax-highlighting-code-block' ),
146+
'roboconf' => __( 'Roboconf', 'syntax-highlighting-code-block' ),
147+
'routeros' => __( 'Microtik RouterOS script', 'syntax-highlighting-code-block' ),
148+
'rsl' => __( 'RenderMan RSL', 'syntax-highlighting-code-block' ),
149+
'ruby' => __( 'Ruby', 'syntax-highlighting-code-block' ),
150+
'ruleslanguage' => __( 'Oracle Rules Language', 'syntax-highlighting-code-block' ),
151+
'rust' => __( 'Rust', 'syntax-highlighting-code-block' ),
152+
'sas' => __( 'SAS', 'syntax-highlighting-code-block' ),
153+
'scala' => __( 'Scala', 'syntax-highlighting-code-block' ),
154+
'scheme' => __( 'Scheme', 'syntax-highlighting-code-block' ),
155+
'scilab' => __( 'Scilab', 'syntax-highlighting-code-block' ),
156+
'scss' => __( 'SCSS', 'syntax-highlighting-code-block' ),
157+
'shell' => __( 'Shell Session', 'syntax-highlighting-code-block' ),
158+
'smali' => __( 'Smali', 'syntax-highlighting-code-block' ),
159+
'smalltalk' => __( 'Smalltalk', 'syntax-highlighting-code-block' ),
160+
'sml' => __( 'SML (Standard ML)', 'syntax-highlighting-code-block' ),
161+
'sqf' => __( 'SQF', 'syntax-highlighting-code-block' ),
162+
'sql' => __( 'SQL (Structured Query Language)', 'syntax-highlighting-code-block' ),
163+
'stan' => __( 'Stan', 'syntax-highlighting-code-block' ),
164+
'stata' => __( 'Stata', 'syntax-highlighting-code-block' ),
165+
'step21' => __( 'STEP Part 21', 'syntax-highlighting-code-block' ),
166+
'stylus' => __( 'Stylus', 'syntax-highlighting-code-block' ),
167+
'subunit' => __( 'SubUnit', 'syntax-highlighting-code-block' ),
168+
'swift' => __( 'Swift', 'syntax-highlighting-code-block' ),
169+
'taggerscript' => __( 'Tagger Script', 'syntax-highlighting-code-block' ),
170+
'tap' => __( 'Test Anything Protocol', 'syntax-highlighting-code-block' ),
171+
'tcl' => __( 'Tcl', 'syntax-highlighting-code-block' ),
172+
'tex' => __( 'TeX', 'syntax-highlighting-code-block' ),
173+
'thrift' => __( 'Thrift', 'syntax-highlighting-code-block' ),
174+
'tp' => __( 'TP', 'syntax-highlighting-code-block' ),
175+
'twig' => __( 'Twig', 'syntax-highlighting-code-block' ),
176+
'typescript' => __( 'TypeScript', 'syntax-highlighting-code-block' ),
177+
'vala' => __( 'Vala', 'syntax-highlighting-code-block' ),
178+
'vbnet' => __( 'VB.NET', 'syntax-highlighting-code-block' ),
179+
'vbscript-html' => __( 'VBScript in HTML', 'syntax-highlighting-code-block' ),
180+
'vbscript' => __( 'VBScript', 'syntax-highlighting-code-block' ),
181+
'verilog' => __( 'Verilog', 'syntax-highlighting-code-block' ),
182+
'vhdl' => __( 'VHDL', 'syntax-highlighting-code-block' ),
183+
'vim' => __( 'Vim Script', 'syntax-highlighting-code-block' ),
184+
'x86asm' => __( 'Intel x86 Assembly', 'syntax-highlighting-code-block' ),
185+
'xl' => __( 'XL', 'syntax-highlighting-code-block' ),
186+
'xml' => __( 'HTML, XML', 'syntax-highlighting-code-block' ),
187+
'xquery' => __( 'XQuery', 'syntax-highlighting-code-block' ),
188+
'yaml' => __( 'YAML', 'syntax-highlighting-code-block' ),
189+
'zephir' => __( 'Zephir', 'syntax-highlighting-code-block' ),
190+
];

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global syntaxHighlightingCodeBlockType */
1+
/* global syntaxHighlightingCodeBlockType, syntaxHighlightingCodeBlockLanguageNames */
22

33
/**
44
* External dependencies
@@ -30,13 +30,14 @@ import { escapeEditableHTML } from '@wordpress/escape-html';
3030
/**
3131
* Internal dependencies
3232
*/
33-
import languagesNames from './language-names';
3433
import {
3534
escape,
3635
escapeIncludingEditableHTML,
3736
escapeIncludingAmpersands,
3837
} from './utils';
3938

39+
const languageNames = syntaxHighlightingCodeBlockLanguageNames;
40+
4041
/**
4142
* Extend code block with syntax highlighting.
4243
*
@@ -175,7 +176,7 @@ const extendCodeBlockWithSyntaxHighlighting = (settings) => {
175176
};
176177

177178
const sortedLanguageNames = sortBy(
178-
Object.entries(languagesNames).map(([value, label]) => ({
179+
Object.entries(languageNames).map(([value, label]) => ({
179180
label,
180181
value,
181182
})),

0 commit comments

Comments
 (0)