From 7631f9477bfeb30499fc6c80db4dafbb4cceccb7 Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Thu, 15 Jan 2026 09:17:35 -0700 Subject: [PATCH] Add @generated comment to HTML and SVG exports The `@generated` marker is a loose standard used to identify machine-generated files. Tools like GitHub, IDEs, and various linters recognize this marker to automatically collapse generated files, exclude generated code from coverage metrics, and provide visual indicators in pull requests. This convention has been adopted by many popular tools including Poetry (in `poetry.lock`), Cargo (in `Cargo.lock`), protobuf gencode, and more. This adds the `@generated` header comment to HTML and SVG files produced by `Console.export_html()`, `Console.export_svg()`, `Console.save_html()`, and `Console.save_svg()`. --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + rich/_export_format.py | 3 ++- tests/test_console.py | 8 ++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e53205666f..182aa154a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Added `@generated` marker comment to HTML and SVG exports + ## [14.2.0] - 2025-10-09 ### Changed diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4b04786b9c..04b444757c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -60,6 +60,7 @@ The following people have contributed to the development of Rich: - [Felipe Guedes](https://github.com/guedesfelipe) - [Min RK](https://github.com/minrk) - [Clément Robert](https://github.com/neutrinoceros) +- [Jack Rosenthal](https://github.com/jackrosenthal) - [Brian Rutledge](https://github.com/bhrutledge) - [Tushar Sadhwani](https://github.com/tusharsadhwani) - [Luca Salvarani](https://github.com/LukeSavefrogs) diff --git a/rich/_export_format.py b/rich/_export_format.py index e7527e52f6..4556bb552c 100644 --- a/rich/_export_format.py +++ b/rich/_export_format.py @@ -1,5 +1,6 @@ CONSOLE_HTML_FORMAT = """\ + @@ -19,7 +20,7 @@ CONSOLE_SVG_FORMAT = """\ - + \n\n\n\n\n
foo <script> 'test' Click\n
\n\n\n' + expected = '\n\n\n\n\n\n\n\n
foo <script> 'test' Click\n
\n\n\n' assert html == expected @@ -524,11 +524,11 @@ def test_export_html_inline() -> None: console.print("[b]foo [link=https://example.org]Click[/link]") html = console.export_html(inline_styles=True) print(repr(html)) - expected = '\n\n\n\n\n\n\n
foo Click\n
\n\n\n' + expected = '\n\n\n\n\n\n\n\n
foo Click\n
\n\n\n' assert html == expected -EXPECTED_SVG = '\n \n \n\n \n \n \n \n \n \n\n Rich\n \n \n \n \n \n \n \n \n \n fooClick\n\n \n \n\n' +EXPECTED_SVG = '\n \n \n\n \n \n \n \n \n \n\n Rich\n \n \n \n \n \n \n \n \n \n fooClick\n\n \n \n\n' def test_export_svg() -> None: @@ -577,7 +577,7 @@ def test_save_text() -> None: def test_save_html() -> None: - expected = '\n\n\n\n\n\n\n
foo\n
\n\n\n' + expected = '\n\n\n\n\n\n\n\n
foo\n
\n\n\n' console = Console(record=True, width=100) console.print("foo") with tempfile.TemporaryDirectory() as path: