@@ -31,35 +31,53 @@ const {TeX} = require('mathjax-full/js/input/tex.js');
3131const { MathML} = require ( 'mathjax-full/js/input/mathml.js' ) ;
3232const { SVG } = require ( 'mathjax-full/js/output/svg.js' ) ;
3333const { liteAdaptor} = require ( 'mathjax-full/js/adaptors/liteAdaptor.js' ) ;
34- // const {jsdomAdaptor} = require('mathjax-full/js/adaptors/jsdomAdaptor.js');
3534const { RegisterHTMLHandler} = require ( 'mathjax-full/js/handlers/html.js' ) ;
3635const { EnrichHandler} = require ( 'mathjax-full/js/a11y/semantic-enrich.js' ) ;
37- // const {Sre} = require('mathjax-full/js/a11y/sre.js');
38-
3936const { AllPackages} = require ( 'mathjax-full/js/input/tex/AllPackages.js' ) ;
4037
41- // const {JSDOM} = require('jsdom');
42-
4338require ( 'mathjax-full/js/util/entities/all.js' ) ;
4439
4540
4641//
4742// Get the command-line arguments
4843//
4944const argv = require ( 'yargs' )
50- . demand ( 1 ) . strict ( )
51- . usage ( '$0 [options] file.html > converted.html' )
52- . options ( {
53- packages : {
54- default : AllPackages . sort ( ) . join ( ', ' ) ,
55- describe : 'the packages to use, e.g. "base, ams"'
56- } ,
57- fontCache : {
58- default : 'global' ,
59- describe : 'cache type: local, global, none'
60- }
61- } )
62- . argv ;
45+ . demand ( 1 ) . strict ( )
46+ . usage ( '$0 [options] file.html > converted.html' )
47+ . options ( {
48+ em : {
49+ default : 16 ,
50+ describe : 'em-size in pixels'
51+ } ,
52+ ex : {
53+ default : 8 ,
54+ describe : 'ex-size in pixels'
55+ } ,
56+ packages : {
57+ default : AllPackages . sort ( ) . join ( ', ' ) ,
58+ describe : 'the packages to use, e.g. "base, ams"'
59+ } ,
60+ sre : {
61+ array : true ,
62+ nargs : 2 ,
63+ describe : 'SRE flags as key value pairs, e.g., "--sre locale de --sre domain clearspeak" generates speech in German with clearspeak rules'
64+ } ,
65+ speech : {
66+ default : 'shallow' ,
67+ describe : 'level of speech: deep, shallow, none'
68+ } ,
69+ container : {
70+ boolean : true ,
71+ describe : 'include <mjx-container> element'
72+ } ,
73+ fontCache : {
74+ default : 'global' ,
75+ describe : 'cache type: local, global, none'
76+ }
77+ } )
78+ . argv ;
79+
80+ const action = require ( './action.js' ) ;
6381
6482//
6583// Read the HTML file
@@ -70,9 +88,37 @@ const htmlfile = require('fs').readFileSync(argv._[0], 'utf8');
7088// Create DOM adaptor and register it for HTML documents
7189//
7290const adaptor = liteAdaptor ( { fontSize : argv . em } ) ;
73- // const adaptor = jsdomAdaptor(JSDOM);
7491EnrichHandler ( RegisterHTMLHandler ( adaptor ) , new MathML ( ) ) ;
75- // RegisterHTMLHandler(adaptor);
92+
93+ //
94+ // Get feature vector for SRE setup. If necessary, compute the path to the
95+ // locale JSON files explicitly.
96+ //
97+ const feature = action . dataPairs ( argv . sre ) ;
98+ feature . speech = argv . speech ;
99+ feature . json = feature . json ? feature . json :
100+ require . resolve ( 'mathjax-full/es5/sre/mathmaps/base.json' ) . replace ( / \/ b a s e \. j s o n $ / , '' ) ;
101+
102+ //
103+ // Remove container elements for all math items, by setting the typesetting
104+ // root to the svg element directly.
105+ //
106+ if ( ! argv . container ) {
107+ action . speechAction . container = [
108+ 199 ,
109+ ( doc ) => {
110+ for ( let math of doc . math ) {
111+ console . log ( math ) ;
112+ math . typesetRoot = adaptor . childNodes ( math . typesetRoot ) [ 0 ] ;
113+ }
114+ } ,
115+ ( math , doc ) => {
116+ math . typesetRoot = adaptor . childNodes ( math . typesetRoot ) [ 0 ] ;
117+ }
118+ ] ;
119+ }
120+
121+
76122
77123
78124//
@@ -82,35 +128,31 @@ const tex = new TeX({packages: argv.packages.split(/\s*,\s*/)});
82128const svg = new SVG ( { fontCache : argv . fontCache } ) ;
83129const html = mathjax . document ( htmlfile , { InputJax : tex , OutputJax : svg ,
84130 enableEnrichment : true ,
85- sre : {
86- json : '/home/sorge/git/MathJax/MathJax-src/es5/sre/mathmaps' ,
87- speech : 'deep'
88- } ,
89- renderActions : require ( './action.js' ) . speechAction
131+ sre : feature ,
132+ renderActions : action . speechAction
90133 }
91134) ;
92135
136+ console . log ( html . renderActions ) ;
93137
94138//
95139// Typeset the document
96140//
97- html . render ( ) ;
98-
99-
100- //
101- // If no math was found on the page, remove the stylesheet and font cache (if any)
102- //
103- if ( Array . from ( html . math ) . length === 0 ) {
104- adaptor . remove ( html . outputJax . svgStyles ) ;
105- const cache = adaptor . elementById ( adaptor . body ( html . document ) , 'MJX-SVG-global-cache' ) ;
106- if ( cache ) adaptor . remove ( cache ) ;
107- }
141+ mathjax . handleRetriesFor ( ( ) => html . render ( ) ) . then (
142+ ( ) => {
143+ //
144+ // If no math was found on the page, remove the stylesheet and font cache (if any)
145+ //
146+ if ( Array . from ( html . math ) . length === 0 ) {
147+ adaptor . remove ( html . outputJax . svgStyles ) ;
148+ const cache = adaptor . elementById ( adaptor . body ( html . document ) , 'MJX-SVG-global-cache' ) ;
149+ if ( cache ) adaptor . remove ( cache ) ;
150+ }
108151
109- //
110- // Output the resulting HTML
111- //
112- console . log ( adaptor . doctype ( html . document ) ) ;
113- console . log ( adaptor . outerHTML ( adaptor . root ( html . document ) ) ) ;
114- // Sre.setupEngine({json: '/home/sorge/git/MathJax/MathJax-src/es5/sre/mathmaps'})
115- // .then(() => Sre.sreReady())
116- // .then(() => { });
152+ //
153+ // Output the resulting HTML
154+ //
155+ console . log ( adaptor . doctype ( html . document ) ) ;
156+ console . log ( adaptor . outerHTML ( adaptor . root ( html . document ) ) ) ;
157+ }
158+ ) ;
0 commit comments