@ -6,10 +6,11 @@ from typing import Union, Callable
import os
import re
import warnings
from . whitespace import NBSP
from . elements import FQuoted
from . context import Group
from . context import Group , InlineGroup , BlockGroup
from . util import nullify , import_md
from . context import Context
from . whitespace import Whitespace , bavlna
@ -69,6 +70,8 @@ class TransformProcessor:
TableFoot : self . transform_TableFoot ,
TableHead : self . transform_TableHead ,
Group : self . transform_Group ,
InlineGroup : self . transform_InlineGroup ,
BlockGroup : self . transform_BlockGroup ,
Cite : self . transform_Cite ,
Code : self . transform_Code ,
@ -253,6 +256,14 @@ class TransformProcessor:
e . content = self . transform ( e . content )
return e
def transform_InlineGroup ( self , e : InlineGroup ) - > InlineGroup :
e . content = self . transform ( e . content )
return e
def transform_BlockGroup ( self , e : BlockGroup ) - > BlockGroup :
e . content = self . transform ( e . content )
return e
def transform_Cite ( self , e : Cite ) - > Cite :
e . content = self . transform ( e . content )
return e
@ -314,7 +325,7 @@ class TransformProcessor:
raise DoubleDocError ( )
self . context = Context ( e , self . root_file_path )
e . content = self . transform ( e . content )
e . content = [ Group ( * e . content , context = self . context ) ]
e . content = [ Block Group( * e . content , context = self . context ) ]
return e
@ -326,7 +337,7 @@ class TransformProcessor:
" sk " : " cs " ,
None : None
}
return FQuoted ( * e . content , quote_type = e . quote_type , style = quote_styles [ self . context . get_metadata ( " language " ) ] )
return FQuoted ( * e . content , quote_type = e . quote_type , style = quote_styles [ self . context . get_metadata ( " lang " ) ] )
def transform_Image ( self , e : Image ) - > Image :
e . content = self . transform ( e . content )
@ -340,12 +351,15 @@ class TransformProcessor:
e . attributes [ " no-srcset " ] = self . context . get_metadata ( " no-srcset " ) if self . context . get_metadata ( " no-srcset " ) is not None else False
return e
def create_Group ( self , * content , new_context : Context ) - > Group :
def create_Group ( self , * content , new_context : Context , inline : bool = False ) - > Group :
old_context = self . context
self . context = new_context
content = self . transform ( [ * content ] )
self . context = old_context
return Group ( * content , context = new_context )
if inline :
return InlineGroup ( * content , context = new_context )
else :
return BlockGroup ( * content , context = new_context )
def transform_Div ( self , e : Div ) - > Union [ Div , Group , Null ] :
e . content = self . transform ( e . content )
@ -355,7 +369,7 @@ class TransformProcessor:
# Content of Div is enclosed in a separate context, all attributes are passed as metadata
new_context = Context ( Doc ( ) , self . context . path , self . context , trusted = self . context . trusted )
for attribute , value in e . attributes . items ( ) :
new_context . set_metadata ( attribute , value ) # FIXME: This raises a warning when done with `language`. Since context is available to OG, we should trash the warning and rework the OG to use the Context.
new_context . set_metadata ( attribute , value )
return self . create_Group ( * e . content , new_context = new_context )
if " c " in e . attributes :
@ -383,19 +397,22 @@ class TransformProcessor:
trusted = False
return self . create_Group ( * includedDoc . content , new_context = Context ( includedDoc , path , self . context , trusted = trusted ) )
if " lang " in e . attributes :
warnings . warn ( " To set language in a way formátítko will understand, this Div has to have the `.group` class and be a Group. " , UserWarning )
return e
def transform_Span ( self , e : Span ) - > Span :
e . content = self . transform ( e . content )
# TODO: This sadly doesn't work. We would need to create a separate class InlineGroup, that would be Inline.
#if "group" in e.classes :
# # `.group` class for Spans
# # Content of Span is enclosed in a separate context, all attributes are passed as metadata
# new_context = Context(Doc(), self.context.path, self.context, trusted=self.context.trusted )
# for attribute, value in e.attributes.items() :
# new_context.set_metadata(attribute, value )
# return self.create_Group(*e.content, new_context=new_context )
if " group " in e . classes :
# `.group` class for Spans
# Content of Span is enclosed in a separate context, all attributes are passed as metadata
new_context = Context ( Doc ( ) , self . context . path , self . context , trusted = self . context . trusted )
for attribute , value in e . attributes . items ( ) :
new_context . set_metadata ( attribute , value )
return self . create_Group ( * e . content , new_context = new_context , inline = True )
if " c " in e . attributes :
# Commands can be called multiple ways, this handles the following syntax: