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
On macOS, download embed-code-macos-arm64.zip for Apple silicon or
embed-code-macos-x64.zip for Intel Macs. Then unzip it and run the binary:
unzip embed-code-macos-arm64.zip
./embed-code-macos-arm64 -mode=check -config-path=showcase/embedding/embed-code.ymlOr 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 ./showcaseThe main user guide is the showcase. Go package docs are useful for maintainers who need to browse package comments and exported APIs.
Generate static API docs:
./scripts/godocThe script writes build/godoc/ and prints the generated main index file link.
Launch the GoDoc server:
./scripts/godoc-serveOpen the package link printed by the script.