class HTMLRenderer::ANSI
Public Instance Methods
anchor(name, title=nil, content=nil)
click to toggle source
# File lib/html-renderer/ansi.rb, line 75 def anchor(name, title=nil, content=nil) result = "Anchor: ##{name}" result << " (#{title})" if title result << "\n" result << "#{content}\n" if content result end
block_code(code, language)
click to toggle source
# File lib/html-renderer/ansi.rb, line 91 def block_code(code, language) code.bold.cyan + "\n" end
block_quote(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 95 def block_quote(text) indent paragraph(text) end
codespan(code)
click to toggle source
# File lib/html-renderer/ansi.rb, line 99 def codespan(code) code.cyan end
definition_list(defs)
click to toggle source
# File lib/html-renderer/ansi.rb, line 159 def definition_list(defs) defs.each do |dt, dd| puts "<15>#{dt}<7>:".colorize puts " #{dd}" puts end end
div(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 132 def div(text) "#{indented?(text) ? text : unwrap(text)}\n" end
double_emphasis(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 116 def double_emphasis(text) text.bold.green end
emphasis(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 120 def emphasis(text) text.green end
header(title, level, anchor=nil)
click to toggle source
# File lib/html-renderer/ansi.rb, line 103 def header(title, level, anchor=nil) bar = ("-"*(title.size+4)).grey title = case level when 1 then title.bold.yellow when 2 then title.bold.cyan when 3 then title.bold.blue else title.magenta end "#{bar}\n #{title}\n#{bar}\n\n" end
image(link, title, content)
click to toggle source
# File lib/html-renderer/ansi.rb, line 83 def image(link, title, content) link(link, nil, title) end
italic(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 87 def italic(text) text.yellow.bold end
linebreak()
click to toggle source
# File lib/html-renderer/ansi.rb, line 124 def linebreak "\n" end
link(link, title, content)
click to toggle source
# File lib/html-renderer/ansi.rb, line 61 def link(link, title, content) unless content&.[] /^Back / str = "" # str += "<15>#{content}</15>" if content str += content.white.bold if content if smash(link) != smash(content) # str += " <8>(</8><11>#{link}</11><8>)</8>" str += " #{"(".grey}#{link.cyan.bold}#{")".grey}" end str end end
list(content, list_type)
click to toggle source
# File lib/html-renderer/ansi.rb, line 136 def list(content, list_type) case list_type when :ordered @counter = 0 "#{content}\n" when :unordered "#{content}\n" end end
list_item(content, list_type)
click to toggle source
# File lib/html-renderer/ansi.rb, line 146 def list_item(content, list_type) case list_type when :ordered @counter ||= 0 @counter += 1 # " <8>#{@counter}.</8> #{content.strip}\n".colorize " #{@counter.to_s.grey}. #{content.strip}\n" when :unordered # " <8>*</8> #{content.strip}\n".colorize " #{"*".grey} #{content.strip}\n" end end
normal_text(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 49 def normal_text(text) text end
paragraph(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 128 def paragraph(text) div(text) + "\n" end
separator()
click to toggle source
# File lib/html-renderer/ansi.rb, line 176 def separator "_____________________________\n\n" end
superscript(content)
click to toggle source
# File lib/html-renderer/ansi.rb, line 57 def superscript(content) "^(#{content})" end
table(header, rows)
click to toggle source
# File lib/html-renderer/ansi.rb, line 167 def table(header, rows) if header table = Terminal::Table.new(headings: header, rows: rows) else table = Terminal::Table.new(rows: rows) end "#{table}\n\n" end
underline(content)
click to toggle source
# File lib/html-renderer/ansi.rb, line 53 def underline(content) content.magenta.bold end
Private Instance Methods
indent(text,amount=2)
click to toggle source
# File lib/html-renderer/ansi.rb, line 35 def indent(text,amount=2) text.lines.map{|line| " "*amount + line }.join end
indented?(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 25 def indented?(text) indent_sizes = text.lines.map{ |line| if line =~ /^(\s+)/ then $1 else '' end }.map(&:size) indent_sizes.all? {|dent| dent > 0 } end
smash(s)
click to toggle source
# File lib/html-renderer/ansi.rb, line 39 def smash(s) s&.downcase&.scan(/\w+/)&.join end
subscript(s)
click to toggle source
# File lib/html-renderer/ansi.rb, line 43 def subscript(s) "[#{s}]" end
unwrap(text)
click to toggle source
# File lib/html-renderer/ansi.rb, line 30 def unwrap(text) return text unless indented? text text.lines.to_a.map(&:strip).join ' ' end