Class: Redcarpet::Render::ColorDown

Inherits:
Base
  • Object
show all
Defined in:
lib/tty_markdown.rb

Constant Summary collapse

UNORDERED =
/unordered/
RUBY_LANG =
/ruby/
COLOR_OFF =
"\033[0m"
WHITE =
"\033[0;107m"
RED =
"\033[0;31m"
GREEN =
"\033[0;32m"
YELLOW =
"\033[0;33m"
L_GRAY =
"\033[0;37m"
CYAN =
"\033[0;36m"
BLUE_BG =
"\033[0;44m"
GRAY_BG =
"\033[0;100m"
ORANGE =
"\033[38;5;136m"
ROSE =
"\033[38;5;167m"
BOLD =
"\033[0;01m"
DIM =
"\033[0;02m"
UNDERSCORE =
"\033[0;04m"
BINK =
"\033[0;05m"

Instance Method Summary collapse

Instance Method Details

#block_code(text, lang = "") ⇒ Object

end



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tty_markdown.rb', line 56

def block_code(text, lang="")
  lang ||= lang.to_s
  result = "```#{lang}\n"
  if lang.match RUBY_LANG
    result << ColorCode::Ruby.new(text).colorize
  else
    result << ColorCode::Unknown.new(text).colorize
  end
  result << "```\n"
  result
end

#block_quote(text) ⇒ Object



102
103
104
105
# File 'lib/tty_markdown.rb', line 102

def block_quote(text)
  [ ROSE,      "> ", text.strip,
    COLOR_OFF, "\n" ].inject("") { |memo, v| memo << v.to_s }
end

#codespan(text) ⇒ Object



68
69
70
# File 'lib/tty_markdown.rb', line 68

def codespan(text)
  GRAY_BG + "`#{text}`" + COLOR_OFF
end

#emphasis(text) ⇒ Object



72
73
74
75
# File 'lib/tty_markdown.rb', line 72

def emphasis(text)
  [ BOLD, '*', text,
    '*',  COLOR_OFF ].inject("") { |memo, v| memo << v.to_s }
end

#header(text, header_level) ⇒ Object



77
78
79
80
81
82
# File 'lib/tty_markdown.rb', line 77

def header(text, header_level)
  heads = "".tap {|h| header_level.times {h << "#"} }
  heads << " "
  op = [ BLUE_BG,   "\n", heads, text,
    COLOR_OFF, "\n" ].inject("") { |memo, v| memo << v.to_s }
end

#hruleObject



107
108
109
# File 'lib/tty_markdown.rb', line 107

def hrule
  "\n----"
end

#list(text, type) ⇒ Object



84
85
86
87
88
# File 'lib/tty_markdown.rb', line 84

def list(text, type)
  text.lines.inject("") do |memo, line|
    memo << "  " + line
  end + "\n"
end

#list_item(text, type) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/tty_markdown.rb', line 90

def list_item(text, type)
  if type.match UNORDERED
    "#{ORANGE}- #{COLOR_OFF}" + text
  else
    text
  end
end

#paragraph(text) ⇒ Object



98
99
100
# File 'lib/tty_markdown.rb', line 98

def paragraph(text)
  "\n" + text + "\n"
end