A CLI tool to batch convert plain text (.txt) files to Markdown (.md). It understands the output format of codebase-convert and formats code blocks with proper syntax highlighting based on file extensions.
- Recursively finds all
.txtfiles in an input directory - Parses
codebase-convertoutput (both XML-tagged and standard formats) into clean, syntax-highlighted Markdown - Falls back to a plain code block for generic text files
- Optional directory structure preservation in the output
- Skips existing files unless
--overwriteis specified - Handles encoding errors and empty files gracefully
- Python 3.9+
python main.py <input_dir> <output_dir> [--overwrite] [--preserve-structure]| Argument | Description |
|---|---|
input_dir |
Path to the directory containing .txt files |
output_dir |
Path to the directory where .md files will be saved |
--overwrite |
Overwrite existing .md files in the output directory |
--preserve-structure |
Mirror the input directory structure in the output folder |
Convert all .txt files from input/ to output/:
python main.py input/ output/Convert and overwrite any existing files:
python main.py input/ output/ --overwriteConvert while preserving the folder structure:
python main.py input/ output/ --preserve-structureIf a .txt file contains codebase-convert output (XML tags or standard headers), it is formatted as:
# Folder Structure
\`\`\`text
...
\`\`\`
# File Contents
### File: `src/main.py`
\`\`\`python
...
\`\`\`All other .txt files are wrapped in a plain code block:
### File: `filename.txt`
\`\`\`
...
\`\`\`