Class: Downterm::Render::Terminal

Inherits:
Redcarpet::Render::Base
  • Object
show all
Defined in:
lib/downterm/render.rb

Instance Method Summary collapse

Instance Method Details



49
50
51
# File 'lib/downterm/render.rb', line 49

def autolink(link, link_type)
  Rainbow(link).underline.to_s
end

#block_code(code, language) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/downterm/render.rb', line 61

def block_code(code, language)
  block = code.split("\n")
              .map { |line| "    #{line}" }
              .map { |line| line.gsub(/>/, '>') }
              .map { |line| line.gsub(/&lt;/, '<') }
              .map { |line| line.gsub(/&amp;/, '&') }
              .join("\n")
  "#{block}\n\n"
end

#block_html(raw_html) ⇒ Object



75
76
77
# File 'lib/downterm/render.rb', line 75

def block_html(raw_html)
  raw_html
end

#block_quote(quote) ⇒ Object



71
72
73
# File 'lib/downterm/render.rb', line 71

def block_quote(quote)
  quote.split("\n").map { |line| "> #{line}" }.join("\n")
end

#codespan(code) ⇒ Object



57
58
59
# File 'lib/downterm/render.rb', line 57

def codespan(code)
  "`#{code}`"
end

#double_emphasis(text) ⇒ Object



37
38
39
# File 'lib/downterm/render.rb', line 37

def double_emphasis(text)
  Rainbow(text).bright.to_s
end

#emphasis(text) ⇒ Object



33
34
35
# File 'lib/downterm/render.rb', line 33

def emphasis(text)
  Rainbow(text).underline.to_s
end

#entity(text) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/downterm/render.rb', line 24

def entity(text)
  case text
  when "&gt;"  then return ">"
  when "&lt;"  then return "<"
  when "&amp;" then return "&"
  else              return text
  end
end

#header(text, header_level) ⇒ Object



20
21
22
# File 'lib/downterm/render.rb', line 20

def header(text, header_level)
  "#{Rainbow(text).bright}\n\n"
end

#hruleObject



109
110
111
# File 'lib/downterm/render.rb', line 109

def hrule
  '-' * Ttycaca::Terminal.new.width + "\n\n"
end

#image(link, title, content) ⇒ Object



53
54
55
# File 'lib/downterm/render.rb', line 53

def image(link, title, content)
  Rainbow(link).underline.to_s
end

#linebreakObject



16
17
18
# File 'lib/downterm/render.rb', line 16

def linebreak
  "\n"
end


45
46
47
# File 'lib/downterm/render.rb', line 45

def link(link, link_title, content)
  "#{Rainbow(content).underline} <#{link}>"
end

#list(contents, list_type) ⇒ Object



95
96
97
98
99
100
# File 'lib/downterm/render.rb', line 95

def list(contents, list_type)
  case list_type
  when :unordered then return contents + "\n"
  when :ordered   then return number_list(contents.split("\n")).join("\n") + "\n"
  end
end

#list_item(text, list_type) ⇒ Object



102
103
104
105
106
107
# File 'lib/downterm/render.rb', line 102

def list_item(text, list_type)
  case list_type
  when :unordered then return "* #{text}"
  when :ordered   then return "#{text}"
  end
end

#normal_text(text) ⇒ Object



12
13
14
# File 'lib/downterm/render.rb', line 12

def normal_text(text)
  text
end

#paragraph(text) ⇒ Object



8
9
10
# File 'lib/downterm/render.rb', line 8

def paragraph(text)
  "#{text}\n\n"
end

#postprocess(full_document) ⇒ Object



113
114
115
# File 'lib/downterm/render.rb', line 113

def postprocess(full_document)
  full_document.rstrip
end

#raw_html(raw_html) ⇒ Object



79
80
81
# File 'lib/downterm/render.rb', line 79

def raw_html(raw_html)
  raw_html
end

#strikethrough(text) ⇒ Object



83
84
85
# File 'lib/downterm/render.rb', line 83

def strikethrough(text)
  text
end

#superscript(text) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/downterm/render.rb', line 87

def superscript(text)
  if text.length > 1
    "^(#{text})"
  else
    "^#{text}"
  end
end

#triple_emphasis(text) ⇒ Object



41
42
43
# File 'lib/downterm/render.rb', line 41

def triple_emphasis(text)
  Rainbow(text).bright.underline.to_s
end