[PYTHON] Use Pygments.rb

Useful when you want to highlight the syntax. It seems that it is connected to Python's pygments with FFI. You can be crazy.

Install python

Put your own handy tools. Detailed in this article. When you put it in homebrew, various executable files such as ʻeasy_install are placed in the mysterious directory (/ usr / local / share / python), so put a symbolic link etc. or mess with $ PATH` ..

Install Pygments

setup


pip install pygments
ln -s /usr/local/share/python/pygmentize /usr/local/bin/pygmentize

let's try it

kaiseki.rb


require 'pygments'

Pygments.start '/usr/local/bin/pygmentize'

code = File.read '/Users/udzura/.rvm/gems/ruby-1.9.3-p194@samples/gems/sinatra-1.3.3/lib/sinatra/base.rb'
puts Pygments.highlight code, lexer: 'ruby', formatter: 'terminal'

http://gyazo.udzura.jp/ad1d5ced39ece3d296eef4ebd6b51e5a.png

bonus

The ruby gem called pry-coolline seems to implement a parser by myself [Yabaso](https://github.com/pry/pry-coolline/blob/master/lib/pry-coolline/paren_match .rb).

Mention

In When coloring code blocks with Ruby, I said "sometimes it becomes a segmentation fault", but I get the impression that it falls so much. I didn't receive it. The version may be up and stable. I don't know how much "if you prepare the python environment properly" is like ...

Recommended Posts

Use Pygments.rb
Use DeepLabCut
Use pycscope
Use collections.Counter
Use: Django-MySQL
Use Numpy
use pandas-ply
Use GitPython
Use Miniconda
Use Invariant TSC
Why use linux
Let's use pytube
Use JIRA API
Use weak references
Use combinatorial optimization
use go module