Skip to content

Repository files navigation

English | 简体中文

SweetShot

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.

What It Supports

  • 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 resvg or lunasvg

Example

build/bin/sweetshot src/lunasvg_rasterizer.cpp --lines 84:112 --focus 87:111 -o docs/images/readme-indent-guides.png

SweetShot indent guides example

Build

You 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-failure

The 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=lunasvg

CLI

The 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.html

PNG 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 is 3.
  • --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-numbers hides line numbers.
  • --no-indent-guides hides indent guide lines.
  • --no-rainbow-brackets hides rainbow bracket colors.
  • --syntax-dir <path> overrides the SweetLine syntax directory.

Agent Skill

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.

About

SweetLine-powered code rendering toolkit for turning source code into polished SVG, HTML, and shareable images(such as PNG).

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages