Compare commits

..

No commits in common. "48e6f53a4fa308503b59aa37c33ff34c01b25b68" and "410c2852b2590f5999f7c8d7acd5a27c21f43865" have entirely different histories.

12 changed files with 35 additions and 56 deletions

View file

@ -1,7 +0,0 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = tab

View file

@ -28,9 +28,8 @@ formatitko = "formatitko.formatitko:main"
[tool.setuptools_scm]
[tool.setuptools.packages.find]
where = ["src"]
exclude = ["src/formatitko/katex-server/node_modules"]
[tool.pyright]
strictParameterNoneValue = false

View file

@ -1,9 +1,10 @@
from panflute import Div, Span, Para, Element
from panflute import Div,Span,Para
from typing import List
# Import local files
from .util import nullify, import_md
from .util import *
from .context import Context
from .mj_show import show
class Command:
pass

View file

@ -1,5 +1,6 @@
from panflute import Doc, Div
from typing import Dict
import os
@ -70,15 +71,15 @@ class Context:
if key == "language":
print("WARN: Setting language this way doesn't propagate to TeX. Either use the Front Matter or specify it additionally using the \\languagexx macro.")
meta = self.doc.metadata
keys = key.split(".")
for k in keys[:-1]:
key = key.split(".")
for k in key[:-1]:
meta = meta[k]
meta[keys[-1]] = value
meta[key[-1]] = value
def unset_metadata(self, key: str):
meta = self.doc.metadata
keys = key.split(".")
for k in keys[:-1]:
key = key.split(".")
for k in key[:-1]:
meta = meta[k]
del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__

View file

@ -1,10 +1,14 @@
#!/usr/bin/env python3
import argparse
import re
import sys
from typing import List
import os
# Import local files
from .transform import transform
from .util import import_md
from .util import *
from .context import Context, Group
from .katex import KatexClient
from .html import html

View file

@ -4,7 +4,6 @@ from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from pygments.util import ClassNotFound
import os
from typing import Union
from .whitespace import NBSP
from .transform import FQuoted
@ -13,7 +12,7 @@ from .util import inlinify
from .context import Group
from .images import ImageProcessor
def html(e: Union[Element, ListContainer], k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
def html(e: Element, k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
# `only` attribute which makes transformed elements appear only in tex
# output or html output
@ -41,7 +40,7 @@ def html(e: Union[Element, ListContainer], k: KatexClient, i: ImageProcessor, in
Emph: "em",
Caption: "figcaption",
Para: "p",
Header: "h"+str(e.level) if isinstance(e, Header) else "",
Header: "h"+str(e.level) if hasattr(e, "level") else "",
LineBlock: "p",
ListItem: "li",
SmallCaps: "span",

View file

@ -1,4 +1,4 @@
from typing import List, Union
from typing import List
import os
import shutil
import subprocess
@ -74,7 +74,7 @@ class ImageProcessor:
return Image.open(full_path).size
def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> Union[str, None]:
def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> str:
for dir in [*self.lookup_dirs, *additional_dirs]:
if os.path.isfile(dir + "/" + input_filename):
return dir + "/" + input_filename

View file

@ -1,38 +1,20 @@
{
"name": "ksp-katex-server",
"version": "1.0.0",
"lockfileVersion": 3,
"lockfileVersion": 1,
"requires": true,
"packages": {
"": {
"name": "ksp-katex-server",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"katex": "^0.16.3"
}
},
"node_modules/commander": {
"commander": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
"integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==",
"engines": {
"node": ">= 12"
}
"integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww=="
},
"node_modules/katex": {
"katex": {
"version": "0.16.3",
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.3.tgz",
"integrity": "sha512-3EykQddareoRmbtNiNEDgl3IGjryyrp2eg/25fHDEnlHymIDi33bptkMv6K4EOC2LZCybLW/ZkEo6Le+EM9pmA==",
"funding": [
"https://opencollective.com/katex",
"https://github.com/sponsors/katex"
],
"dependencies": {
"requires": {
"commander": "^8.0.0"
},
"bin": {
"katex": "cli.js"
}
}
}

View file

@ -4,6 +4,7 @@ import tempfile
import json
import os
from typing import Dict
import time
class KatexError(Exception):
@ -65,5 +66,5 @@ class KatexClient:
def __enter__(self):
return self
def __exit__(self):
def __exit__(self, type, value, tb):
self._server_process.terminate()

View file

@ -3,7 +3,7 @@
###
import sys, re
from panflute import Str, Element, ListContainer, DictContainer
from panflute import *
avoid_keys = {
'dict',

View file

@ -1,6 +1,5 @@
from panflute import *
import os
from typing import Union
from .whitespace import NBSP
from .transform import FQuoted
@ -9,7 +8,7 @@ from .context import Group
from .images import ImageProcessor
# Heavily inspired by: git://git.ucw.cz/labsconf2022.git
def tex(e: Union[Element, ListContainer], i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
def tex(e: Element, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
# `only` attribute which makes transformed elements appear only in tex
# output or html output
@ -31,7 +30,7 @@ def tex(e: Union[Element, ListContainer], i: ImageProcessor, indent_level: int=0
tag = e.tag.lower()
tags = {
Header: "h"+chr(64 + e.level) if isinstance(e, Header) else "",
Header: "h"+chr(64 + e.level) if hasattr(e, "level") else "",
}
if type(e) in tags:
tag = tags[type(e)]

View file

@ -1,11 +1,11 @@
from panflute import Element, Div, Span, Quoted, Image, CodeBlock, Str, MetaInlines, MetaStr, MetaBool
from panflute import *
import re
# Import local files
from .whitespace import Whitespace, NBSP, bavlna
from .command import Command, BlockCommand, InlineCommand, handle_command_define, executeCommand
from .util import nullify, import_md
from .context import Context, Group
from .whitespace import *
from .command import *
from .util import *
from .context import *
# This is a small extension to the Quoted panflute elements which allows to