@ -3,6 +3,7 @@ from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, Quote
from panflute import BlockQuote , BulletList , Citation , CodeBlock , Definition , DefinitionItem , DefinitionList , Div , Figure , Header , HorizontalRule , LineBlock , LineItem , ListItem , MetaBlocks , MetaBool , MetaInlines , MetaList , MetaMap , MetaString , Null , OrderedList , Para , Plain , RawBlock , Table , TableBody , TableFoot , TableHead
from panflute import TableRow , TableCell , Caption , Doc
from panflute import MetaValue
from panflute . containers import attach
from typing import Union , Callable
from types import ModuleType
@ -75,8 +76,8 @@ class TransformProcessor(NOPProcessor):
self . context = Context ( e , self . root_file_path )
for module , module_name in self . _command_modules :
self . context . add_commands_from_module ( module , module_name )
e . content = self . transform ( e . content )
e . content = [ BlockGroup ( * e . content , context = self . context ) ]
e . content = self . transform ( e . content )
return e
@ -136,8 +137,9 @@ class TransformProcessor(NOPProcessor):
# Commands can be called multiple ways, this handles the following syntax:
# :::{c=commandname}
# :::
e = BlockCommand ( * e . content , identifier = e . identifier , classes = e . classes , attributes = e . attributes )
return self . transform ( e )
command = BlockCommand ( * e . content , identifier = e . identifier , classes = e . classes , attributes = e . attributes )
attach ( command , e . parent , e . location , e . index )
return self . transform ( command )
if " partial " in e . attributes :
# `partial` attribute
@ -195,14 +197,16 @@ class TransformProcessor(NOPProcessor):
if " c " in e . attributes :
# Commands can be called multiple ways, this handles the following syntax:
# []{c=commandname} and
e = InlineCommand ( * e . content , identifier = e . identifier , classes = e . classes , attributes = e . attributes )
return self . transform ( e )
command = InlineCommand ( * e . content , identifier = e . identifier , classes = e . classes , attributes = e . attributes )
attach ( command , e . parent , e . location , e . index )
return self . transform ( command )
if len ( e . content ) == 1 and isinstance ( e . content [ 0 ] , Str ) :
## Handle special command shorthand [!commandname]{}
if re . match ( r " ^![ \ w.]+$ " , e . content [ 0 ] . text ) :
e = InlineCommand ( identifier = e . identifier , classes = e . classes , attributes = { * * e . attributes , " c " : e . content [ 0 ] . text [ 1 : ] } )
return self . transform ( e )
command = InlineCommand ( identifier = e . identifier , classes = e . classes , attributes = { * * e . attributes , " c " : e . content [ 0 ] . text [ 1 : ] } )
attach ( command , e . parent , e . location , e . index )
return self . transform ( command )
## Handle import [#ksp_formatitko as ksp]{}, [#ksp_formatitko]{type=module} or [#path/file.md]{type=md}
# Import a python module as commands (type=module, the default) or
@ -255,8 +259,9 @@ class TransformProcessor(NOPProcessor):
if not self . context . trusted :
return nullify ( e )
command_output = parse_command ( e . text ) ( BlockCommand ( ) , self . context , self )
e = BlockCommand ( ) . replaceSelf ( * ( [ ] if command_output is None else command_output ) )
return self . transform ( e )
command = BlockCommand ( ) . replaceSelf ( * ( [ ] if command_output is None else command_output ) )
attach ( command , e . parent , e . location , e . index )
return self . transform ( command )
if " python " in e . classes and ( " define " in e . attributes or " redefine " in e . attributes ) :
if not self . context . trusted :
@ -264,7 +269,9 @@ class TransformProcessor(NOPProcessor):
return handle_command_define ( e , self . context )
if " c " in e . attributes :
return self . transform ( CodeCommand ( e . text , identifier = e . identifier , classes = e . classes , attributes = e . attributes ) )
command = CodeCommand ( e . text , identifier = e . identifier , classes = e . classes , attributes = e . attributes )
attach ( command , e . parent , e . location , e . index )
return self . transform ( command )
# Pass down metadata 'highlight' and 'highlight_style' as attribute to CodeBlocks
# OG now has Context so this is not needed per se, but I'm keeping this here for the handling of attribute > context > default value