GithubHelp home page GithubHelp logo

guruthree / pango-syntax-highlighter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thiemol/pango-syntax-highlighter

0.0 1.0 0.0 8 KB

Can be used to generate images of code

Python 100.00%
code code-tools image-generation syntax-highlighting

pango-syntax-highlighter's Introduction

Pango Syntax Highlighter

This is an incredibly basic tool for Python 3.x for use when creating images of code, e.g., for slides with code snippets in. It takes a given file and using Pygments it converts it into a syntax highlighted Pango compatible output, which can in turn be converted to an image with Pango.

Usage

usage: pangosyntaxhighlight.py [-h] [--language LANGUAGE] [--list-languages] [--style STYLE] [--list-styles] inputfile outputfile

Syntax highlight code in Pango format using Pygments

positional arguments:
  inputfile            the input file
  outputfile           the output file

options:
  -h, --help           show this help message and exit
  --language LANGUAGE  the syntax language of the input file (otherwise auto-detected/auto)
  --list-languages     list available languages (lexers)
  --style STYLE        highlighting style, e.g., vs
  --list-styles        list available styles

Examples

To convert myfile.cpp to the image myfile.png:

python3 pangosyntaxhighlight.py myfile.cpp output.txt && pango-view --markup --font=mono -qo myfile.png output.txt

Specifying a specific programming language for a generic .txt file:

python3 pangosyntaxhighlight.py code.txt output.txt --language cpp && pango-view --markup --font=mono -qo code.png output.txt

Run with --list-languages to get a list of supported languages/lexers by short names (e.g., cpp, python, etc.). Additional short names may also work, see the available lexers list for the complete list. For example, --list-languages lists delphi, not pascal, but the latter will work.

Specifying the vs highlighting style:

python3 pangosyntaxhighlight.py myfile.cpp output.txt --style vs && pango-view --markup --font=mono -qo myfile.png output.txt

Run with --list-styles to get a list of styles supported by your system. Style previews are available here.

To change the resolution of generated images use the --dpi flag for pango-view:

python3 pangosyntaxhighlight.py myfile.cpp output.txt && pango-view --markup --font=mono --dpi=120 -qo myfile.png output.txt

Requirements

python, pygments, pango

pango-syntax-highlighter's People

Contributors

guruthree avatar linuxjedi avatar thiemol avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.