code2md is a command-line tool that converts code from a specified directory into a Markdown file. It supports multiple programming languages and allows for customization through command-line flags.
For the easiest installation, download a pre-built binary.
Download the Binary:
-
Go to the releases page.
-
Download the latest binary for your operating system.
-
Windows
- Rename the downloaded file to code2md.exe.
- Place the binary in a directory that is included in your system's PATH, such as C:\Windows, or add the directory containing code2md.exe to your PATH environment variable.
-
Linux/Mac:
- Rename the binary based on your architecture:
mv code2md-linux-amd64 code2md # For Linux AMD64 mv code2md-linux-arm64 code2md # For Linux ARM64 mv code2md-darwin-amd64 code2md # For macOS AMD64 mv code2md-darwin-arm64 code2md # For macOS ARM64
- make the binary executable and move it to
/usr/local/binchmod +x code2md sudo mv code2md /usr/local/bin/ sudo chown root:root /usr/local/bin/code2md
- Rename the binary based on your architecture:
-
Requirements: Install the following dependencies
- Git to clone this repository
- Go 1.18 or later
- Make (for build and installation tasks)
-
Clone the repository:
git clone https://github.com/ahoehne/code2md.git cd code2md -
Build the application:
make build
-
Install the application:
sudo make install
To build the application for multiple platforms, run:
make buildallTo run the tests, use:
make testTo convert code from the current directory into a Markdown file named code.md, use the following command:
code2md -i . -o code.md| Flag | Short | Description |
|---|---|---|
--input |
-i |
Input directory to scan (required) |
--output |
-o |
Output Markdown file (optional, defaults to stdout) |
--languages |
-l |
Comma-separated list of allowed languages (extensions or names) |
--ignore |
-I |
Comma-separated ignore patterns |
--max-file-size |
-m |
Maximum file size in bytes (default: 100MB) |
--help |
-h |
Show help |
--version |
-v |
Show version information |
Files are excluded in three ways:
.gitignorefiles in the input directory (including nested ones) are respected with gitignore semantics.--ignorepatterns use the same syntax and replace the built-in defaults (*.yaml,*.yml,*.xml).- The
.gitdirectory and the output file itself are always skipped.
Pattern syntax follows .gitignore:
*.logmatches at any depth;*and?never cross/buildmatches a file or directory namedbuildat any depthbuild/matches directories only/buildorsrc/buildare anchored to the input directory root**matches any number of directories (docs/**,a/**/b,**/file.txt)!patternre-includes a previously ignored file; the last matching pattern wins
Language manifest files (pom.xml, package.json, go.mod, ...) of enabled languages bypass the built-in default patterns, but never patterns you pass via --ignore or .gitignore.
- On by default:
php,go,js,mjs,cjs,ts,mts,cts,jsx,tsx,py,sh,java,c,h,cpp,cc,cxx,hpp,hh,cs,rs,Dockerfile - Opt-in via
-l:md,html,scss,css,json,yaml,yml,xml,toml,sql
These commands copy the contents of code.md into the clipboard.
xclip -sel clip < code.mdpbcopy < code.mdclip < code.mdContributions are welcome. Please open an issue or submit a pull request.
This project is licensed under the MIT License.