Created
November 14, 2017 13:50
-
-
Save arika/232cf91ec8a1328f5283255b096d236b to your computer and use it in GitHub Desktop.
RI Rouge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Author
arika
commented
Nov 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment