Deklarovány atributy u tříd.
This commit is contained in:
parent
edbd985043
commit
123df37ce8
8 changed files with 43 additions and 5 deletions
|
@ -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
|
# This class is basically an extension to panflute's doc, this is why metadata
|
||||||
# is read directly from it.
|
# is read directly from it.
|
||||||
class Context:
|
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):
|
def __init__(self, doc: Doc, path: str, parent: Union['Context', None]=None, trusted: bool=True):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self._commands = {}
|
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.
|
# Whenever a new context is created, its content should be eclosed in a group and vice-versa.
|
||||||
class Group(Element):
|
class Group(Element):
|
||||||
|
metadata: dict
|
||||||
|
context: Context
|
||||||
def __init__(self, *args, context:Context, metadata={}, **kwargs):
|
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.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
|
self.context = context
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .whitespace import Whitespace, NBSP
|
||||||
# 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
|
||||||
# have language-aware quotation marks.
|
# have language-aware quotation marks.
|
||||||
class FQuoted(Quoted):
|
class FQuoted(Quoted):
|
||||||
|
style: str
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.style = kwargs["style"]
|
self.style = kwargs["style"]
|
||||||
del kwargs["style"]
|
del kwargs["style"]
|
||||||
|
|
|
@ -21,6 +21,9 @@ from .images import ImageProcessor
|
||||||
from .util import inlinify
|
from .util import inlinify
|
||||||
|
|
||||||
class HTMLGenerator(OutputGenerator):
|
class HTMLGenerator(OutputGenerator):
|
||||||
|
imageProcessor: ImageProcessor
|
||||||
|
katexClient: KatexClient
|
||||||
|
|
||||||
def __init__(self, output_file, katexClient: KatexClient, imageProcessor: ImageProcessor, *args, **kwargs):
|
def __init__(self, output_file, katexClient: KatexClient, imageProcessor: ImageProcessor, *args, **kwargs):
|
||||||
self.katexClient = katexClient
|
self.katexClient = katexClient
|
||||||
self.imageProcessor = imageProcessor
|
self.imageProcessor = imageProcessor
|
||||||
|
|
|
@ -22,6 +22,11 @@ class AsyError(ConversionProgramError):
|
||||||
|
|
||||||
|
|
||||||
class ImageProcessor:
|
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]):
|
def __init__(self, public_dir: str, web_path: str, cache_dir: str, *lookup_dirs: list[str]):
|
||||||
self.public_dir = public_dir
|
self.public_dir = public_dir
|
||||||
self.cache_dir = cache_dir
|
self.cache_dir = cache_dir
|
||||||
|
|
|
@ -15,6 +15,11 @@ class KatexServerError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class KatexClient:
|
class KatexClient:
|
||||||
|
_client: socket.socket
|
||||||
|
_server_process: subprocess.Popen[bytes]
|
||||||
|
_socket_file: str
|
||||||
|
_temp_dir: tempfile.TemporaryDirectory[str]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Create temporary directory for socket
|
# Create temporary directory for socket
|
||||||
self._temp_dir = tempfile.TemporaryDirectory(prefix='formatitko')
|
self._temp_dir = tempfile.TemporaryDirectory(prefix='formatitko')
|
||||||
|
|
|
@ -11,6 +11,8 @@ from .output_generator import OutputGenerator
|
||||||
from .images import ImageProcessor
|
from .images import ImageProcessor
|
||||||
|
|
||||||
class LaTeXGenerator(OutputGenerator):
|
class LaTeXGenerator(OutputGenerator):
|
||||||
|
imageProcessor: ImageProcessor
|
||||||
|
|
||||||
def __init__(self, output_file, imageProcessor: ImageProcessor, *args, **kwargs):
|
def __init__(self, output_file, imageProcessor: ImageProcessor, *args, **kwargs):
|
||||||
self.imageProcessor = imageProcessor
|
self.imageProcessor = imageProcessor
|
||||||
super().__init__(output_file, *args, **kwargs)
|
super().__init__(output_file, *args, **kwargs)
|
||||||
|
|
|
@ -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 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 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 panflute import TableRow, TableCell, Caption, Doc
|
||||||
from typing import Union
|
from typing import Union, Callable
|
||||||
|
|
||||||
from .whitespace import NBSP
|
from .whitespace import NBSP
|
||||||
from .elements import FQuoted
|
from .elements import FQuoted
|
||||||
from .context import Group, InlineGroup, BlockGroup
|
from .context import Group, InlineGroup, BlockGroup, Context
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -15,6 +15,15 @@ class UnknownElementError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class OutputGenerator:
|
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):
|
def __init__(self, output_file, indent_str: str="\t", initial_indent_level: int=0):
|
||||||
self.output_file = output_file
|
self.output_file = output_file
|
||||||
self.indent_str = indent_str
|
self.indent_str = indent_str
|
||||||
|
|
|
@ -31,11 +31,14 @@ class DoubleDocError(Exception):
|
||||||
|
|
||||||
class TransformProcessor:
|
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):
|
def __init__(self, root_file_path: str):
|
||||||
self.context: Context = None
|
|
||||||
self.root_file_path = root_file_path
|
self.root_file_path = root_file_path
|
||||||
self.root_highlight_style = "default"
|
|
||||||
self._command_modules = []
|
|
||||||
|
|
||||||
self.TYPE_DICT = {
|
self.TYPE_DICT = {
|
||||||
TableRow: self.transform_TableRow,
|
TableRow: self.transform_TableRow,
|
||||||
|
|
Loading…
Reference in a new issue