from panflute import Span, Div, Element, Plain, Para class InlineError(Exception): pass class Command: pass # This distinction is needed because while transforming the tree, inline # elements cannot be replaced with block ones class InlineCommand(Span, Command): def replaceSelf(self, *content: list[Element]) -> Span: try: return Span(*content) except TypeError: if len(content) == 1 and (isinstance(content[0], Para) or isinstance(content[0], Plain)): return Span(*content[0].content) else: return Div(*content) pass class BlockCommand(Div, Command): def replaceSelf(self, *content: list[Element]) -> Div: try: return Div(*content) except TypeError: return Div(Para(*content)) pass class CodeCommand(BlockCommand): test: str def __init__(self, *args, **kwargs): self.text = args[0] super().__init__(**kwargs)