|
|
@ -7,16 +7,20 @@ 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 |
|
|
|
from .whitespace import Whitespace |
|
|
|
from .command import BlockCommand, InlineCommand, CodeCommand, Command |
|
|
|
from .output_generator import FormatitkoRecursiveError |
|
|
|
|
|
|
|
ELCl = Union[Element, ListContainer, list[Union[Element, ListContainer]]] |
|
|
|
|
|
|
|
class DoubleDocError(Exception): |
|
|
|
"TransformProcessor should only ever see a single Doc." |
|
|
|
pass |
|
|
|
|
|
|
|
class NOPProcessor: |
|
|
|
TYPE_DICT: dict[type, Callable] |
|
|
|
context: Union[Context, None] = None |
|
|
|
|
|
|
|
class UnknownElementError(Exception): |
|
|
|
f"An unknown Element has been passed to the NOPProcessor, probably because panflute introduced a new one." |
|
|
@ -120,7 +124,7 @@ class NOPProcessor: |
|
|
|
err.add_element(e) |
|
|
|
raise err |
|
|
|
except Exception as err: |
|
|
|
raise FormatitkoRecursiveError(e) from err |
|
|
|
raise FormatitkoRecursiveError(e, self.context.filename) from err |
|
|
|
|
|
|
|
def transform_list(self, e: list[Union[Element, ListContainer]]) -> list[Union[Element, ListContainer]]: |
|
|
|
for i in range(len(e)): |
|
|
@ -301,6 +305,9 @@ class NOPProcessor: |
|
|
|
return e |
|
|
|
|
|
|
|
def transform_Doc(self, e: Doc) -> Doc: |
|
|
|
if self.context is not None: |
|
|
|
raise DoubleDocError() |
|
|
|
self.context = Context(e, self.root_file_path) |
|
|
|
e.content = self.transform(e.content) |
|
|
|
return e |
|
|
|
|
|
|
|