-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_tex2html.php
51 lines (36 loc) · 1.19 KB
/
json_tex2html.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// License: GPLv3
require 'libconverttlp.php';
$tex_json_filename = dirname(__FILE__) . '/tlp_latex.json';
if (isset($argv[1])) {
$tex_json_filename = $argv[1];
}
if (!(file_exists($tex_json_filename))) {
exit_with_error('Input JSON file ' . $tex_json_filename . ' not found.');
}
$tex_obj = json_decode(file_get_contents($tex_json_filename)) ?? 'ERROR';
if ($tex_obj==='ERROR') {
exit_with_error('JSON file was not properly parsed.');
}
$subsfile = dirname(__FILE__) . '/html_substitutions.json';
if (!(file_exists($subsfile))) {
exit_with_error("HTML big substitutions file not found.");
}
$bigsubs = json_decode(file_get_contents($subsfile)) ?? 'ERROR';
if ($bigsubs==='ERROR') {
exit_with_error("Could not parse HTML big substitutions file.");
}
$html_obj = new StdClass();
foreach($tex_obj as $pn => $ptext) {
$htext = new StdClass();
foreach ($ptext as $version => $lang_array) {
$harray = array();
foreach($lang_array as $p) {
array_push($harray, tex_to_html($p, true));
}
$htext->{$version} = $harray;
}
$html_obj->{$pn} = $htext;
}
echo json_encode($html_obj, JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
?>