diff --git a/src/formatitko/context.py b/src/formatitko/context.py index 8abc209..b12dc4e 100644 --- a/src/formatitko/context.py +++ b/src/formatitko/context.py @@ -21,6 +21,14 @@ CommandCallable = Callable[[Command, 'Context'], list[Element]] # This is here b # This class is basically an extension to panflute's doc, this is why metadata # is read directly from it. class Context: + parent: Union["Context", None] + _commands: dict[str, Union[CommandCallable, None]] + doc: Doc + trusted: bool + path: str + dir: str + filename: str + def __init__(self, doc: Doc, path: str, parent: Union['Context', None]=None, trusted: bool=True): self.parent = parent self._commands = {} @@ -100,6 +108,8 @@ class Context: # # Whenever a new context is created, its content should be eclosed in a group and vice-versa. class Group(Element): + metadata: dict + context: Context def __init__(self, *args, context:Context, metadata={}, **kwargs): self.metadata = metadata # This is only here for backwards compatibility with old html.py, tex.py and transform.py. FIXME: Remove this when the time comes. self.context = context diff --git a/src/formatitko/elements.py b/src/formatitko/elements.py index 9915f15..f39543d 100644 --- a/src/formatitko/elements.py +++ b/src/formatitko/elements.py @@ -8,6 +8,7 @@ from .whitespace import Whitespace, NBSP # This is a small extension to the Quoted panflute elements which allows to # have language-aware quotation marks. class FQuoted(Quoted): + style: str def __init__(self, *args, **kwargs): self.style = kwargs["style"] del kwargs["style"] diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index a579d3f..0659758 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -21,6 +21,9 @@ from .images import ImageProcessor from .util import inlinify class HTMLGenerator(OutputGenerator): + imageProcessor: ImageProcessor + katexClient: KatexClient + def __init__(self, output_file, katexClient: KatexClient, imageProcessor: ImageProcessor, *args, **kwargs): self.katexClient = katexClient self.imageProcessor = imageProcessor diff --git a/src/formatitko/images.py b/src/formatitko/images.py index 3f31b00..09eb748 100644 --- a/src/formatitko/images.py +++ b/src/formatitko/images.py @@ -22,6 +22,11 @@ class AsyError(ConversionProgramError): class ImageProcessor: + public_dir: str + cache_dir: str + lookup_dirs: list[str] + web_path: str + def __init__(self, public_dir: str, web_path: str, cache_dir: str, *lookup_dirs: list[str]): self.public_dir = public_dir self.cache_dir = cache_dir diff --git a/src/formatitko/katex.py b/src/formatitko/katex.py index 5ee78a7..b0a3570 100644 --- a/src/formatitko/katex.py +++ b/src/formatitko/katex.py @@ -15,6 +15,11 @@ class KatexServerError(Exception): class KatexClient: + _client: socket.socket + _server_process: subprocess.Popen[bytes] + _socket_file: str + _temp_dir: tempfile.TemporaryDirectory[str] + def __init__(self): # Create temporary directory for socket self._temp_dir = tempfile.TemporaryDirectory(prefix='formatitko') diff --git a/src/formatitko/latex_generator.py b/src/formatitko/latex_generator.py index aff1698..124cf11 100644 --- a/src/formatitko/latex_generator.py +++ b/src/formatitko/latex_generator.py @@ -11,6 +11,8 @@ from .output_generator import OutputGenerator from .images import ImageProcessor class LaTeXGenerator(OutputGenerator): + imageProcessor: ImageProcessor + def __init__(self, output_file, imageProcessor: ImageProcessor, *args, **kwargs): self.imageProcessor = imageProcessor super().__init__(output_file, *args, **kwargs) diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index 0fc973c..c795dba 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -2,11 +2,11 @@ from panflute import Element, ListContainer, Inline, Block from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, Quoted, RawInline, SmallCaps, SoftBreak, Space, Span, Str, Strikeout, Strong, Subscript, Superscript, Underline from panflute import BlockQuote, BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Div, Figure, Header, HorizontalRule, LineBlock, LineItem, ListItem, MetaBlocks, MetaBool, MetaInlines, MetaList, MetaMap, MetaString, Null, OrderedList, Para, Plain, RawBlock, Table, TableBody, TableFoot, TableHead from panflute import TableRow, TableCell, Caption, Doc -from typing import Union +from typing import Union, Callable from .whitespace import NBSP from .elements import FQuoted -from .context import Group, InlineGroup, BlockGroup +from .context import Group, InlineGroup, BlockGroup, Context import re @@ -15,6 +15,15 @@ class UnknownElementError(Exception): pass class OutputGenerator: + _at_start_of_line: bool + context: Union[Context, None] + indent_level: int + indent_str: str + output_file: ... + TYPE_DICT_BLOCK: dict[type, Callable] + TYPE_DICT_INLINE: dict[type, Callable] + TYPE_DICT_MISC: dict[type, Callable] + def __init__(self, output_file, indent_str: str="\t", initial_indent_level: int=0): self.output_file = output_file self.indent_str = indent_str diff --git a/src/formatitko/transform_processor.py b/src/formatitko/transform_processor.py index 1e31521..a6eb4b0 100644 --- a/src/formatitko/transform_processor.py +++ b/src/formatitko/transform_processor.py @@ -31,11 +31,14 @@ class DoubleDocError(Exception): class TransformProcessor: + context: Union[Context, None] = None + root_file_path: str + root_highlight_style: str = "default" + _command_modules: list[tuple[Union[dict[str, CommandCallable], ModuleType], str]] = [] + TYPE_DICT: dict[type, Callable] + def __init__(self, root_file_path: str): - self.context: Context = None self.root_file_path = root_file_path - self.root_highlight_style = "default" - self._command_modules = [] self.TYPE_DICT = { TableRow: self.transform_TableRow,