From ea7a07c1803b84529301b1eb568a3066dfdefc9f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 23 Sep 2018 21:18:29 +0200 Subject: Add KaTeX derivation --- default.nix | 2 ++ pkgs/KaTeX/default.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pkgs/KaTeX/default.nix diff --git a/default.nix b/default.nix index a04c69d..ffc0ddd 100644 --- a/default.nix +++ b/default.nix @@ -11,6 +11,8 @@ let oomox-gtk-theme = callPackage ./pkgs/oomox-gtk-theme { }; oomox-archdroid-icon-theme = callPackage ./pkgs/oomox-archdroid-icon-theme { }; + KaTeX = callPackage ./pkgs/KaTeX { }; + InputXSLT = callPackage ./pkgs/xslt/InputXSLT { }; StaticXSLT = callPackage ./pkgs/xslt/StaticXSLT { }; BuildXSLT = callPackage ./pkgs/xslt/BuildXSLT { }; diff --git a/pkgs/KaTeX/default.nix b/pkgs/KaTeX/default.nix new file mode 100644 index 0000000..37fe63a --- /dev/null +++ b/pkgs/KaTeX/default.nix @@ -0,0 +1,49 @@ +{ stdenv, pkgs, ... }: + +let + katex-src = stdenv.mkDerivation rec { + name = "katex-src"; + + src = pkgs.fetchzip { + url = "https://github.com/Khan/KaTeX/releases/download/v0.10.0-alpha/katex.zip"; + sha256 = "002dzyf3wcyjxv4m6vv0v99gf82a9k7rxsnlvf93h9fhcda2vj7l"; + }; + + buildInputs = [ pkgs.nodejs ]; + + installPhase = '' + mkdir -p $out/share/katex + cp katex.min.js $out/share/katex/ + ''; + + meta = { + description = "KaTeX"; + homepage = https://github.com/Khan/KaTeX; + license = stdenv.lib.licenses.mit; + platforms = stdenv.lib.platforms.all; + }; + }; +in pkgs.writeTextFile { + name = "katex-wrapper"; + executable = true; + destination = "/bin/katex"; + + text = '' + #!${pkgs.nodejs}/bin/node + + var katex = require("${katex-src}/share/katex/katex.min.js"); + var input = ""; + + var args = process.argv.slice(2); + + process.stdin.on("data", function(chunk) { + input += chunk.toString(); + }); + + process.stdin.on("end", function() { + var options = { displayMode: args.indexOf("--display-mode") !== -1 }; + var output = katex.renderToString(input, options); + console.log(output); + }); + ''; +} -- cgit v1.2.3