cmd / mdembed
mdembed embeds programming file contents in Markdown.
It is open source.
Install:
go install github.com/croaky/mdembed@latest
Use
In prompt.md:
# Context
```embed
cmd/server.go
lib/**/*.rb
```
Run:
cat prompt.md | mdembed
The output will contain code blocks with the file contents, each with a header comment showing the filename:
# Context
```go
// cmd/server.go
// file contents...
```
```rb
# lib/foo.rb
# file contents...
```
```rb
# lib/bar.rb
# file contents...
```
Block markers
Embed specific sections of a file using emdo and emdone markers:
func main() {
// emdo setup
cfg := loadConfig()
db := connectDB(cfg)
// emdone setup
// ... rest of code
}
Reference the block by name:
```embed
main.go setup
```
Recursive embeds
Referencing another Markdown file embeds its contents directly, recursively processing any embed blocks it contains.
Why
I wanted a workflow in Vim:
- Open
tmp.mdin my project. - Write a prompt for an LLM, referencing files in my project.
- Hit a key combo to send the contents to an LLM.
mdembed handles the Markdown parsing.
mods handles the LLM:
cat prompt.md | mdembed | mods