def test_export_html_inline(): console = Console(record=True, width=100) console.print("[b]foo [link=https://example.org]Click[/link]") html = console.export_html(inline_styles=True) print(repr(html)) expected = '<!DOCTYPE html>\n<head>\n<meta charset="UTF-8">\n<style>\n\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<html>\n<body>\n <code>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><span style="font-weight: bold">foo </span><span style="font-weight: bold"><a href="https://example.org">Click</a></span>\n</pre>\n </code>\n</body>\n</html>\n' assert html == expected
def print_exception(self, e): console = rich.console.Console(record=True) _print_rich_exception(console, e) res = console.export_html( code_format='<style>{stylesheet}</style><pre>{code}</pre>' ).replace('━', '-') self.buffer.append(res)
def test_export_html(): console = Console(record=True, width=100) console.print( "[b]foo <script> 'test' [link=https://example.org]Click[/link]") html = console.export_html() expected = '<!DOCTYPE html>\n<head>\n<meta charset="UTF-8">\n<style>\n.r1 {font-weight: bold}\n.r2 {color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold}\n.r3 {color: #008000; text-decoration-color: #008000; font-weight: bold}\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<html>\n<body>\n <code>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><span class="r1">foo <</span><span class="r2">script</span><span class="r1">> </span><span class="r3">'test'</span><span class="r1"> </span><a class="r1" href="https://example.org">Click</a>\n</pre>\n </code>\n</body>\n</html>\n' assert html == expected
def _rich_to_html(r): console = rich.console.Console(record=True) console.print(r) return console.export_html( code_format='<style>{stylesheet}</style><pre>{code}</pre>').replace( '━', '-')