Browse Source

KaTeX server is now in separate repo.

master
Jan Černohorský 3 months ago
parent
commit
6180b581b8
  1. 3
      .gitmodules
  2. 0
      src/formatitko/katex-server/index.mjs
  3. 7
      src/formatitko/katex-server/package-lock.json
  4. 5
      src/formatitko/katex-server/package.json
  5. 15
      src/formatitko/katex-server/yarn.lock
  6. 28
      src/formatitko/katex.py

3
.gitmodules

@ -1,3 +1,6 @@
[submodule "ucwmac"]
path = ucwmac
url = git://git.ucw.cz/ucwmac.git
[submodule "src/formatitko/katex-server"]
path = src/formatitko/katex-server
url = https://gitea.ks.matfyz.cz/KSP/formatitko-katex-server.git

0
src/formatitko/katex-server/index.mjs

7
src/formatitko/katex-server/package-lock.json

@ -1,15 +1,18 @@
{
"name": "ksp-katex-server",
"name": "formatitko-katex-server",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ksp-katex-server",
"name": "formatitko-katex-server",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"katex": "^0.16.3"
},
"bin": {
"formatitko-katex-server": "index.mjs"
}
},
"node_modules/commander": {

5
src/formatitko/katex-server/package.json

@ -1,8 +1,11 @@
{
"name": "ksp-katex-server",
"name": "formatitko-katex-server",
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"bin": {
"formatitko-katex-server":"index.mjs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},

15
src/formatitko/katex-server/yarn.lock

@ -0,0 +1,15 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
commander@^8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
katex@^0.16.3:
version "0.16.9"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.16.9.tgz#bc62d8f7abfea6e181250f85a56e4ef292dcb1fa"
integrity sha512-fsSYjWS0EEOwvy81j3vRA8TEAhQhKiqO+FQaKWp0m39qwOzHVBgAUBIXWj1pB+O2W3fIpNa6Y9KSKCVbfPhyAQ==
dependencies:
commander "^8.3.0"

28
src/formatitko/katex.py

@ -3,6 +3,7 @@ import subprocess
import tempfile
import json
import os
import shutil
class KatexError(Exception):
pass
@ -20,8 +21,10 @@ class KatexClient:
_socket_file: str
_temp_dir: tempfile.TemporaryDirectory[str]
_connected: bool
_katex_server_path: str
def __init__(self, socket: str=None, connect: bool=True):
def __init__(self, socket: str=None, connect: bool=True, katex_server_path: str=None):
self._katex_server_path = katex_server_path
if socket is not None:
self._socket_file = socket
else:
@ -38,20 +41,21 @@ class KatexClient:
self._temp_dir = tempfile.TemporaryDirectory(prefix='formatitko')
self._socket_file = self._temp_dir.name + "/katex-socket"
srcdir = os.path.dirname(os.path.realpath(__file__))
if self._katex_server_path is None:
srcdir = os.path.dirname(os.path.realpath(__file__))
# Test if `node_modules` directory exists and if not, run `npm install`
if not os.path.isdir(srcdir + "/katex-server/node_modules"):
print("Installing node dependencies for the first time...")
try:
subprocess.run(["npm", "install"], cwd=srcdir+"/katex-server", check=True)
except subprocess.CalledProcessError as e:
if e.returncode == 127:
# Test if `node_modules` directory exists and if not, run `npm install`
if not os.path.isdir(srcdir + "/katex-server/node_modules"):
print("Installing node dependencies for the first time...")
npm = shutil.which("npm") or shutil.which("yarnpkg")
if npm is None:
raise NPMNotFoundError("npm not found. Node.js is required to use KaTeX.")
else:
raise e
subprocess.run([npm, "install"], cwd=srcdir+"/katex-server", check=True)
self._katex_server_path = srcdir + "/katex-server/index.mjs"
self._server_process = subprocess.Popen(["node", srcdir + "/katex-server/index.mjs", self._socket_file], stdout=subprocess.PIPE)
self._server_process = subprocess.Popen(["node", self._katex_server_path, self._socket_file], stdout=subprocess.PIPE)
ok = self._server_process.stdout.readline()
if ok != b"OK\n":

Loading…
Cancel
Save