Class: Gloo::Docs::MarkdownRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/docs/markdown_renderer.rb

Class Method Summary collapse

Class Method Details

.colorize(text) ⇒ Object

Colorize the given markdown text for terminal display.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gloo/docs/markdown_renderer.rb', line 19

def self.colorize( text )
  in_code = false
  lines = text.split( "\n" ).map do |line|
    if line.start_with?( '```' )
      in_code = !in_code
      next line.light_black
    end
    next line.light_black if in_code
    next line.sub( /^#\s*/, '' ).blue.bold if line.start_with?( '# ' )
    next line.sub( /^##\s*/, '' ).cyan.bold if line.start_with?( '## ' )
    next line.cyan if line.start_with?( '### ' ) || line.start_with?( '#### ' )
    next line.light_black if line =~ /\A-{3,}\z/

    line
  end
  return lines.join( "\n" )
end