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, theme) ⇒ 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, theme )
  in_code = false
  lines = text.split( "\n" ).map do |line|
    if line.start_with?( '```' )
      in_code = !in_code
      next theme.muted( line )
    end
    next theme.muted( line ) if in_code
    next theme.heading( line.sub( /^#\s*/, '' ) ) if line.start_with?( '# ' )
    next theme.subheading( line.sub( /^##\s*/, '' ) ) if line.start_with?( '## ' )
    next theme.subheading( line ) if line.start_with?( '### ' ) || line.start_with?( '#### ' )
    next theme.muted( line ) if line =~ /\A-{3,}\z/

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