@@ -87,27 +87,25 @@ def render(self, content_state: Optional[ContentState] = None) -> str:
87
87
def render_block (
88
88
self , block : Block , entity_map : EntityMap , wrapper_state : WrapperState
89
89
) -> Element :
90
+ has_styles = "inlineStyleRanges" in block and block ["inlineStyleRanges" ]
91
+ has_entities = "entityRanges" in block and block ["entityRanges" ]
90
92
has_decorators = should_render_decorators (
91
93
self .composite_decorators , block ["text" ]
92
94
)
93
95
94
- if (
95
- "inlineStyleRanges" in block
96
- and block ["inlineStyleRanges" ]
97
- or "entityRanges" in block
98
- and block ["entityRanges" ]
99
- ):
96
+ if has_styles or has_entities :
100
97
content = DOM .create_element ()
101
98
entity_state = EntityState (self .entity_options , entity_map )
102
- style_state = StyleState (self .style_options )
99
+ style_state = StyleState (self .style_options ) if has_styles else None
103
100
104
101
for (text , commands ) in self .build_command_groups (block ):
105
102
for command in commands :
106
103
entity_state .apply (command )
107
- style_state .apply (command )
104
+ if style_state :
105
+ style_state .apply (command )
108
106
109
107
# Decorators are not rendered inside entities.
110
- if entity_state .has_no_entity () and has_decorators :
108
+ if has_decorators and entity_state .has_no_entity ():
111
109
decorated_node = render_decorators (
112
110
self .composite_decorators ,
113
111
text ,
@@ -117,9 +115,12 @@ def render_block(
117
115
else :
118
116
decorated_node = text
119
117
120
- styled_node = style_state .render_styles (
121
- decorated_node , block , wrapper_state .blocks
122
- )
118
+ if style_state :
119
+ styled_node = style_state .render_styles (
120
+ decorated_node , block , wrapper_state .blocks
121
+ )
122
+ else :
123
+ styled_node = decorated_node
123
124
entity_node = entity_state .render_entities (
124
125
styled_node , block , wrapper_state .blocks
125
126
)
0 commit comments