Skip to content

Commit 92e7164

Browse files
Fix #3104 (#3105)
* Fix #3104 * Fixing tests to account for new inline styles in HTML export * Update changelog * Add Aaron Beaudoin to contributors file. --------- Co-authored-by: Darren Burns <[email protected]>
1 parent 9f620dc commit 92e7164

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Adds missing parameters to Panel.fit https://github.com/Textualize/rich/issues/3142
1313

14+
### Fixed
15+
16+
- Ensure font is correctly inherited in exported HTML https://github.com/Textualize/rich/issues/3104
17+
1418
## [13.6.0] - 2023-09-30
1519

1620
### Added

Diff for: CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ The following people have contributed to the development of Rich:
7373
- [James Addison](https://github.com/jayaddison)
7474
- [Pierro](https://github.com/xpierroz)
7575
- [Bernhard Wagner](https://github.com/bwagner)
76+
- [Aaron Beaudoin](https://github.com/AaronBeaudoin)

Diff for: rich/_export_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</style>
1313
</head>
1414
<body>
15-
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code>{code}</code></pre>
15+
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
1616
</body>
1717
</html>
1818
"""

Diff for: tests/test_console.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def test_export_html():
529529
console.print("[b]foo <script> 'test' [link=https://example.org]Click[/link]")
530530
html = console.export_html()
531531
print(repr(html))
532-
expected = '<!DOCTYPE html>\n<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<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code><span class="r1">foo &lt;</span><span class="r2">script</span><span class="r1">&gt; </span><span class="r3">&#x27;test&#x27;</span><span class="r1"> </span><a class="r1" href="https://example.org">Click</a>\n</code></pre>\n</body>\n</html>\n'
532+
expected = '<!DOCTYPE html>\n<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<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit"><span class="r1">foo &lt;</span><span class="r2">script</span><span class="r1">&gt; </span><span class="r3">&#x27;test&#x27;</span><span class="r1"> </span><a class="r1" href="https://example.org">Click</a>\n</code></pre>\n</body>\n</html>\n'
533533
assert html == expected
534534

535535

@@ -538,7 +538,7 @@ def test_export_html_inline():
538538
console.print("[b]foo [link=https://example.org]Click[/link]")
539539
html = console.export_html(inline_styles=True)
540540
print(repr(html))
541-
expected = '<!DOCTYPE html>\n<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<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code><span style="font-weight: bold">foo </span><span style="font-weight: bold"><a href="https://example.org">Click</a></span>\n</code></pre>\n</body>\n</html>\n'
541+
expected = '<!DOCTYPE html>\n<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<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit"><span style="font-weight: bold">foo </span><span style="font-weight: bold"><a href="https://example.org">Click</a></span>\n</code></pre>\n</body>\n</html>\n'
542542
assert html == expected
543543

544544

@@ -591,7 +591,7 @@ def test_save_text():
591591

592592

593593
def test_save_html():
594-
expected = "<!DOCTYPE html>\n<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<body>\n <pre style=\"font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><code>foo\n</code></pre>\n</body>\n</html>\n"
594+
expected = '<!DOCTYPE html>\n<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<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit">foo\n</code></pre>\n</body>\n</html>\n'
595595
console = Console(record=True, width=100)
596596
console.print("foo")
597597
with tempfile.TemporaryDirectory() as path:

0 commit comments

Comments
 (0)