mirror of https://github.com/Textualize/rich.git
Fix broken HTML encoding
Missing to specify encoding can mess some clients which may break the file encoding or render it incorrectly. Example: file that loads ok locally, after upload to S3 gets broken if the encoding is not mentioned in file. Use of UTF-8 is a very good practice, but we still need to mention it.
This commit is contained in:
parent
86ee6a1de9
commit
60fde2a274
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [7.0.1] - unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- UTF-8 encoding is now mentioned in HTML head section
|
||||||
|
|
||||||
## [7.0.0] - 2020-09-18
|
## [7.0.0] - 2020-09-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -56,6 +56,7 @@ OverflowMethod = Literal["fold", "crop", "ellipsis", "ignore"]
|
||||||
CONSOLE_HTML_FORMAT = """\
|
CONSOLE_HTML_FORMAT = """\
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
<style>
|
<style>
|
||||||
{stylesheet}
|
{stylesheet}
|
||||||
body {{
|
body {{
|
||||||
|
|
|
@ -251,7 +251,7 @@ def test_export_html():
|
||||||
console = Console(record=True, width=100)
|
console = Console(record=True, width=100)
|
||||||
console.print("[b]foo [link=https://example.org]Click[/link]")
|
console.print("[b]foo [link=https://example.org]Click[/link]")
|
||||||
html = console.export_html()
|
html = console.export_html()
|
||||||
expected = '<!DOCTYPE html>\n<head>\n<style>\n.r1 {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><a href="https://example.org"><span class="r1">Click</span></a>\n</pre>\n </code>\n</body>\n</html>\n'
|
expected = '<!DOCTYPE html>\n<head>\n<meta charset="UTF-8">\n<style>\n.r1 {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><a href="https://example.org"><span class="r1">Click</span></a>\n</pre>\n </code>\n</body>\n</html>\n'
|
||||||
assert html == expected
|
assert html == expected
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ def test_export_html_inline():
|
||||||
console = Console(record=True, width=100)
|
console = Console(record=True, width=100)
|
||||||
console.print("[b]foo [link=https://example.org]Click[/link]")
|
console.print("[b]foo [link=https://example.org]Click[/link]")
|
||||||
html = console.export_html(inline_styles=True)
|
html = console.export_html(inline_styles=True)
|
||||||
expected = '<!DOCTYPE html>\n<head>\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><a href="https://example.org"><span style="font-weight: bold">Click</span></a>\n</pre>\n </code>\n</body>\n</html>\n'
|
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><a href="https://example.org"><span style="font-weight: bold">Click</span></a>\n</pre>\n </code>\n</body>\n</html>\n'
|
||||||
assert html == expected
|
assert html == expected
|
||||||
|
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ def test_save_text():
|
||||||
|
|
||||||
|
|
||||||
def test_save_html():
|
def test_save_html():
|
||||||
expected = "<!DOCTYPE html>\n<head>\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\">foo\n</pre>\n </code>\n</body>\n</html>\n"
|
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\">foo\n</pre>\n </code>\n</body>\n</html>\n"
|
||||||
console = Console(record=True, width=100)
|
console = Console(record=True, width=100)
|
||||||
console.print("foo")
|
console.print("foo")
|
||||||
with tempfile.TemporaryDirectory() as path:
|
with tempfile.TemporaryDirectory() as path:
|
||||||
|
|
Loading…
Reference in New Issue