Class: Downterm::Render::Terminal
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- Downterm::Render::Terminal
- Defined in:
- lib/downterm/render.rb
Instance Method Summary collapse
- #autolink(link, link_type) ⇒ Object
- #block_code(code, language) ⇒ Object
- #block_html(raw_html) ⇒ Object
- #block_quote(quote) ⇒ Object
- #codespan(code) ⇒ Object
- #double_emphasis(text) ⇒ Object
- #emphasis(text) ⇒ Object
- #entity(text) ⇒ Object
- #header(text, header_level) ⇒ Object
- #hrule ⇒ Object
- #image(link, title, content) ⇒ Object
- #linebreak ⇒ Object
- #link(link, link_title, content) ⇒ Object
- #list(contents, list_type) ⇒ Object
- #list_item(text, list_type) ⇒ Object
- #normal_text(text) ⇒ Object
- #paragraph(text) ⇒ Object
- #postprocess(full_document) ⇒ Object
- #raw_html(raw_html) ⇒ Object
- #strikethrough(text) ⇒ Object
- #superscript(text) ⇒ Object
- #triple_emphasis(text) ⇒ Object
Instance Method Details
#autolink(link, link_type) ⇒ Object
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(/</, '<') } .map { |line| line.gsub(/&/, '&') } .join("\n") "#{block}\n\n" end |
#block_html(raw_html) ⇒ Object
78 79 80 |
# File 'lib/downterm/render.rb', line 78 def block_html(raw_html) raw_html end |
#block_quote(quote) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/downterm/render.rb', line 71 def block_quote(quote) trimmed_quote = %Q{"#{quote.rstrip}"} trailing_whitespace = quote[quote.rstrip.length..-1] q = trimmed_quote.split("\n").map { |line| " #{line}" }.join("\n") "#{q}#{trailing_whitespace}" 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 ">" then return ">" when "<" then return "<" when "&" 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 |
#hrule ⇒ Object
112 113 114 |
# File 'lib/downterm/render.rb', line 112 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 |
#linebreak ⇒ Object
16 17 18 |
# File 'lib/downterm/render.rb', line 16 def linebreak "\n" end |
#link(link, link_title, content) ⇒ Object
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
98 99 100 101 102 103 |
# File 'lib/downterm/render.rb', line 98 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
105 106 107 108 109 110 |
# File 'lib/downterm/render.rb', line 105 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
116 117 118 |
# File 'lib/downterm/render.rb', line 116 def postprocess(full_document) full_document.rstrip end |
#raw_html(raw_html) ⇒ Object
82 83 84 |
# File 'lib/downterm/render.rb', line 82 def raw_html(raw_html) raw_html end |
#strikethrough(text) ⇒ Object
86 87 88 |
# File 'lib/downterm/render.rb', line 86 def strikethrough(text) text end |
#superscript(text) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/downterm/render.rb', line 90 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 |