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 ) :
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 ) :
def replaceSelf ( self , content : list [ Element ] ) - > Div :
return Div ( * content )
pass