@ -15,7 +15,6 @@ class FQuoted(Quoted):
def transform ( e : Element , c : Context ) - > Element : # Returns next sibling element to transform
def transform ( e : Element , c : Context ) - > Element : # Returns next sibling element to transform
""" Transform the AST, making format-agnostic changes. """
""" Transform the AST, making format-agnostic changes. """
if isinstance ( e , Whitespace ) and bavlna ( e , c ) :
if isinstance ( e , Whitespace ) and bavlna ( e , c ) :
e = NBSP ( )
e = NBSP ( )
@ -41,7 +40,7 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element
# commands without affecting the state of the current document.
# commands without affecting the state of the current document.
if ( isinstance ( e , Div ) ) and " partial " in e . attributes :
if ( isinstance ( e , Div ) ) and " partial " in e . attributes :
includedDoc = import_md ( open ( e . attributes [ " partial " ] , " r " ) . read ( ) )
includedDoc = import_md ( open ( e . attributes [ " partial " ] , " r " ) . read ( ) )
nContext = Context ( includedDoc , c )
nContext = Context ( includedDoc , e . attributes [ " partial " ] , c )
includedDoc = includedDoc . walk ( transform , nContext )
includedDoc = includedDoc . walk ( transform , nContext )
e = Div ( * includedDoc . content )
e = Div ( * includedDoc . content )
@ -60,9 +59,17 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element
## Command defines
## Command defines
# possible TODO: def/longdef?
# possible TODO: def/longdef?
if isinstance ( e , CodeBlock ) and hasattr ( e , " classes " ) and " python " in e . classes and hasattr ( e , " attributes " ) :
if isinstance ( e , CodeBlock ) and hasattr ( e , " classes " ) and " python " in e . classes and hasattr ( e , " attributes " ) \
and ( " define " in e . attributes or " redefine " in e . attributes ) :
e = handle_command_define ( e , c )
e = handle_command_define ( e , c )
# Pass down metadata 'highlight' and 'highlight_style' as attribute to CodeBlocks
if isinstance ( e , CodeBlock ) :
if not " highlight " in e . attributes :
e . attributes [ " highlight " ] = c . get_metadata ( " highlight " ) if c . get_metadata ( " highlight " ) is not None else True
if not " style " in e . attributes :
e . attributes [ " style " ] = c . get_metadata ( " highlight_style " ) if c . get_metadata ( " highlight_style " ) is not None else " default "
## Shorthands
## Shorthands
if isinstance ( e , Span ) and len ( e . content ) == 1 and isinstance ( e . content [ 0 ] , Str ) :
if isinstance ( e , Span ) and len ( e . content ) == 1 and isinstance ( e . content [ 0 ] , Str ) :
## Handle special command shorthand [!commandname]{}
## Handle special command shorthand [!commandname]{}