Class: GptTranslate::Plain::Strip
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- GptTranslate::Plain::Strip
- Defined in:
- lib/jekyll-chatgpt-translate/plain.rb
Overview
Markdown to pain text. Motivated by github.com/vmg/redcarpet/blob/master/lib/redcarpet/render_strip.rb
Instance Method Summary collapse
- #block_code(code, _lang) ⇒ Object
- #block_html(html) ⇒ Object
- #block_quote(txt) ⇒ Object
- #codespan(content) ⇒ Object
- #double_emphasis(txt) ⇒ Object
- #emphasis(txt) ⇒ Object
- #header(text, level) ⇒ Object
- #image(link, title, alt) ⇒ Object
- #link(link, _title, content) ⇒ Object
- #list(content, _type) ⇒ Object
- #list_item(content, type) ⇒ Object
- #paragraph(text) ⇒ Object
- #raw_html(html) ⇒ Object
Instance Method Details
#block_code(code, _lang) ⇒ Object
75 76 77 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 75 def block_code(code, _lang) code end |
#block_html(html) ⇒ Object
105 106 107 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 105 def block_html(html) "#{html}\n" end |
#block_quote(txt) ⇒ Object
79 80 81 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 79 def block_quote(txt) "> #{txt}" end |
#codespan(content) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 91 def codespan(content) if content.start_with?("\n") "```#{content}```" elsif content.end_with?("\n") "```\n#{content.split("\n", 2)[1]}```" else "`#{content}`" end end |
#double_emphasis(txt) ⇒ Object
71 72 73 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 71 def double_emphasis(txt) "**#{txt}**" end |
#emphasis(txt) ⇒ Object
83 84 85 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 83 def emphasis(txt) "*#{txt}*" end |
#header(text, level) ⇒ Object
87 88 89 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 87 def header(text, level) "#{'#' * level} #{text}\n\n" end |
#image(link, title, alt) ⇒ Object
101 102 103 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 101 def image(link, title, alt) "![#{alt}](#{link} \"#{title}\")" end |
#link(link, _title, content) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 129 def link(link, _title, content) if !link.nil? && link.start_with?('/', 'https://', 'http://') "[#{content}](#{link})" else content end end |
#list(content, _type) ⇒ Object
113 114 115 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 113 def list(content, _type) content end |
#list_item(content, type) ⇒ Object
117 118 119 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 117 def list_item(content, type) "#{type == :ordered ? '1.' : '*'} #{content.strip}\n\n" end |
#paragraph(text) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 121 def paragraph(text) unless text.start_with?('```') text.gsub!(/\n+/, ' ') text.gsub!(/\s{2,}/, ' ') end "#{text}\n\n" end |
#raw_html(html) ⇒ Object
109 110 111 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 109 def raw_html(html) html end |