Repository navigation
feat: download code blocks as files - #1672
Draft
TobiasWallura-xitaso wants to merge 1 commit into
Draft
TobiasWallura-xitaso wants to merge 1 commit into
TobiasWallura-xitaso wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The language-index cache prevents retries after a transient import failure, and filtering fence tokens causes known languages such as c++ and c# to download with incorrect .txt extensions.
2 open issues
1 file not reviewed
pnpm-lock.yaml: Generated file
What changed in this PR
Adds file downloads to code blocks throughout the chat interface, alongside the existing copy action.
Changes:
- Resolves filenames from fence titles and language metadata, with sanitization and lazy-loaded Linguist data.
- Adds a download button with translated labels and error messages in six locales.
- Documents filename rules and adds unit coverage for resolution and sanitization.
| File | Description |
|---|---|
pnpm-lock.yaml |
Locks the Linguist dependency. |
docs/concepts/README.md |
Links the download concept guide. |
docs/concepts/code-block-download.md |
Documents download behavior and filename rules. |
apps/chat-bot/src/utils/code-blocks.ts |
Adds filename resolution and sanitization. |
apps/chat-bot/src/utils/code-blocks.test.ts |
Tests filename rules, aliases, and sanitization. |
apps/chat-bot/src/components/chat/markdown-code.tsx |
Places the download action beside copy. |
apps/chat-bot/src/components/chat/download-code-button.tsx |
Implements file downloads and error feedback. |
apps/chat-bot/package.json |
Adds the pinned Linguist dependency. |
apps/chat-bot/messages/ru.json |
Adds Russian download translations. |
apps/chat-bot/messages/it.json |
Adds Italian download translations. |
apps/chat-bot/messages/fr.json |
Adds French download translations. |
apps/chat-bot/messages/en.json |
Adds English download translations. |
apps/chat-bot/messages/de.json |
Adds German download translations. |
apps/chat-bot/messages/ar.json |
Adds Arabic download translations. |
Review effort: Balanced
Playwright Smart ReporterPassed: 40 of 40 tests passed.
Baseline run: Slowest tests
|
Add a download button next to the copy button of code blocks. The file name is the fence title if it is a known file name, otherwise the title or "code" plus the extension of the fence language. Extensions, file names and aliases come from linguist-languages, loaded on first use. Browsers already sanitize download names, so only the length is capped in bytes (Chromium silently drops longer names). The Blob uses application/octet-stream so Chromium keeps extension-less names like Dockerfile. Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
TobiasWallura-xitaso
force-pushed
the
feat/code-block-download
branch
from
November 11, 2026 19:59
5014a1f to
052170c
Compare
This branch has not been deployed
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.

Adds a download button to code blocks, next to the copy button. It saves the block text as a file.
titleif it is a known file name (hello.py,Dockerfile), otherwise the title plus the extension of the fence language (Sortierfunktion.py). Without a title it iscode.<ext>, orcode.txtfor an unknown language.linguist-languages(GitHub Linguist data, no dependencies, loaded with a dynamic import on the first download). No hand-written lists in the code.<a download>names (checked in Chromium and Firefox). Only the length is capped in bytes, because Chromium silently saves nothing above ~245 bytes.application/octet-stream, because Chromium appends.txtto extension-less names likeDockerfilefortext/plain.MarkdownCode, so it shows everywhereMarkdownDisplayis used. The system prompt is unchanged.docs/concepts/code-block-download.md.Checked in the browser: the downloads are
hello.py,Sortierfunktion.py,Dockerfileandcode.shwith the exact block content.🤖 Written by AI under human supervision.