@@ -87,27 +87,25 @@ def render(self, content_state: Optional[ContentState] = None) -> str:
8787 def render_block (
8888 self , block : Block , entity_map : EntityMap , wrapper_state : WrapperState
8989 ) -> Element :
90+ has_styles = "inlineStyleRanges" in block and block ["inlineStyleRanges" ]
91+ has_entities = "entityRanges" in block and block ["entityRanges" ]
9092 has_decorators = should_render_decorators (
9193 self .composite_decorators , block ["text" ]
9294 )
9395
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 :
10097 content = DOM .create_element ()
10198 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
103100
104101 for (text , commands ) in self .build_command_groups (block ):
105102 for command in commands :
106103 entity_state .apply (command )
107- style_state .apply (command )
104+ if style_state :
105+ style_state .apply (command )
108106
109107 # 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 ():
111109 decorated_node = render_decorators (
112110 self .composite_decorators ,
113111 text ,
@@ -117,9 +115,12 @@ def render_block(
117115 else :
118116 decorated_node = text
119117
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
123124 entity_node = entity_state .render_entities (
124125 styled_node , block , wrapper_state .blocks
125126 )
0 commit comments