|
| 1 | +#! /usr/bin/env node |
| 2 | + |
| 3 | +/************************************************************************* |
| 4 | + * |
| 5 | + * am2htmlcss |
| 6 | + * |
| 7 | + * Uses MathJax to convert an AsciiMath string to an HTML page. |
| 8 | + * |
| 9 | + * ---------------------------------------------------------------------- |
| 10 | + * |
| 11 | + * Copyright (c) 2016 The MathJax Consortium |
| 12 | + * |
| 13 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | + * you may not use this file except in compliance with the License. |
| 15 | + * You may obtain a copy of the License at |
| 16 | + * |
| 17 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | + * |
| 19 | + * Unless required by applicable law or agreed to in writing, software |
| 20 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | + * See the License for the specific language governing permissions and |
| 23 | + * limitations under the License. |
| 24 | + */ |
| 25 | + |
| 26 | +var mjAPI = require("../lib/mj-single.js"); |
| 27 | + |
| 28 | +var argv = require("yargs") |
| 29 | + .demand(1).strict() |
| 30 | + .usage("Usage: am2htmlcss [options] 'math' > file.html",{ |
| 31 | + speech: { |
| 32 | + boolean: true, |
| 33 | + describe: "include speech text" |
| 34 | + }, |
| 35 | + speechrules: { |
| 36 | + default: "mathspeak", |
| 37 | + describe: "ruleset to use for speech text (chromevox or mathspeak)" |
| 38 | + }, |
| 39 | + speechstyle: { |
| 40 | + default: "default", |
| 41 | + describe: "style to use for speech text (default, brief, sbrief)" |
| 42 | + }, |
| 43 | + linebreaks: { |
| 44 | + boolean: true, |
| 45 | + describe: "perform automatic line-breaking" |
| 46 | + }, |
| 47 | + ex: { |
| 48 | + default: 6, |
| 49 | + describe: "ex-size in pixels" |
| 50 | + }, |
| 51 | + width: { |
| 52 | + default: 100, |
| 53 | + describe: "width of container in ex" |
| 54 | + }, |
| 55 | + extensions: { |
| 56 | + default: "", |
| 57 | + describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" |
| 58 | + }, |
| 59 | + fontURL: { |
| 60 | + default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS", |
| 61 | + describe: "the URL to use for web fonts" |
| 62 | + } |
| 63 | + }) |
| 64 | + .argv; |
| 65 | + |
| 66 | +mjAPI.config({extensions: argv.extensions, fontURL: argv.fontURL}); |
| 67 | +mjAPI.start(); |
| 68 | + |
| 69 | +mjAPI.typeset({ |
| 70 | + math: argv._[0], |
| 71 | + format: "AsciiMath", |
| 72 | + html:true, css: true, |
| 73 | + speakText: argv.speech, |
| 74 | + speakRuleset: argv.speechrules.replace(/^chromevox$/i,"default"), |
| 75 | + speakStyle: argv.speechstyle, |
| 76 | + ex: argv.ex, width: argv.width, |
| 77 | + linebreaks: argv.linebreaks |
| 78 | +}, function (data) { |
| 79 | + if (!data.errors) { |
| 80 | + console.log("<!DOCTYPE html>\n<html>\n<head>"); |
| 81 | + console.log('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'); |
| 82 | + console.log("<title></title>\n<style>"); |
| 83 | + console.log(data.css); |
| 84 | + console.log("</style>\n</head>\n<body>"); |
| 85 | + console.log(data.html); |
| 86 | + console.log("</body>\n</html>"); |
| 87 | + } |
| 88 | +}); |
0 commit comments