File tree 1 file changed +4
-1
lines changed
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class Element:
28
28
29
29
transform_origin : Optional [str ] = None
30
30
style : Optional [str ] = None
31
+ data : Optional [dict ] = None
31
32
32
33
@classmethod
33
34
def _as_str (cls , val : Any ) -> str :
@@ -48,7 +49,7 @@ def as_dict(self) -> dict[str, str]:
48
49
for key , val in vars (self ).items ():
49
50
if val is None :
50
51
continue
51
- if key in ("elements" , "text" ):
52
+ if key in ("elements" , "text" , "data" ):
52
53
continue
53
54
key = key .rstrip ("_" )
54
55
key = key .replace ("__" , ":" )
@@ -58,6 +59,8 @@ def as_dict(self) -> dict[str, str]:
58
59
59
60
def as_str (self ) -> str :
60
61
props = " " .join (f'{ k } ="{ v } "' for k , v in self .as_dict ().items ())
62
+ if self .data :
63
+ props += " " + " " .join (f'data-{ k } ="{ v } "' for k , v in self .data .items ())
61
64
if self .text :
62
65
return f"<{ self .element_name } { props } >{ self .text } </{ self .element_name } >"
63
66
if self .elements :
You can’t perform that action at this time.
0 commit comments