Skip to main content

Generate syntax-highlighted code screenshots

Project description

Pygments Renderer

License: CSSM Unlimited License v2.0

A CLI tool that generates syntax-highlighted code screenshots as PNG images. Designed for developers, educators, and content creators who need beautiful code screenshots for presentations, documentation, or social media.

Features

  • Automatic Language Detection: Uses Pygments guess_lexer to automatically detect the programming language.
  • 48 Built-in Themes: Choose from 48 Pygments color schemes (monokai, dracula, nord, solarized-dark, etc.).
  • Dynamic Background: Background color is automatically set from the chosen theme.
  • Custom Width: Adjust image width for different code lengths.
  • Custom Title: Set the window title bar text.
  • Universal Language Support: Works with any of the 575+ languages supported by Pygments.

Technologies Used

  • Python 3: Runtime
  • Pygments: Syntax highlighting and language detection
  • Pillow (PIL): Image generation

Prerequisites

  • Python ≥ 3.8

Installation

pip install -e .

Or install dependencies directly:

pip install Pillow Pygments

Getting Started

  1. Clone the repository:

    git clone https://github.com/ChernegaSergiy/pygments-renderer.git
    
  2. Install dependencies:

    pip install -e .
    
  3. Generate a screenshot:

    pygments-renderer input.cpp -o code.png
    

Usage

usage: pygments-renderer [-h] [-o OUTPUT] [-l LANGUAGE] [-t THEME] [-w WIDTH]
                         [-T TITLE]
                         input

Generate syntax-highlighted code screenshots

positional arguments:
  input                 Input file path

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output image path (default: output.png)
  -l LANGUAGE, --language LANGUAGE
                        Language (e.g., cpp, python, html, html+php)
  -t THEME, --theme THEME
                        Color theme (default, monokai, dracula, etc.)
  -w WIDTH, --width WIDTH
                        Image width (default: 880)
  -T TITLE, --title TITLE
                        Window title

Examples

Basic usage (auto-detect language):

pygments-renderer examples/task1.cpp -o code.png

Specify language and theme:

pygments-renderer input.py -t dracula -o code.png

Custom width and title:

pygments-renderer main.rs -w 1200 -T "Rust Source" -o output.png

Use with HTML + PHP:

pygments-renderer template.php -l html+php -t solarized-dark -o screenshot.png

Available Themes

Here are some popular themes you can use with -t or --theme:

  • monokai - Dark, purple-tinted (background: #272822)
  • dracula - Dark, purple/cyan (background: #282a36)
  • nord - Dark, cool gray (background: #2e3440)
  • gruvbox-dark - Retro dark (background: #282828)
  • solarized-dark - Warm dark (background: #002b36)
  • solarized-light - Warm light (background: #fdf6e3)
  • github-dark - GitHub dark (background: #0d1117)
  • material - Material Design (background: #263238)
  • one-dark - Atom One Dark (background: #282c34)
  • vim - Vim classic (background: #000000)
  • rrt - Terminal classic (background: #000000)
  • default - Pygments default (background: #f8f8f8)

Contributing

Contributions are welcome and appreciated! Here's how you can contribute:

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to adhere to the existing coding style.

License

This project is licensed under the CSSM Unlimited License v2.0 (CSSM-ULv2). See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygments_renderer-1.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygments_renderer-1.0.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pygments_renderer-1.0.0.tar.gz.

File metadata

  • Download URL: pygments_renderer-1.0.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pygments_renderer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5242cd0de0480704f58c3484acc801eaae7c13c3d8357c6d9cca81da784d700b
MD5 2e28f518f4459e8a13b8db90c914ec5c
BLAKE2b-256 a6a0d72bf0356c53df0fd518fec0b45c394d9235a1d8ab7cb204d155217197b4

See more details on using hashes here.

File details

Details for the file pygments_renderer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pygments_renderer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c1c321e1acc96edc27e35782c3e5670d068d35e531f1d62864be2de9d589510
MD5 ba22545ca300b87f90cbd16bde5af08e
BLAKE2b-256 4b3dcbe6a01d4459c98ddbacf17f3eee07c55189e415e3c762460a0c9a4a9be4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page