Skip to content

feat: download code blocks as files - #1672

Draft
TobiasWallura-xitaso wants to merge 1 commit into
mainfrom
feat/code-block-download
Draft

TobiasWallura-xitaso wants to merge 1 commit into
mainfrom
feat/code-block-download

Conversation

@TobiasWallura-xitaso

@TobiasWallura-xitaso TobiasWallura-xitaso commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a download button to code blocks, next to the copy button. It saves the block text as a file.

Code blocks with download buttons

  • File name: the fence title if 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 is code.<ext>, or code.txt for an unknown language.
  • Known file names, extensions and language aliases come from linguist-languages (GitHub Linguist data, no dependencies, loaded with a dynamic import on the first download). No hand-written lists in the code.
  • The title is not sanitized: browsers already sanitize <a download> names (checked in Chromium and Firefox). Only the length is capped in bytes, because Chromium silently saves nothing above ~245 bytes.
  • The Blob is application/octet-stream, because Chromium appends .txt to extension-less names like Dockerfile for text/plain.
  • The button is part of MarkdownCode, so it shows everywhere MarkdownDisplay is used. The system prompt is unchanged.
  • Concept doc: docs/concepts/code-block-download.md.

Checked in the browser: the downloads are hello.py, Sortierfunktion.py, Dockerfile and code.sh with the exact block content.

🤖 Written by AI under human supervision.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 18:48
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.70175% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...t-bot/src/components/chat/download-code-button.tsx 8.33% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread apps/chat-bot/src/utils/code-blocks.ts Resolved
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Playwright Smart Reporter

Passed: 40 of 40 tests passed.

Pass rate Passed Failed Flaky Skipped Duration
100% 40 0 0 0 2.3m

Baseline run: main @ 99b28a5f

Slowest tests

Test Duration
character is submitted, rejected, resubmitted and approved across chat-bot and admin [chromium] 53.8s
teacher can login, create and join shared dialogpartner chat [chromium] 35.0s
can be set in the overview and the detail page and removed again [chromium] 29.0s
can be set in the overview and the detail page and removed again [chromium] 24.7s
teacher can login, create an assistant and start a chat [chromium] 22.3s

Open the full report

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues require changes to the code-block download feature.

No open issues 🎉

2 resolved since last review
1 file not reviewed
  • pnpm-lock.yaml: Generated file

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants