Embed Code is a Go command-line tool that keeps documentation snippets in sync
with source files. It scans Markdown and HTML documents for <embed-code>
instructions, resolves the requested source content, and manages the following
code fence.
This project replaces the earlier embed-code utility for Ruby/Jekyll.
The complete usage guide lives in the showcase. It covers configuration, embedding instructions, check mode, embed mode, expected failures, and runnable examples.
- Embeds whole files, named fragments, source ranges, or matching source lines.
- Supports multiple named source roots for one documentation tree.
- Filters comments when examples should omit implementation notes.
- Processes Markdown and HTML documents.
- Runs in
checkmode for CI andembedmode to update documentation.
Download the asset for your platform from GitHub Releases.
On Linux, for example:
./embed-code-linux -mode=check -config-path=showcase/embedding/embed-code.ymlIt may be necessary to give the executable permission with
chmod +xon Unix-like systems:chmod +x embed-code-linux
Since binary file for macOS is not signed, it may be necessary to change its attributes to allow execution:
xattr -d com.apple.quarantine embed-code-macos
Or run it with Go:
go run ./main.go -mode=check -config-path=showcase/embedding/embed-code.ymlUse -mode=embed when documentation should be rewritten with current source
content. See the configuration guide for
all command-line flags and YAML options.
Use Go 1.26.4.
go build -trimpath -o embed-code main.goThis creates embed-code on Unix-like systems or embed-code.exe on Windows.
The -trimpath flag prevents local absolute paths from appearing in stack traces.
Run the normal test suite:
go test ./...Run the executable showcase:
go test -tags showcase ./showcase