Skip to main content

Generate syntax-highlighted code screenshots

Project description

Pygments Renderer

License: CSSM Unlimited License v2.0 Python Version PyPI Version

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]
                         [-s START] [-f FONT] [-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)
  -s START, --start START
                        Starting line number (default: 1)
  -f FONT, --font FONT  Font file path or system font name
  -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

Custom starting line number:

pygments-renderer input.cpp -s 10 -o code.png

Custom font:

pygments-renderer input.cpp -f "Consolas" -o code.png
pygments-renderer input.cpp -f /path/to/font.ttf -o code.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.1.0.tar.gz (10.0 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.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygments_renderer-1.1.0.tar.gz
  • Upload date:
  • Size: 10.0 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.1.0.tar.gz
Algorithm Hash digest
SHA256 066ffc017701d6dc4f73a7fddb0ee3b85c228171cfd8f9d135447115af54fb5e
MD5 0fbde955b2077020f2885e27d5044099
BLAKE2b-256 e4014f157ac39202cb599fde58d1b4d7ec06c771b423529ad3ed7a54be6b650b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pygments_renderer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38e4532bccbc31f296f218e03223a7e946ed1ed6249c80276a2cca5c758140bb
MD5 377a7eda95f29cbcdd4b3b04b0575b30
BLAKE2b-256 d645b811b2b2469dfde4ec6b6b1439eb48da56d228592f91ccf1523db76cc0b7

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