English | 简体中文
SweetShot is a code screenshot generator.
Syntax highlighting and themes come from SweetLine. Output can be SVG, PNG, or HTML. Use the CLI for README files, docs, blog posts, release notes, or generated assets. Use the C++ core when the renderer needs to live inside another app.
- SVG, PNG, and HTML output
- Built-in themes
- Line numbers and line ranges
- Focus and mark ranges for calling out lines
- Indent guides for nested code blocks
- Rainbow brackets for nested bracket pairs
- PNG rendering through
resvgorlunasvg
build/bin/sweetshot src/lunasvg_rasterizer.cpp --lines 84:112 --focus 87:111 -o docs/images/readme-indent-guides.pngYou need CMake and a C++17 compiler. The default PNG backend is resvg, so the default build also needs Rust/Cargo.
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failureThe build fetches SweetLine with CMake FetchContent from https://github.com/FinalScave/SweetLine.git. It is pinned to b9617f1b0108d5384b0d61493b6ed992efcf0dfd.
Set SWEETSHOT_PNG_BACKEND if you want to choose the PNG renderer explicitly:
cmake -S . -B build -DSWEETSHOT_PNG_BACKEND=resvg
cmake -S . -B build-lunasvg -DSWEETSHOT_PNG_BACKEND=lunasvgThe output format is picked from the output file extension.
build/bin/sweetshot main.cpp -o main.svg
build/bin/sweetshot main.cpp -o main.png
build/bin/sweetshot main.cpp -o main.png --scale 1
build/bin/sweetshot main.cpp --theme default --lines 20:60 --focus 32:38 -o part.svg
cat main.cpp | build/bin/sweetshot --lang cpp -o stdin.htmlPNG output uses the configured backend. It renders at 3x scale by default so text stays sharp in normal use.
Common flags:
--scale <factor>sets the PNG output scale. The default is3.--theme <name>selects a built-in theme.--lines <start:end>renders a one-based inclusive line range.--focus <range-list>highlights one-based lines.--mark <range-list>marks one-based lines.--no-line-numbershides line numbers.--no-indent-guideshides indent guide lines.--no-rainbow-bracketshides rainbow bracket colors.--syntax-dir <path>overrides the SweetLine syntax directory.
skill/sweetshot-code-screenshot/ packages SweetShot for agents that need to generate code screenshots without building this repository first.
The skill includes platform binaries, bundled SweetLine syntax files, and SKILL.md with invocation rules. Agent integrations should prefer the binary under the skill directory and pass --syntax-dir; when no syntax directory is provided, use skill/sweetshot-code-screenshot/syntaxes.
