All Projects β†’ pygments β†’ Pygments.rb

pygments / Pygments.rb

Licence: mit
πŸ’Ž Ruby wrapper for Pygments syntax highlighter

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Pygments.rb

Webstorm Styled Components
styled-components highlighting support in IntelliJ editors
Stars: ✭ 342 (-36.9%)
Mutual labels:  syntax-highlighting
Code Blocks
Syntax highlighting for Google Docs
Stars: ✭ 422 (-22.14%)
Mutual labels:  syntax-highlighting
Delphi Ide Theme Editor
Custom color highlighting for Object Pascal IDE's
Stars: ✭ 489 (-9.78%)
Mutual labels:  syntax-highlighting
Highlight
Rich featured syntax highlighter for Keynote slides.
Stars: ✭ 367 (-32.29%)
Mutual labels:  syntax-highlighting
Asm Dude
Visual Studio extension for assembly syntax highlighting and code completion in assembly files and the disassembly window
Stars: ✭ 3,898 (+619.19%)
Mutual labels:  syntax-highlighting
Primrose
A syntax-highlighting text editors that renders to an HTML5 Canvas
Stars: ✭ 451 (-16.79%)
Mutual labels:  syntax-highlighting
Clangkit
ClangKit provides an Objective-C frontend to LibClang. Source tokenization, diagnostics and fix-its are actually implemented.
Stars: ✭ 330 (-39.11%)
Mutual labels:  syntax-highlighting
Matchtagalways
A Vim plugin that always highlights the enclosing html/xml tags
Stars: ✭ 513 (-5.35%)
Mutual labels:  syntax-highlighting
Rainbow levels.vim
A different approach to code highlighting.
Stars: ✭ 415 (-23.43%)
Mutual labels:  syntax-highlighting
Zep
Zep - An embeddable editor, with optional support for using vim keystrokes.
Stars: ✭ 477 (-11.99%)
Mutual labels:  syntax-highlighting
Highlight.js
JavaScript syntax highlighter with language auto-detection and zero dependencies.
Stars: ✭ 19,312 (+3463.1%)
Mutual labels:  syntax-highlighting
Enlighterjs
πŸ”† an open source syntax highlighter written in pure javascript
Stars: ✭ 379 (-30.07%)
Mutual labels:  syntax-highlighting
Nord
An arctic, north-bluish color palette.
Stars: ✭ 4,816 (+788.56%)
Mutual labels:  syntax-highlighting
Nano Highlight
a spiffy collection of nano syntax highlighting files
Stars: ✭ 344 (-36.53%)
Mutual labels:  syntax-highlighting
Cudatext
Cross-platform text editor, written in Lazarus
Stars: ✭ 498 (-8.12%)
Mutual labels:  syntax-highlighting
Rainbow csv
🌈Rainbow CSV - Vim plugin: Highlight columns in CSV and TSV files and run queries in SQL-like language
Stars: ✭ 337 (-37.82%)
Mutual labels:  syntax-highlighting
Replxx
A readline and libedit replacement that supports UTF-8, syntax highlighting, hints and Windows and is BSD licensed.
Stars: ✭ 446 (-17.71%)
Mutual labels:  syntax-highlighting
Kibi
A text editor in ≀1024 lines of code, written in Rust
Stars: ✭ 522 (-3.69%)
Mutual labels:  syntax-highlighting
Sublime Monokai Extended
Extends Monokai from Soda with additional syntax highlighting for Markdown, LESS, HTML, Handlebars and more.
Stars: ✭ 505 (-6.83%)
Mutual labels:  syntax-highlighting
Ohmyrepl.jl
Syntax highlighting and other enhancements for the Julia REPL
Stars: ✭ 466 (-14.02%)
Mutual labels:  syntax-highlighting

= {project-name} Ted Nyman [email protected]; Aman Gupta [email protected]; Marat Radchenko [email protected] :project-name: pygments.rb :slug: pygments/{project-name} :uri-project: https://github.com/{slug} :uri-ci: {uri-project}/actions?query=branch%3Amaster :uri-gem: https://rubygems.org/gems/{project-name} :uri-pygments: https://pygments.org/

image:https://img.shields.io/gem/v/{project-name}.svg[Latest Release,link={uri-gem}] image:{uri-project}/workflows/CI/badge.svg?branch=master[Build Status,link={uri-ci}]

== Introduction

{project-name} is a Ruby wrapper for {uri-pygments}[Pygments] syntax highlighter.

{project-name} works by talking over a simple pipe to a long-lived Python child process. This library replaces https://github.com/github/albino[github/albino], as well as an older version of {project-name} that used an embedded Python interpreter.

Each Ruby process that runs has its own 'personal Python'; for example, 4 Unicorn workers will have one Python process each. If a Python process dies, a new one will be spawned on the next pygments.rb request.

== System Requirements

  • Python >= 3.5
  • Ruby >= 2.3

== Installation

Add this line to your application's Gemfile:

[source,ruby]

gem 'pygments.rb'

And then execute:

[source,shell script]

$ bundle install

Or install pygments.rb gem yourself as:

[source,shell script]

$ gem install pygments.rb

== Usage

Require pygments.rb module:

[source,ruby]

require 'pygments'

Highlight a file:

[source,ruby]

Pygments.highlight(File.read(FILE), lexer: 'ruby')

Optionally, pass encoding and other lexer/formatter options via an :options hash:

[source,ruby]

Pygments.highlight('code', options: {encoding: 'utf-8'})

pygments.rb uses HTML formatter by default. To use a different formatter, specify it via :formatter parameter:

[source,ruby]

Pygments.highlight('code', formatter: 'bbcode') Pygments.highlight('code', formatter: 'terminal')

To generate CSS for HTML formatted code, use the Pygments.css method:

[source,ruby]

Pygments.css Pygments.css('.highlight')

To use a specific pygments style, pass the :style option to the Pygments.css method:

[source,ruby]

Pygments.css(style: 'monokai')

Other Pygments high-level API methods are also available. These methods return arrays detailing all the available lexers, formatters, and styles:

[source,ruby]

Pygments.lexers Pygments.formatters Pygments.styles

To use a custom pygments installation, specify the path to Pygments.start:

[source,ruby]

Pygments.start("/path/to/pygments")

If you'd like logging, set the environmental variable MENTOS_LOG to a file path for your logfile.

You can apply a timeout to pygments.rb calls by specifying number of seconds in MENTOS_TIMEOUT environmental variable or by passing the :timeout argument (takes precedence over MENTOS_TIMEOUT):

[source,ruby]

Pygments.highlight('code', timeout: 4)

== Benchmarks


$ ruby bench.rb 50 Benchmarking.... Size: 698 bytes Iterations: 50 user system total real pygments popen 0.010000 0.010000 0.020000 ( 0.460370) pygments popen (process already started) 0.010000 0.000000 0.010000 ( 0.272975) pygments popen (process already started 2) 0.000000 0.000000 0.000000 ( 0.273589)


$ ruby bench.rb 10 Benchmarking.... Size: 15523 bytes Iterations: 10 user system total real pygments popen 0.000000 0.000000 0.000000 ( 0.819419) pygments popen (process already started) 0.010000 0.000000 0.010000 ( 0.676515) pygments popen (process already started 2) 0.000000 0.010000 0.010000 ( 0.674189)

== Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake test to run the tests.

== Copyright

Copyright (C) Ted Nyman, Aman Gupta, Marat Radchenko, 2012-2021. Free use of this software is granted under the terms of the MIT License.

For the full text of the license, see the link:LICENSE[] file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].