Add --default-extension argument to force file format#1842
Merged
Conversation
Closed
thomas-zahner
approved these changes
Sep 11, 2025
| [default: md,mkd,mdx,mdown,mdwn,mkdn,mkdown,markdown,html,htm,txt] | ||
|
|
||
| --default-extension <EXTENSION> | ||
| Default file extension to treat files without extensions as having. |
Member
There was a problem hiding this comment.
I'm really confused by this sentence 😅
Suggested change
| Default file extension to treat files without extensions as having. | |
| This is the default file extension that is applied to files without an extension. |
Member
Author
There was a problem hiding this comment.
Probably just me editing the wording over and over again until I broke the grammar.
Member
There was a problem hiding this comment.
@mre I noticed now that you merged your version. Did you forget about changing it? I still think this original version is quite confusing 😄
Member
Author
There was a problem hiding this comment.
Oh, that was by mistake. I thought I updated the text but apparently not.
Resolves #1665 by implementing a --default-extension option that allows users to specify a default file extension for files without extensions. Key features: - New --default-extension CLI option (e.g., --default-extension md) - Accepts any valid file extension: md, html, txt, etc. - Extension is used to determine file type for processing files without extensions - Invalid extensions gracefully fall back to default plaintext handling - Consistent with existing --extensions option pattern Implementation details: - Added default_extension field to Config struct - Enhanced FileType::from_extension() to be public with proper documentation - Updated Input processing to use default file type hint when provided - Added comprehensive unit and integration tests Examples: lychee --default-extension md README # Treat README as markdown lychee --default-extension html index # Treat index as HTML lychee --default-extension txt CHANGELOG # Treat CHANGELOG as plaintext This approach is more user-friendly than abstract file types, as users work directly with familiar file extensions while maintaining full compatibility with the existing file type system.
- Made from_extension() method public with must_use attribute - Added comprehensive unit tests for extension parsing - Tests cover valid extensions, case sensitivity, and invalid inputs
The SSL error message varies between environments (local vs CI). Reverting to original expected message for consistency with CI.
Fixes test_readme_usage_up_to_date by adding the new --default-extension option to the usage section in README.md
Co-authored-by: Thomas Zahner <thomas.zahner@protonmail.ch>
Co-authored-by: Thomas Zahner <thomas.zahner@protonmail.ch>
- Change "invalid" to "unknown" in test comments and variables - Rename parameter from "ext" to "extension" in from_extension function - Keep from_extension method instead of implementing From<&str> trait for better API clarity
- Add missing default_extension field to Config initialization - Update README documentation to match current help text format
- Add more descriptive comments explaining the test behavior - Include actual link content in the test file to verify link extraction - Assert that the link is actually found and extracted as plaintext - This makes the test more robust and demonstrates the fallback behavior
This was referenced Sep 15, 2025
Closed
This was referenced Oct 21, 2025
Closed
Merged
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.
Summary
Fixes #1665 by implementing a
--default-extensionoption that allows users to specify a default file extension for files without extensions.Problem
Users needed a way to manually specify the file format for files without clear extensions. This is common with:
Solution
Added
--default-extensionCLI option that:md,html,txt)--extensionsoptionExamples
Implementation Details
--default-extensionargument toConfigstructFileType::from_extension()to be publicinputs()method to convert extension toFileTypehintDesign Decision: Extensions vs Types
Initially considered using abstract types (
--default-type markdown), but switched to extensions (--default-extension md) because:--extensionsoption patternTest Plan
FileType::from_extension()with valid/invalid extensionsVerification
Before:
Files without extensions were always treated as plaintext, potentially missing links in markdown/HTML content.
After:
The feature integrates seamlessly with existing functionality while providing users the control they need over file type detection.