Skip to content

Instantly share code, notes, and snippets.

@arika
Created November 14, 2017 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arika/232cf91ec8a1328f5283255b096d236b to your computer and use it in GitHub Desktop.
Save arika/232cf91ec8a1328f5283255b096d236b to your computer and use it in GitHub Desktop.
RI Rouge
# Usage:
#
# RUBYOPT='-r ./to_rouge' RI_ROUGE=monokai.sublime \
# ri --format=rouge Class.methods
require 'rdoc'
require 'rouge'
module RDoc
class Markup
class ToRouge < Markup::ToAnsi
def initialize(*)
super
theme = Rouge::Theme.find(ENV['RI_ROUGE'] || 'thankful_eyes').new
@rouge_lexer = Rouge::Lexer.find('ruby')
@rouge_formatter = Rouge::Formatters::Terminal256.new(theme)
end
def rougify(string)
@rouge_formatter.format(@rouge_lexer.lex(string))
end
def accept_verbatim(verbatim)
indent = ' ' * (@indent + 2)
verbatim.parts.each do |part|
@res << indent unless part == "\n"
@res << rougify(part)
end
@res << "\n" unless @res =~ /\n\z/
end
end
end
end
@arika
Copy link
Author

arika commented Nov 14, 2017

ri-rouge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment