Class: GptTranslate::Pars
- Inherits:
-
Object
- Object
- GptTranslate::Pars
- Defined in:
- lib/jekyll-chatgpt-translate/pars.rb
Overview
Markdown broken down ito pars.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2023-2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(markdown) ⇒ Pars
constructor
Ctor.
-
#to_a ⇒ Object
Returns an array of strings.
Constructor Details
#initialize(markdown) ⇒ Pars
Ctor. markdown
The markdown
35 36 37 |
# File 'lib/jekyll-chatgpt-translate/pars.rb', line 35 def initialize(markdown) @markdown = markdown end |
Instance Method Details
#to_a ⇒ Object
Returns an array of strings
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll-chatgpt-translate/pars.rb', line 40 def to_a pars = [] inside = false @markdown.strip.split(/\n{2,}/).compact.each do |par| if inside pars[pars.size - 1] = "#{pars[pars.size - 1]}\n\n#{par}" else pars << par end inside = true if par.start_with?('```') && !inside inside = false if par.end_with?('```') && inside end pars end |