From de0fce7fde193271dbde5afa5b6cb555d7766e5d Mon Sep 17 00:00:00 2001 From: "Ashwin V. Mohanan" Date: Sun, 19 May 2024 21:53:35 +0200 Subject: [PATCH] Transform to ES6 module style imports, import mathjax plugin --- default.nix | 5 +- index.html | 2 +- package.json | 16 ++--- src/cli.js | 164 ++++++++++++++++++++++++++++++++----------------- src/version.js | 2 +- 5 files changed, 119 insertions(+), 70 deletions(-) diff --git a/default.nix b/default.nix index f9bb40b..8f690a4 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,6 @@ +# nixos-23.11 { - pkgs ? import {} + pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/bacb8503d3a51d9e9b52e52a1ba45e2c380ad07d.tar.gz") {} }: pkgs.mkShell { @@ -12,7 +13,7 @@ pkgs.mkShell { ]; # libs buildInputs = with pkgs; [ - nodejs-slim-12_x + pkgs.nodejs-slim_18 ]; shellHook = '' npm install . diff --git a/index.html b/index.html index 63c0fa0..d19da8d 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + ` } -const mjNodeConfig = { - html: true, - // mml: true, - // svg: true, - equationNumbers: "AMS", - speakText: false -}; +// if (argv.mathjax) { +// // const { createMathjaxInstance, mathjax } = require("@mdit/plugin-mathjax"); +// var mjLoaded = import("@mdit/plugin-mathjax").then( +// (module) => { +// // var { createMathjaxInstance, mathjax } = module; +// const mathjaxInstance = module.createMathjaxInstance(mjConfig); +// md.use(module.mathjax, mathjaxInstance); +// mjStyle = mathjaxInstance.outputStyle(); +// }, +// () => { +// console.error("Could not import @mdit/plugin-mathjax") +// } +// ) +// } function mathJaxRenderEmit(newHtml) { - if(argv.mathjax) { - mjpage( - newHtml, - mjPageConfig, - mjNodeConfig, - function(data) { - if (argv.debug) { - console.log("Rendered html saved as debug.html") - // console.debug(data); // resulting HTML string - fs.writeFileSync('debug.html', data, 'utf-8'); // debug - } - io.emit('newContent', data); - } - ); - } - else { + // if(argv.mathjax) { + // mjpage( + // newHtml, + // mjPageConfig, + // mjNodeConfig, + // function(data) { + // if (argv.debug) { + // console.log("Rendered html saved as debug.html") + // // console.debug(data); // resulting HTML string + // fs.writeFileSync('debug.html', data, 'utf-8'); // debug + // } + // io.emit('newContent', data); + // } + // ); + // } + // else { + // } + + // mjLoaded.then(() => io.emit('newContent', newHtml) - } + // ); + // console.log(mjLoaded) if (argv.debug) { console.debug('Emitting new data'); // console.debug(newHtml); // resulting HTML string @@ -194,6 +237,10 @@ function addSecurityHeaders(req, res, isIndexFile) { if (argv.debug) console.debug(`Content-Security-Policy=${csp}`) } +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; + + function httpHandler(req, res) { if (argv.debug) console.debug("Received %s request", req.method); @@ -204,6 +251,7 @@ function httpHandler(req, res) { // Example: /my-repo/raw/master/sub-dir/some.png let githubUrl = req.url.match(/\/[^\/]+\/raw\/[^\/]+\/(.+)/); let isIndexFile = /^\/(index\.html)?(\?|$)/.test(req.url); + const __dirname = dirname(fileURLToPath(import.meta.url)); let pkgRoot = path.dirname(__dirname); let cwd = process.cwd(); diff --git a/src/version.js b/src/version.js index 3984662..2607b7c 100644 --- a/src/version.js +++ b/src/version.js @@ -1,2 +1,2 @@ // Generated by genversion. -module.exports = '0.3.0' +module.exports = '0.4.0.dev0'