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