This repository was archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmjpage
executable file
·135 lines (130 loc) · 3.97 KB
/
mjpage
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /usr/bin/env node
/************************************************************************
* Copyright (c) 2016 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const mjpage = require('../lib/main.js').mjpage;
const fs = require('fs');
const argv = require("yargs")
.strict()
.usage("Usage: mjpage [options] < input.html > output.html")
.options({
speech: {
boolean: true,
default: true,
describe: "include speech text"
},
linebreaks: {
boolean: true,
describe: "perform automatic line-breaking"
},
dollars: {
boolean: true,
describe: "use single-dollar delimiters"
},
fragment: {
boolean: true,
describe: "return body.innerHTML instead of full document"
},
format: {
default: "AsciiMath,TeX,MathML",
describe: "input format(s) to look for"
},
noGlobalSVG: {
boolean: true,
describe: "In SVG output use globalCache"
},
font: {
default: "TeX",
describe: "web font to use in SVG output"
},
semantics: {
boolean: true,
describe: "for TeX or Asciimath source and MathML output, add input in <semantics> tag"
},
notexhints: {
boolean: true,
describe: "for TeX input and MathML output, don't add TeX-specific classes"
},
output: {
default: "SVG",
describe: "output format (SVG, CommonHTML, or MML)"
},
eqno: {
default: "none",
describe: "equation number style (none, AMS, or all)"
},
ex: {
default: 6,
describe: "ex-size in pixels"
},
width: {
default: 100,
describe: "width of equation container in ex (for line-breaking)"
},
extensions: {
default: "",
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
},
fontURL: {
default: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/fonts/HTML-CSS",
describe: "the URL to use for web fonts"
}
})
.argv;
if (argv.font === "STIX") argv.font = "STIX-Web";
argv.format = argv.format.split(/ *, */);
const mjglobal = {
extensions: argv.extensions,
fontURL: argv.fontURL,
singleDollars: argv.dollars,
fragment: argv.fragment,
MathJax: {
SVG: {
font: argv.font
},
menuSettings: {
semantics: argv.semantics,
texHints: !argv.notexhints
}
}
};
const mjlocal = {
format: argv.format,
svg: (argv.output === 'SVG'),
useGlobalCache: !argv.noGlobalSVG,
html: (argv.output === 'CommonHTML'),
css: (argv.output === 'CommonHTML'),
mml: (argv.output === 'MML'),
equationNumbers: argv.eqno,
speakText: argv.speech,
// speakRuleset: argv.speechrules.replace(/^chromevox$/i, "default"),
// speakStyle: argv.speechstyle,
ex: argv.ex,
width: argv.width,
linebreaks: argv.linebreaks
};
//
// Read the input file and collect the file contents
// When done, process the HTML.
//
let html = "";
process.stdin.on("data", function(chunk) {
html += chunk;
});
process.stdin.on("end", function() {
mjpage(html, mjglobal, mjlocal, function(result) {
process.stdout.write(result);
});
});