Get console markup to render this Text. Returns: str: A string potentially creating markup tags.
(self)
| 228 | |
| 229 | @property |
| 230 | def markup(self) -> str: |
| 231 | """Get console markup to render this Text. |
| 232 | |
| 233 | Returns: |
| 234 | str: A string potentially creating markup tags. |
| 235 | """ |
| 236 | from .markup import escape |
| 237 | |
| 238 | output: List[str] = [] |
| 239 | |
| 240 | plain = self.plain |
| 241 | markup_spans = [ |
| 242 | (0, False, self.style), |
| 243 | *((span.start, False, span.style) for span in self._spans), |
| 244 | *((span.end, True, span.style) for span in self._spans), |
| 245 | (len(plain), True, self.style), |
| 246 | ] |
| 247 | markup_spans.sort(key=itemgetter(0, 1)) |
| 248 | position = 0 |
| 249 | append = output.append |
| 250 | for offset, closing, style in markup_spans: |
| 251 | if offset > position: |
| 252 | append(escape(plain[position:offset])) |
| 253 | position = offset |
| 254 | if style: |
| 255 | append(f"[/{style}]" if closing else f"[{style}]") |
| 256 | markup = "".join(output) |
| 257 | return markup |
| 258 | |
| 259 | @classmethod |
| 260 | def from_markup( |