Compare commits
3 commits
410c2852b2
...
48e6f53a4f
Author | SHA1 | Date | |
---|---|---|---|
48e6f53a4f | |||
4375e3fc8f | |||
af3138c049 |
12 changed files with 56 additions and 35 deletions
7
.editorconfig
Normal file
7
.editorconfig
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = tab
|
|
@ -28,8 +28,9 @@ formatitko = "formatitko.formatitko:main"
|
||||||
|
|
||||||
[tool.setuptools_scm]
|
[tool.setuptools_scm]
|
||||||
|
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
where = ["src"]
|
where = ["src"]
|
||||||
exclude = ["src/formatitko/katex-server/node_modules"]
|
exclude = ["src/formatitko/katex-server/node_modules"]
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
strictParameterNoneValue = false
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
from panflute import Div,Span,Para
|
from panflute import Div, Span, Para, Element
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# Import local files
|
# Import local files
|
||||||
from .util import *
|
from .util import nullify, import_md
|
||||||
from .context import Context
|
from .context import Context
|
||||||
from .mj_show import show
|
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
from panflute import Doc, Div
|
from panflute import Doc, Div
|
||||||
from typing import Dict
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,15 +70,15 @@ class Context:
|
||||||
if key == "language":
|
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.")
|
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
|
meta = self.doc.metadata
|
||||||
key = key.split(".")
|
keys = key.split(".")
|
||||||
for k in key[:-1]:
|
for k in keys[:-1]:
|
||||||
meta = meta[k]
|
meta = meta[k]
|
||||||
meta[key[-1]] = value
|
meta[keys[-1]] = value
|
||||||
|
|
||||||
def unset_metadata(self, key: str):
|
def unset_metadata(self, key: str):
|
||||||
meta = self.doc.metadata
|
meta = self.doc.metadata
|
||||||
key = key.split(".")
|
keys = key.split(".")
|
||||||
for k in key[:-1]:
|
for k in keys[:-1]:
|
||||||
meta = meta[k]
|
meta = meta[k]
|
||||||
del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__
|
del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from typing import List
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Import local files
|
# Import local files
|
||||||
from .transform import transform
|
from .transform import transform
|
||||||
from .util import *
|
from .util import import_md
|
||||||
from .context import Context, Group
|
from .context import Context, Group
|
||||||
from .katex import KatexClient
|
from .katex import KatexClient
|
||||||
from .html import html
|
from .html import html
|
||||||
|
|
|
@ -4,6 +4,7 @@ from pygments.lexers import get_lexer_by_name
|
||||||
from pygments.formatters import HtmlFormatter
|
from pygments.formatters import HtmlFormatter
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
import os
|
import os
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from .whitespace import NBSP
|
from .whitespace import NBSP
|
||||||
from .transform import FQuoted
|
from .transform import FQuoted
|
||||||
|
@ -12,7 +13,7 @@ from .util import inlinify
|
||||||
from .context import Group
|
from .context import Group
|
||||||
from .images import ImageProcessor
|
from .images import ImageProcessor
|
||||||
|
|
||||||
def html(e: Element, k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
|
def html(e: Union[Element, ListContainer], k: KatexClient, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
|
||||||
|
|
||||||
# `only` attribute which makes transformed elements appear only in tex
|
# `only` attribute which makes transformed elements appear only in tex
|
||||||
# output or html output
|
# output or html output
|
||||||
|
@ -40,7 +41,7 @@ def html(e: Element, k: KatexClient, i: ImageProcessor, indent_level: int=0, ind
|
||||||
Emph: "em",
|
Emph: "em",
|
||||||
Caption: "figcaption",
|
Caption: "figcaption",
|
||||||
Para: "p",
|
Para: "p",
|
||||||
Header: "h"+str(e.level) if hasattr(e, "level") else "",
|
Header: "h"+str(e.level) if isinstance(e, Header) else "",
|
||||||
LineBlock: "p",
|
LineBlock: "p",
|
||||||
ListItem: "li",
|
ListItem: "li",
|
||||||
SmallCaps: "span",
|
SmallCaps: "span",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -74,7 +74,7 @@ class ImageProcessor:
|
||||||
return Image.open(full_path).size
|
return Image.open(full_path).size
|
||||||
|
|
||||||
|
|
||||||
def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> str:
|
def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> Union[str, None]:
|
||||||
for dir in [*self.lookup_dirs, *additional_dirs]:
|
for dir in [*self.lookup_dirs, *additional_dirs]:
|
||||||
if os.path.isfile(dir + "/" + input_filename):
|
if os.path.isfile(dir + "/" + input_filename):
|
||||||
return dir + "/" + input_filename
|
return dir + "/" + input_filename
|
||||||
|
|
30
src/formatitko/katex-server/package-lock.json
generated
30
src/formatitko/katex-server/package-lock.json
generated
|
@ -1,20 +1,38 @@
|
||||||
{
|
{
|
||||||
"name": "ksp-katex-server",
|
"name": "ksp-katex-server",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"packages": {
|
||||||
"commander": {
|
"": {
|
||||||
|
"name": "ksp-katex-server",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"katex": "^0.16.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/commander": {
|
||||||
"version": "8.3.0",
|
"version": "8.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
|
||||||
"integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww=="
|
"integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 12"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"katex": {
|
"node_modules/katex": {
|
||||||
"version": "0.16.3",
|
"version": "0.16.3",
|
||||||
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.3.tgz",
|
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.3.tgz",
|
||||||
"integrity": "sha512-3EykQddareoRmbtNiNEDgl3IGjryyrp2eg/25fHDEnlHymIDi33bptkMv6K4EOC2LZCybLW/ZkEo6Le+EM9pmA==",
|
"integrity": "sha512-3EykQddareoRmbtNiNEDgl3IGjryyrp2eg/25fHDEnlHymIDi33bptkMv6K4EOC2LZCybLW/ZkEo6Le+EM9pmA==",
|
||||||
"requires": {
|
"funding": [
|
||||||
|
"https://opencollective.com/katex",
|
||||||
|
"https://github.com/sponsors/katex"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
"commander": "^8.0.0"
|
"commander": "^8.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"katex": "cli.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import tempfile
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
class KatexError(Exception):
|
class KatexError(Exception):
|
||||||
|
@ -66,5 +65,5 @@ class KatexClient:
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, tb):
|
def __exit__(self):
|
||||||
self._server_process.terminate()
|
self._server_process.terminate()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
import sys, re
|
import sys, re
|
||||||
from panflute import *
|
from panflute import Str, Element, ListContainer, DictContainer
|
||||||
|
|
||||||
avoid_keys = {
|
avoid_keys = {
|
||||||
'dict',
|
'dict',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from panflute import *
|
from panflute import *
|
||||||
import os
|
import os
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from .whitespace import NBSP
|
from .whitespace import NBSP
|
||||||
from .transform import FQuoted
|
from .transform import FQuoted
|
||||||
|
@ -8,7 +9,7 @@ from .context import Group
|
||||||
from .images import ImageProcessor
|
from .images import ImageProcessor
|
||||||
|
|
||||||
# Heavily inspired by: git://git.ucw.cz/labsconf2022.git
|
# Heavily inspired by: git://git.ucw.cz/labsconf2022.git
|
||||||
def tex(e: Element, i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
|
def tex(e: Union[Element, ListContainer], i: ImageProcessor, indent_level: int=0, indent_str: str="\t") -> str:
|
||||||
|
|
||||||
# `only` attribute which makes transformed elements appear only in tex
|
# `only` attribute which makes transformed elements appear only in tex
|
||||||
# output or html output
|
# output or html output
|
||||||
|
@ -30,7 +31,7 @@ def tex(e: Element, i: ImageProcessor, indent_level: int=0, indent_str: str="\t"
|
||||||
tag = e.tag.lower()
|
tag = e.tag.lower()
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Header: "h"+chr(64 + e.level) if hasattr(e, "level") else "",
|
Header: "h"+chr(64 + e.level) if isinstance(e, Header) else "",
|
||||||
}
|
}
|
||||||
if type(e) in tags:
|
if type(e) in tags:
|
||||||
tag = tags[type(e)]
|
tag = tags[type(e)]
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from panflute import *
|
from panflute import Element, Div, Span, Quoted, Image, CodeBlock, Str, MetaInlines, MetaStr, MetaBool
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Import local files
|
# Import local files
|
||||||
from .whitespace import *
|
from .whitespace import Whitespace, NBSP, bavlna
|
||||||
from .command import *
|
from .command import Command, BlockCommand, InlineCommand, handle_command_define, executeCommand
|
||||||
from .util import *
|
from .util import nullify, import_md
|
||||||
from .context import *
|
from .context import Context, Group
|
||||||
|
|
||||||
|
|
||||||
# This is a small extension to the Quoted panflute elements which allows to
|
# This is a small extension to the Quoted panflute elements which allows to
|
||||||
|
|
Loading…
Reference in a new issue