(segments: Iterable[Segment])
| 57 | |
| 58 | |
| 59 | def _render_segments(segments: Iterable[Segment]) -> str: |
| 60 | def escape(text: str) -> str: |
| 61 | """Escape html.""" |
| 62 | return text.replace("&", "&").replace("<", "<").replace(">", ">") |
| 63 | |
| 64 | fragments: List[str] = [] |
| 65 | append_fragment = fragments.append |
| 66 | theme = DEFAULT_TERMINAL_THEME |
| 67 | for text, style, control in Segment.simplify(segments): |
| 68 | if control: |
| 69 | continue |
| 70 | text = escape(text) |
| 71 | if style: |
| 72 | rule = style.get_html_style(theme) |
| 73 | text = f'<span style="{rule}">{text}</span>' if rule else text |
| 74 | if style.link: |
| 75 | text = f'<a href="{style.link}" target="_blank">{text}</a>' |
| 76 | append_fragment(text) |
| 77 | |
| 78 | code = "".join(fragments) |
| 79 | html = JUPYTER_HTML_FORMAT.format(code=code) |
| 80 | |
| 81 | return html |
| 82 | |
| 83 | |
| 84 | def display(segments: Iterable[Segment], text: str) -> None: |
no test coverage detected