|
@ -46,20 +46,20 @@ class KatexClient: |
|
|
srcdir = os.path.dirname(os.path.realpath(__file__)) |
|
|
srcdir = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
|
|
|
# Test if `node_modules` directory exists and if not, run `npm install` |
|
|
# Test if `node_modules` directory exists and if not, run `npm install` |
|
|
if not os.path.isdir(srcdir + "/katex-server/node_modules"): |
|
|
if not os.path.isdir(srcdir + "/katex_server/node_modules"): |
|
|
print("Installing node dependencies for the first time...") |
|
|
print("Installing node dependencies for the first time...") |
|
|
npm = shutil.which("npm") or shutil.which("yarnpkg") |
|
|
npm = shutil.which("npm") or shutil.which("yarnpkg") |
|
|
if npm is None: |
|
|
if npm is None: |
|
|
raise NPMNotFoundError("npm not found. Node.js is required to use KaTeX.") |
|
|
raise NPMNotFoundError("npm not found. Node.js is required to use KaTeX.") |
|
|
subprocess.run([npm, "install"], cwd=srcdir+"/katex-server", check=True) |
|
|
subprocess.run([npm, "install"], cwd=srcdir+"/katex_server", check=True) |
|
|
|
|
|
|
|
|
self._katex_server_path = srcdir + "/katex-server/index.mjs" |
|
|
self._katex_server_path = srcdir + "/katex_server/index.mjs" |
|
|
|
|
|
|
|
|
self._server_process = subprocess.Popen(["node", self._katex_server_path, 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() |
|
|
ok = self._server_process.stdout.readline() |
|
|
if ok != b"OK\n": |
|
|
if ok != b"OK\n": |
|
|
raise KatexServerError("Failed to connect to katex-server") |
|
|
raise KatexServerError("Failed to connect to katex_server") |
|
|
|
|
|
|
|
|
def connect(self): |
|
|
def connect(self): |
|
|
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|