feat: add configurable base filename for code block downloads#559
Open
aradhyacp wants to merge 5 commits into
Open
feat: add configurable base filename for code block downloads#559aradhyacp wants to merge 5 commits into
aradhyacp wants to merge 5 commits into
Conversation
…and context - Introduced CodeDownloadConfig interface to define optional baseFileName for code downloads. - Updated StreamdownProps to include codeDownload property. - Enhanced StreamdownContextType to support codeDownload configuration. - Ensured default values are set for new properties in the context.
… codeDownload configuration - Modified filename logic in CodeBlockDownloadButton to utilize baseFileName from StreamdownContext. - Ensured fallback to default filename if baseFileName is not provided.
…lename scenarios - Added tests to verify the functionality of custom baseFileName in the download button. - Included cases for handling undefined codeDownload, unknown languages, and special characters in filenames. - Ensured that the button is enabled and the correct filename is used during the download process.
Contributor
|
@aradhyacp is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
…nd component usage - Simplified the rendering of CodeBlockDownloadButton by consolidating props into a single line. - Updated test assertions for expected save calls to improve readability and maintainability.
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.
Description
Adds support for configuring the base filename used by the built-in code block download button.
Previously, downloaded files were always named file., where the extension was inferred from the detected language (for example file.ts, file.py, file.json). This change allows consumers to specify a custom base filename while preserving Streamdown's existing language-to-extension mapping.
The implementation intentionally focuses on a configurable base filename rather than supporting dynamic filename generation or code-fence metadata.
While code-fence metadata (for example
```ts title=main.ts) is a reasonable source for filenames, it is not consistently emitted by AI assistants. Many popular AI chatbots—including major providers—typically output fenced code blocks without metadata, making it an unreliable source for default filenames. A simple configurable base filename provides a predictable solution that works regardless of where the markdown originates.The existing language detection continues to determine the correct file extension automatically, so users only need to configure the filename prefix.
Type of Change
Related Issues
Fixes #558
Closes #558
Related to #558
Changes Made
Testing
Test Coverage
Test component:
Verified that downloads produce:
customFileName.tsxWhen codeDownload is omitted, the existing behavior remains unchanged:
file.tsxScreenshots/Demos
Checklist
pnpm changeset)Changeset
Additional Notes
This PR intentionally does not introduce support for filename generation from code-fence metadata (for example title=main.ts)
The goal of this change is to provide a simple and reliable API that works consistently across markdown produced by different sources. Since many AI assistants do not emit code-fence metadata, relying on it would not provide a dependable default experience. Likewise, callback-based filename generation adds API complexity for a use case that can already be addressed by configuring a base filename while continuing to infer the correct extension automatically.
Future enhancements can build on this API if broader filename customization becomes a common request.