You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
771 B

from panflute import Span, Div, Element, Plain, Para
from .util import inlinify
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):
11 months ago
def replaceSelf(self, content: list[Element]) -> Span:
try:
return Span(*content)
except TypeError:
if inlinify(content):
return Span(inlinify(content))
else:
raise InlineError(f"The command {self.attributes['c']} returned multiple Paragraphs and must be executed using `::: {{c={self.attributes['c']}}}\\n:::`.\n\n{content}")
pass
class BlockCommand(Div, Command):
11 months ago
def replaceSelf(self, content: list[Element]) -> Div:
return Div(*content)
pass