@@ -395,6 +395,34 @@ def assemble(
395395 text_append (end )
396396 return cls ("" .join (text ), spans )
397397
398+ def simplify (self ) -> Content :
399+ """Simplify spans in place.
400+
401+ This joins contiguous spans together which can produce faster renders.
402+
403+ Note that this is only typically worth it if you have appended a large number of Content instances together,
404+ and it only needs to be done once.
405+
406+ Returns:
407+ Self.
408+ """
409+ spans = self .spans
410+ if not spans :
411+ return self
412+ last_span = Span (0 , 0 , Style ())
413+ new_spans : list [Span ] = []
414+ changed : bool = False
415+ for span in self ._spans :
416+ if span .start == last_span .end and span .style == last_span .style :
417+ last_span = new_spans [- 1 ] = Span (last_span .start , span .end , span .style )
418+ changed = True
419+ else :
420+ new_spans .append (span )
421+ last_span = span
422+ if changed :
423+ self ._spans [:] = new_spans
424+ return self
425+
398426 def __eq__ (self , other : object ) -> bool :
399427 """Compares text only, so that markup doesn't effect sorting."""
400428 if isinstance (other , str ):
@@ -528,7 +556,6 @@ def get_span(y: int) -> tuple[int, int] | None:
528556 return None
529557
530558 for y , line in enumerate (self .split (allow_blank = True )):
531-
532559 if post_style is not None :
533560 line = line .stylize (post_style )
534561
@@ -1201,6 +1228,11 @@ def render_segments(
12011228 ]
12021229 return segments
12031230
1231+ def __rich__ (self ):
1232+ from rich .segment import Segments
1233+
1234+ return Segments (self .render_segments (Style (), "\n " ))
1235+
12041236 def _divide_spans (self , offsets : tuple [int , ...]) -> list [tuple [Span , int , int ]]:
12051237 """Divide content from a list of offset to cut.
12061238
@@ -1568,7 +1600,6 @@ def to_strip(self, style: Style) -> tuple[list[Segment], int]:
15681600 def _apply_link_style (
15691601 self , link_style : RichStyle , segments : list [Segment ]
15701602 ) -> list [Segment ]:
1571-
15721603 _Segment = Segment
15731604 segments = [
15741605 _Segment (
0 commit comments