Vyřešeno pár errorů od pyrightu, odstraněny hvězdičkové importy (#16), zbyly jen v html.py a tex.py, které se stejně budou celé předělávat.

This commit is contained in:
Jan Černohorský 2023-07-18 19:33:23 +02:00
parent af3138c049
commit 4375e3fc8f
10 changed files with 25 additions and 29 deletions

View file

@ -28,8 +28,9 @@ 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,10 +1,9 @@
from panflute import Div,Span,Para
from panflute import Div, Span, Para, Element
from typing import List
# Import local files
from .util import *
from .util import nullify, import_md
from .context import Context
from .mj_show import show
class Command:
pass

View file

@ -1,6 +1,5 @@
from panflute import Doc, Div
from typing import Dict
import os
@ -71,15 +70,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
key = key.split(".")
for k in key[:-1]:
keys = key.split(".")
for k in keys[:-1]:
meta = meta[k]
meta[key[-1]] = value
meta[keys[-1]] = value
def unset_metadata(self, key: str):
meta = self.doc.metadata
key = key.split(".")
for k in key[:-1]:
keys = key.split(".")
for k in keys[:-1]:
meta = meta[k]
del meta.content[key[-1]] # A hack because MetaMap doesn't have a __delitem__

View file

@ -1,14 +1,10 @@
#!/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 *
from .util import import_md
from .context import Context, Group
from .katex import KatexClient
from .html import html

View file

@ -4,6 +4,7 @@ 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
@ -12,7 +13,7 @@ from .util import inlinify
from .context import Group
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
# output or html output
@ -40,7 +41,7 @@ def html(e: Element, k: KatexClient, i: ImageProcessor, indent_level: int=0, ind
Emph: "em",
Caption: "figcaption",
Para: "p",
Header: "h"+str(e.level) if hasattr(e, "level") else "",
Header: "h"+str(e.level) if isinstance(e, Header) else "",
LineBlock: "p",
ListItem: "li",
SmallCaps: "span",

View file

@ -1,4 +1,4 @@
from typing import List
from typing import List, Union
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]=[]) -> str:
def find_image(self, input_filename: str, additional_dirs: List[str]=[]) -> Union[str, None]:
for dir in [*self.lookup_dirs, *additional_dirs]:
if os.path.isfile(dir + "/" + input_filename):
return dir + "/" + input_filename

View file

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

View file

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

View file

@ -1,5 +1,6 @@
from panflute import *
import os
from typing import Union
from .whitespace import NBSP
from .transform import FQuoted
@ -8,7 +9,7 @@ from .context import Group
from .images import ImageProcessor
# 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
# 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()
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:
tag = tags[type(e)]

View file

@ -1,11 +1,11 @@
from panflute import *
from panflute import Element, Div, Span, Quoted, Image, CodeBlock, Str, MetaInlines, MetaStr, MetaBool
import re
# Import local files
from .whitespace import *
from .command import *
from .util import *
from .context import *
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
# This is a small extension to the Quoted panflute elements which allows to