{"_id":"@4qwerty7/mathjax-node-page","_rev":"2-1a2b83d43ab231abea6ea3e5380f97b1","name":"@4qwerty7/mathjax-node-page","dist-tags":{"latest":"3.2.1"},"versions":{"3.2.0":{"name":"@4qwerty7/mathjax-node-page","version":"3.2.0","description":"Converter for HTML fragments with mathematics using mathjax-node","main":"./lib/main.js","scripts":{"test":"tape test/*.js"},"bin":{"mjpage":"bin/mjpage"},"repository":{"type":"git","url":"git+https://github.com/pkra/mathjax-node-page.git"},"keywords":["mathjax","math","tex","mathml","png","html"],"author":{"name":"MathJax Consortium"},"license":"Apache-2.0","bugs":{"url":"https://github.com/pkra/mathjax-node-page/issues"},"homepage":"https://github.com/pkra/mathjax-node-page#readme","dependencies":{"mathjax-node":"^2.0.0","yargs":"^13.0.0"},"devDependencies":{"tape":"^4.0.0"},"gitHead":"0b19eda91d0ced7fb75e0de35a860401be3600d3","_id":"@4qwerty7/mathjax-node-page@3.2.0","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-nmzbJGSyHtYf2SAuHT0fTaa+LMQmi86z5/l8YWN+jFMEkwJJL3Fs7GJtUqkvrN23ygHMnIkQh5DTrxylBpxyGA==","shasum":"c744ea52273a772b6a1b54d0400dc1ed9cc8a401","tarball":"https://registry.npmjs.org/@4qwerty7/mathjax-node-page/-/mathjax-node-page-3.2.0.tgz","fileCount":47,"unpackedSize":307656,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffl6fCRA9TVsSAnZWagAAxioP/3Tw32j9VG1jWVK1K2eS\nG472pueBvrr9kuvbp+FYIVxbA87qVzAO8OuYxe03ifN3wa4+7OtRvMQvciBr\n1QrJU+qdCM7z4w2yJ8DhjcAI5dOGclX7NokZcvGhDU+mwzbmJB9iub8sRoG4\n4bQkLDvYQ5Yw9/DOcmzNWDdbsstsF58dGFZIXSlGRgAEcn9JxQNTxZ9/ky88\nY/4jlICYktgkooriyjC2PO/XKw4rJevJdbgok1U+JzpykKSIHHY9G4VkFkUv\nlCPfgH1CLTzAYrhnxhqa84KlYwGVXXfpaYippypQWIeNYCYQLG7ESCXhB6EG\nokr00wiYflBdKgrffz5Qfaydx06vhj5LC4tO73A7NP/9QsVKAH2OLB29bHqV\nODZlisAialRGYCVY0OBA+zMdNg68Pv2Rr0zPpGjT26AmWRBNLMahTCFesfCj\noTmFgcZog89YMd9zu8gMVKqq7E86NvxHFsq1JuUfMjlErZRoulwBz8Ff4+ZX\nMKf95AUxLKiAayyblLRhmpK5bS+eCQ/sGjyqDAqsgseTnHOEQ1Svwgmd62EE\ngwwdMCl7f7RPu5Y5phJgm5CdV5kRnA+lS400WXdpozrUzWRS3NEgj1lQJUX4\n42oUCJjLTTSPE4xFDpsaagjCfrUNnl/KihXaX0RShvb+MF6CxZi9yYxHoY6u\nV/oG\r\n=SDfw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGMrLjDunk6wuN6QsemrA9VWtGjQfQXD0X/tsh4OA6mWAiByLN0On+yVsQBENcobxCXtjY3AvbCQ8UospwUV6XBf2Q=="}]},"maintainers":[{"name":"4qwerty7","email":"ebpqwerty472123@gmail.com"}],"_npmUser":{"name":"4qwerty7","email":"ebpqwerty472123@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mathjax-node-page_3.2.0_1602117279496_0.6696232353733198"},"_hasShrinkwrap":false},"3.2.1":{"name":"@4qwerty7/mathjax-node-page","version":"3.2.1","description":"Converter for HTML fragments with mathematics using mathjax-node","main":"./lib/main.js","scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"git+https://github.com/pkra/mathjax-node-page.git"},"keywords":["mathjax","math","tex","mathml","png","html"],"author":{"name":"MathJax Consortium"},"license":"Apache-2.0","bugs":{"url":"https://github.com/pkra/mathjax-node-page/issues"},"homepage":"https://github.com/pkra/mathjax-node-page#readme","dependencies":{"mathjax-node":"^2.0.0"},"devDependencies":{"tape":"^4.0.0"},"gitHead":"043d6cbbacbcd403c2bc2d6e119c851a4248a436","_id":"@4qwerty7/mathjax-node-page@3.2.1","_nodeVersion":"16.13.1","_npmVersion":"8.3.0","dist":{"integrity":"sha512-dBZ+Sl0YLCCud3TPuRgWU0IKY3L5x355kBeLDgs+ToJUYQAyA+tVl9vFd51k+lQNeAtkKBUlwiomYJ1WvfT3Wg==","shasum":"c933ed0283b1e27b534399c29b9b18f644f4823d","tarball":"https://registry.npmjs.org/@4qwerty7/mathjax-node-page/-/mathjax-node-page-3.2.1.tgz","fileCount":45,"unpackedSize":302966,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiJgfdACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpPEg/8DYXAY54Fc5Pb8P4oLz+T9RTRAliyhUlr1oe6gfaNV4c6zBdc\r\nNiZLsrdxAYfJDAoHgxCZzzdu4dF3WD1IsIXutZUTK3e02PSxqs6WwdmtN3ZR\r\nLqiSpq4N3mevCeh158Txy8qNHPu8PTUKIjy0fgSO31xgsg1bwQRyraZKmqdK\r\nP/9l3L6NnxFOgQCz7U9xkJ0LUb6MWfIBSep3kew37GMwtWtYdJyEm/rdbWJ1\r\n3xkt8blA1dOdcYp3m1AOT01NYI3BknGARcQo0Y43Umzo/uwkfYIywXMeyvO0\r\n+55BLSz249YgW1nPpkWGhhN4DTwmxDQy1ihpxexHTK+UfscOob08NFoM+FVu\r\ntdNi1tfNThzcl1aL6itjDs82NOXVXgZbsusmyI9vAPiXU8iBNPVhXvIaSekJ\r\nYEOTvS8qqVwxCnD3v9cPEe/PyuGo8rriDjdlpcD4wUbKaH7ReTHEH7moMA2o\r\nAFtz2XG5YAwKSQis2lG4f38IOX+qqv6eAYiyqznnNTdfMk3s0VQ01Abkh5QQ\r\nNHtMc11uSGbqz0kRKXnTaYzhgEYja6d0aTy7VbwX8DfR3ioESML8pJXG0lut\r\noSPd5K8jYP23Ka34e5Gev5FUTEKhMplIi25Gj+7gHi+O8pGDgKJwEeaK8wHY\r\nI+jhxPbgF4vAl1MjabJFjbfYt2tWxMDarQc=\r\n=meJu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCRpgN5h6ctU1iE3/9qHn1D5qU4SctRrNc6TRjYUL3tCgIhAPe/SjiTnWnOLr4ZW8MmQsdxKLy3ztsceWnT7OV0UATD"}]},"_npmUser":{"name":"4qwerty7","email":"ebpqwerty472123@gmail.com"},"directories":{},"maintainers":[{"name":"4qwerty7","email":"ebpqwerty472123@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mathjax-node-page_3.2.1_1646659548939_0.6251016904258806"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-08T00:34:39.448Z","3.2.0":"2020-10-08T00:34:39.681Z","modified":"2022-04-04T10:47:19.629Z","3.2.1":"2022-03-07T13:25:49.175Z"},"maintainers":[{"name":"4qwerty7","email":"ebpqwerty472123@gmail.com"}],"description":"Converter for HTML fragments with mathematics using mathjax-node","homepage":"https://github.com/pkra/mathjax-node-page#readme","keywords":["mathjax","math","tex","mathml","png","html"],"repository":{"type":"git","url":"git+https://github.com/pkra/mathjax-node-page.git"},"author":{"name":"MathJax Consortium"},"bugs":{"url":"https://github.com/pkra/mathjax-node-page/issues"},"license":"Apache-2.0","readme":"# mathjax-node-page [![Build Status](https://travis-ci.org/pkra/mathjax-node-page.svg?branch=master)](https://travis-ci.org/pkra/mathjax-node-page)\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/pkra/mathjax-node-page.svg)](https://greenkeeper.io/)\n\nThis Node.js module builds on [mathjax-node](https://github.com/mathjax/mathjax-node) and provides processing of larger content fragments\n\n## installation\n\nUse\n\n```\nnpm install mathjax-node-page\n```\n\nto install mathjax-node-page and its dependencies.\n\n## Usage\n\nmathjax-node-page exports `mjpage` which expects four parameters:\n\n```javascript\nmjpage(input, mjpageConfig, mjnodeConfig, callback)\n```\n\nWhere `input` is a string with HTML or `jsdom` object (`JSDOM` class should be acquired via exported `JSDOM`), `pageConfig` specifies page-wide options, and `mjnodeConfig` expects mathjax-node configuration options.\n\nThe defaults for `pageConfig` are\n\n```javascript\n{\n    format: [\"MathML\", \"TeX\", \"AsciiMath\"], // determines type of pre-processors to run\n    output: '', // global override for output option; 'svg', 'html' or 'mml'\n    tex: {}, // configuration options for tex pre-processor, cf. lib/tex.js\n    ascii: {}, // configuration options for ascii pre-processor, cf. lib/ascii.js\n    singleDollars: false, // allow single-dollar delimiter for inline TeX\n    fragment: false, // return body.innerHTML instead of full document\n    cssInline: true,  // determines whether inline css should be added\n    jsdom: {...}, // jsdom-related options\n    displayMessages: false, // determines whether Message.Set() calls are logged\n    displayErrors: false, // determines whether error messages are shown on the console\n    undefinedCharError: false, // determines whether unknown characters are saved in the error array\n    extensions: '', // a convenience option to add MathJax extensions\n    fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output\n    MathJax: {}, // options MathJax configuration, see https://docs.mathjax.org\n    errorHandler: (id, wrapperNode, sourceFormula, sourceFormat, errors) => {...} // function to handle rendering error\n}\n```\nand where `mjnodeConfig` represents mathjax-node configuration options, the defaults are.\n\n```javascript\n{\n  ex: 6, // ex-size in pixels\n  width: 100, // width of math container (in ex) for linebreaking and tags\n  useFontCache: true, // use <defs> and <use> in svg output?\n  useGlobalCache: false, // use common <defs> for all equations?\n  state: mjstate, // track global state\n  linebreaks: false, // do linebreaking?\n  equationNumbers: \"none\", // or \"AMS\" or \"all\"\n  math: \"\", // the math to typeset\n  html: false, // generate HTML output?\n  css: false, // generate CSS for HTML output?\n  mml: false, // generate mml output?\n  svg: false, // generate svg output?\n  speakText: true, // add spoken annotations to output?\n  timeout: 10 * 1000, // 10 second timeout before restarting MathJax\n}\n```\n\n## Advanced usage\n### mathjax-node customization\nmathjax-node-page exports `init` function that allows you to pass in a custom `mathjax-node`  (for example, [mathjax-node-svg2png](https://github.com/pkra/mathjax-node-svg2png)).\n```javascript\nconst mjnode = require('mathjax-node-svg2png');\nmjpage.init(mjnode);\n```\n\nIf your custom mathjax-node provides new output options, you can add them by calling `addOutput`. As a second parameter, you can pass custom output handler, which is a function that modifies a DOM element with the conversion result.  The default output handler behavior is to write contents to `wrapper.innerHTML`.\n```javascript\nmjpage.addOutput('png', (wrapper, data) => {\n\twrapper.innerHTML = `<img src=\"${data}\">`;\n});\n// ...now you can use standard mathjax-node-page API\n```\n\nReset to default mathjax-node behavior by calling `init` with empty parameters. Ensure that all your current mathjax-node-page tasks have been completed before calling it.\n```javascript\nmjpage.init();  // reset back to default mathjax-node\n```\n\n### Events\n`mjpage` runs jobs which inherit `EventEmitter` and provide the following event hooks.\nAdd the corresponding event handlers to manipulate the input/output and DOM before/after conversion.\n\nAll the event handlers are destroyed when job ends to prevent memory leaks.\n\n#### Formula conversion events\n* `beforeConversion` -> `handler(parsedFormula)`: runs before individual formula conversion started, but after initial DOM processing. All the formulas are wrapped in `<script type=\"...\">` tags, where `@type` is one of the following:\n```javascript\nconst scripts = document.querySelectorAll(`\n    script[type=\"math/TeX\"],\n    script[type=\"math/inline-TeX\"],\n    script[type=\"math/AsciiMath\"],\n    script[type=\"math/MathML\"],\n    script[type=\"math/MathML-block\"]`\n);\n```\n* `afterConersion` -> `handler(parsedFormula)`: runs after individual formula conversion completed and DOM was changed. Formula DOM node is a `<span class=\"mjpage...\">` wrapper whose contents are the conversion result.\n\nAll formula conversion events pass `ParsedFormula` instance to the event handler.\n\n```javascript\n{\n    id, // index of formula on the page\n    jobID, // mjpage job ID; formulas belonging to the same page run have the same jobID\n    node, // DOM node with the formula (contents change before and after conversion)\n    sourceFormula, // the source formula\n    sourceFormat, // the source formula format (e.g. \"inline-TeX\")\n    outputFormula, // the converted formula result from mathjax-node typeset function; use outputFormula[outputFormat] to get the resulting formula string\n    outputFormat // the resulting formula format (e.g. \"svg\")\n}\n```\n\n#### Page conversion events\n* `beforeSerialiation` -> `handler(document, css`): runs when converted page DOM was prepared immediately before serialization. Use to manipulate resulting page DOM. The event handler receives `document` node (jsdom) and page `css`. Won't trigger if `input` is a `jsdom` object.\n\nIf `input` is a HTML string, `mjpage` function callback receives result after the DOM serialization.  \nIf `input` is a `jsdom` object, `mjpage` function callback receives `jsdom` object itself.\n\n#### Error handling\nWhen a rendering error occurs, `config.errorHandler` will be called. These arguments are passed:\n\n* `id`: index of formula on the page.\n* `wrapperNode`: The jsdom HTMLElement object where the rendered math should be put.\n* `sourceFormula`: The input math code.\n* `sourceFormat`: The format of input math code -- e.g. `inline-TeX` or `TeX`.\n* `errors`: A array of strings of MathJax-Node returned errors.\n\nModify the `wrapperNode` object to show some error message to user. The default error handling function is printing the error with `console.log`.\n\n#### Example\n```javascript\nmjpage(input, {\n    format: [\"TeX\"]\n}, {\n    svg: true\n}, function(output) {\n    // output is your final result\n})\n.on('afterConversion', function(parsedFormula) {\n    // manipulate parsed result and DOM at your will\n    // see description of parsedFormula object above\n});\n```\n\n\n\n## CLI\n\nmathjax-node-page installs a CLI tool. Run `mjpage` to print usage instructions.\n\n### Example\n\n```javascript\nconst mjpage = require('../lib/main.js').mjpage;\nconst fs = require('fs');\nconst input = fs.readFileSync('input.html');\n\nmjpage(input, {format: [\"TeX\"]}, {svg: true}, function(output) {\n    console.log(output); // resulting HTML string\n});\n```\n","readmeFilename":"README.md"}