class Downterm::Render::Terminal
Public Instance Methods
autolink(link, link_type)
click to toggle source
# File lib/downterm/render.rb, line 49 def autolink(link, link_type) Rainbow(link).underline.to_s end
block_code(code, language)
click to toggle source
# 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(/</, '<') } .map { |line| line.gsub(/&/, '&') } .join("\n") "#{block}\n\n" end
block_html(raw_html)
click to toggle source
# File lib/downterm/render.rb, line 76 def block_html(raw_html) raw_html end
block_quote(quote)
click to toggle source
# File lib/downterm/render.rb, line 71 def block_quote(quote) trailing = quote[quote.rstrip.length..-1] quote.split("\n").map { |line| " | #{line}" }.join("\n") + trailing end
codespan(code)
click to toggle source
# File lib/downterm/render.rb, line 57 def codespan(code) "`#{code}`" end
double_emphasis(text)
click to toggle source
# File lib/downterm/render.rb, line 37 def double_emphasis(text) Rainbow(text).bright.to_s end
emphasis(text)
click to toggle source
# File lib/downterm/render.rb, line 33 def emphasis(text) Rainbow(text).underline.to_s end
entity(text)
click to toggle source
# File lib/downterm/render.rb, line 24 def entity(text) case text when ">" then return ">" when "<" then return "<" when "&" then return "&" else return text end end
header(text, header_level)
click to toggle source
# File lib/downterm/render.rb, line 20 def header(text, header_level) "#{Rainbow(text).bright}\n\n" end
hrule()
click to toggle source
# File lib/downterm/render.rb, line 110 def hrule '-' * Ttycaca::Terminal.new.width + "\n\n" end
image(link, title, content)
click to toggle source
# File lib/downterm/render.rb, line 53 def image(link, title, content) Rainbow(link).underline.to_s end
linebreak()
click to toggle source
# File lib/downterm/render.rb, line 16 def linebreak "\n" end
link(link, link_title, content)
click to toggle source
# File lib/downterm/render.rb, line 45 def link(link, link_title, content) "#{Rainbow(content).underline} <#{link}>" end
list(contents, list_type)
click to toggle source
# File lib/downterm/render.rb, line 96 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)
click to toggle source
# File lib/downterm/render.rb, line 103 def list_item(text, list_type) case list_type when :unordered then return "* #{text}" when :ordered then return "#{text}" end end
normal_text(text)
click to toggle source
# File lib/downterm/render.rb, line 12 def normal_text(text) text end
paragraph(text)
click to toggle source
# File lib/downterm/render.rb, line 8 def paragraph(text) "#{text}\n\n" end
postprocess(full_document)
click to toggle source
# File lib/downterm/render.rb, line 114 def postprocess(full_document) full_document.rstrip end
raw_html(raw_html)
click to toggle source
# File lib/downterm/render.rb, line 80 def raw_html(raw_html) raw_html end
strikethrough(text)
click to toggle source
# File lib/downterm/render.rb, line 84 def strikethrough(text) text end
superscript(text)
click to toggle source
# File lib/downterm/render.rb, line 88 def superscript(text) if text.length > 1 "^(#{text})" else "^#{text}" end end
triple_emphasis(text)
click to toggle source
# File lib/downterm/render.rb, line 41 def triple_emphasis(text) Rainbow(text).bright.underline.to_s end
Private Instance Methods
number_list(items)
click to toggle source
# File lib/downterm/render.rb, line 120 def number_list(items) width = items.count.to_s.length (1..items.count).zip(items).map { |e| sprintf("%*d. %s", width, e[0], e[1]) } end