The Markdown TOC Generator is a Python script that automatically creates a Markdown-formatted table of contents (TOC) for any given directory. It's designed to process directories recursively, listing all directories and text files along with their contents in a structured Markdown file.
- Recursively processes directories and files to create a detailed TOC.
- Supports a wide range of text file extensions, including code files.
- Option to include files with any chosen extension in the TOC.
- Ability to exclude specific files or directories using patterns.
- Generates a Markdown file (.md) with the complete structure and contents of the specified directory.
No special installation is required. Ensure you have Python installed on your system.
The script is executed from the command line, with several options available to customize its behavior:
python script.py -i <input_directory_path> -o <output_file_name>
-i
,--input
: Path to the input directory to process.-o
,--output
: Output file name for the Markdown TOC (without the .md extension).-ext
,--extension
: (Optional) Treat files with this extension as text files for inclusion in the TOC.-x
,--exclude
: (Optional) Exclude files/folders matching these patterns (supports wildcards).
-
Basic TOC Generation
python markdown-toc.py -i /path/to/directory -o output_filename
This will generate a TOC for all text files in the specified directory.
-
Including Specific File Extensions
python markdown-toc.py -i /path/to/directory -o output_filename -ext .xyz
This will include
.xyz
files as text in the TOC. -
Excluding Specific Files and Directories
python markdown-toc.py -i /path/to/directory -o output_filename -x "*.log" "temp/*"
This will exclude all
.log
files and everything in thetemp
directory. -
Combining Inclusion and Exclusion
python markdown-toc.py -i /path/to/directory -o output_filename -ext .py -x ".git"
This will treat
.py
files as text and exclude.git
folders.
The output is a Markdown file containing the TOC. Directories are indicated with "#" based on their depth, and files are listed with their contents (for text files).
Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.
Note: This script is highly customizable to suit various needs for directory content visualization. Great for documentation or managing file structures in projects.