Add clipboard_rich_formats: RTF + CSV/TSV clipboard codecs#402
Merged
Conversation
rich_clipboard added CF_HTML, but RTF (the format rich editors accept for styled paste) and the Csv format Excel reads were still missing. Add both: build_rtf/rtf_to_text build and strip RTF control words and escapes in pure Python with a unit-testable round-trip, and rows_to_csv/ csv_to_rows wrap the stdlib csv module (delimiter-parametrised for TSV). The Win32 get/set share one generic byte-transfer helper; codecs are platform-independent and headless-tested.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 86 |
| Duplication | 3 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
rich_clipboardaddedCF_HTMLfor rich paste into Word/Outlook, but two other cross-app clipboard formats were still missing:"Rich Text Format") — the format almost every rich editor accepts for styled paste.build_rtf/rtf_to_textbuild and strip RTF control words and\uNNNN/\'XXescapes in pure Python, with a fully unit-testable round-trip (verified for ASCII, accents, CJK, braces/backslash, newlines, tabs, and real-world hex/destination-group RTF)."Csv"format Excel reads) —rows_to_csv/csv_to_rowswrap the stdlibcsvmodule, delimiter-parametrised so\tgives TSV.Design
RuntimeErrorelsewhere, like the baseclipboardmodule)._consume_word/_consume_hex/_consume_control/_apply_word) so every function stays under CC 10._win_set_format(format_id, payload)/_win_get_format(format_id)shared by RTF and CSV (parameterised by format id — DRY within the module, distinct fromrich_clipboard/clipboard_files' format-specific helpers). The sets seed plain text so plain editors still paste.__all__→AC_set/get_clipboard_rtf+AC_set/get_clipboard_csv→ac_*MCP tools (sets side-effect-only, gets read-only) → Script Builder (Data). Qt-free verified.Tests
test/unit_test/headless/test_clipboard_rich_formats_batch.py— RTF round-trips (plain/breaks, unicode/escapes, ASCII-output assertion, metadata-drop + hex-decode, type error), CSV/TSV round-trips with embedded commas/newlines, and 5-layer wiring. 23 passed alongside the clipboard siblings. Win32 set/get not executed in CI (Windows-only), matchingclipboard_files/rich_clipboard.