Class: GptTranslate::Plain
- Inherits:
-
Object
- Object
- GptTranslate::Plain
- Defined in:
- lib/jekyll-chatgpt-translate/plain.rb
Overview
Markdown to plain text.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2023-2024 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Classes: Strip
Instance Method Summary collapse
-
#initialize(markdown) ⇒ Plain
constructor
Ctor.
-
#to_s ⇒ Object
Liquid tags are removed, but this implementation is primitive Seestackoverflow.com/questions/.
Constructor Details
#initialize(markdown) ⇒ Plain
Ctor.
36 37 38 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 36 def initialize(markdown) @markdown = markdown end |
Instance Method Details
#to_s ⇒ Object
Liquid tags are removed, but this implementation is primitive Seestackoverflow.com/questions/
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-chatgpt-translate/plain.rb', line 42 def to_s Redcarpet::Markdown.new(Strip).render( @markdown .gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2") # condensed list into item-per-par .gsub(/<!--.+?-->/m, '') .gsub(/{{[^}]+}}/, '') .gsub(/{%.+?%}/, '') .gsub(/^\{.+?\}\n/, '') .gsub(/\n\{.+?\}$/, '') ).strip end |