jekyll-chatgpt-translate 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0104da23aeb28e61fb3c2eb4599684accff5945175001b86a49cc821f5e49be6
4
- data.tar.gz: 05a05b676a664ec01567f15c49c24bbc2809bd3aeb4dd11666eeea123ec19a7e
3
+ metadata.gz: f3a1fa14a50caf08c780825e889b16c100e4afcd4042db089e49b33d01eece4a
4
+ data.tar.gz: 87cf1124880695e6efad136115b7dfd9e33a629e03f154adc5f7325f7f6e43e9
5
5
  SHA512:
6
- metadata.gz: f9e400ffbf49216617b0a10cf6600a8786c891dbb73d950da2bdd363acf2c67e1d8e3e86c119a26be56aaed2226bd3b64d1dfb136c7b9272ac4e993ec7c83e81
7
- data.tar.gz: 1b4d7a1da595f9bf4829b739d786268c66bac31d9b3b42d9cd9a422bcb1b626af9aa54eeb0088be7e33c2fe39aaa787e972d6c136df20769e55f39f290d6285d
6
+ metadata.gz: fb6b987ce7934d9294ba69f73d4d23bb3c74d6394cc5537ed956ee0b54b280f0ae79e5d12c9974ef75402f0586422700727d02304e44c4d7f5c74090c7b7c03c
7
+ data.tar.gz: 597a0397823b9d91a65ce1b8269f3117f37152b2ab9c8eafd501a9c4c0aaeec9ecd70022460616c2ae8c212605fb2fd1df347ab07b9accc5323e5931d7cfd037
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
29
29
  s.required_ruby_version = '>= 2.6'
30
30
  s.name = 'jekyll-chatgpt-translate'
31
- s.version = '0.0.15'
31
+ s.version = '0.0.16'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -52,7 +52,7 @@ class GptTranslate::ChatGPT
52
52
  if par.length <= 32
53
53
  Jekyll.logger.debug("Not translating this, b/c too short: \"#{par}\"")
54
54
  par
55
- elsif par !~ /^[a-zA-Zа-яА-Я]/
55
+ elsif par !~ /^[[:alpha:]]/
56
56
  Jekyll.logger.debug("Not translating this, b/c it's not a plain text: \"#{par}\"")
57
57
  par
58
58
  elsif @key.empty?
@@ -40,36 +40,26 @@ class GptTranslate::Plain
40
40
  def to_s
41
41
  # To turn compact lists into proper lists
42
42
  @markdown.gsub(/([^\n])\n(\s*\*)/, "\\1\n\n\\2").split(/\n{2,}/).compact.map do |par|
43
- par.gsub!("\t", ' ')
44
- par.gsub!(/\n+/, ' ')
45
- par.gsub!(/ {2,}/, ' ')
43
+ par.strip!
46
44
  # Liquid tags are removed, but this implementation is primitive
47
45
  # Seehttps://stackoverflow.com/questions/
48
46
  par.gsub!(/{{[^}]+}}/, '')
49
47
  par.gsub!(/{%.+?%}/, '')
50
48
  par.gsub!(/<!--.+?-->/m, '')
51
- par.strip!
52
- Redcarpet::Markdown.new(Strip).render(par)
49
+ par = Redcarpet::Markdown.new(Strip).render(par)
50
+ par.gsub!("\t", ' ')
51
+ par.gsub!(/\n+/, ' ') unless par.start_with?('```')
52
+ par.gsub!(/ {2,}/, ' ') unless par.start_with?('```')
53
+ par.strip
53
54
  end.join("\n\n").gsub(/\n{2,}/, "\n\n").strip
54
55
  end
55
56
 
56
- # # To ignore/remove Liquid tags.
57
- # class NullDrop < Liquid::Drop
58
- # def method_missing(*)
59
- # nil
60
- # end
61
-
62
- # def respond_to_missing?(*)
63
- # true
64
- # end
65
- # end
66
-
67
57
  # Markdown to pain text.
68
58
  class Strip < Redcarpet::Render::Base
69
59
  %i[
70
60
  block_code block_quote
71
61
  block_html
72
- autolink codespan double_emphasis
62
+ autolink double_emphasis
73
63
  emphasis underline
74
64
  triple_emphasis strikethrough
75
65
  superscript highlight quote
@@ -81,8 +71,16 @@ class GptTranslate::Plain
81
71
  end
82
72
  end
83
73
 
84
- def raw_html(_content)
85
- 'HTML'
74
+ def codespan(content)
75
+ if content.start_with?("\n")
76
+ "```#{content}```"
77
+ else
78
+ content
79
+ end
80
+ end
81
+
82
+ def raw_html(content)
83
+ content
86
84
  end
87
85
 
88
86
  def list(content, _type)
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.15'
26
+ VERSION = '0.0.16'
27
27
  end
data/test/test_plain.rb CHANGED
@@ -78,17 +78,24 @@ class GptTranslate::PlainTest < Minitest::Test
78
78
 
79
79
  def test_code_block
80
80
  assert_equal(
81
- "Hello:\n\nJava",
81
+ "Hello:\n\n```\nJava\n```",
82
82
  GptTranslate::Plain.new("Hello:\n\n```\nJava\n```\n").to_s
83
83
  )
84
84
  end
85
85
 
86
86
  def test_html
87
87
  assert_equal(
88
- 'This is picture: HTML!',
88
+ 'This is picture: <img src="a"/>!',
89
89
  GptTranslate::Plain.new('This is picture: <img src="a"/>!').to_s
90
90
  )
91
- assert_equal('HTML', GptTranslate::Plain.new('<img src="a"/>').to_s)
91
+ assert_equal('<img src="a"/>', GptTranslate::Plain.new('<img src="a"/>').to_s)
92
+ end
93
+
94
+ def test_big_code
95
+ assert_equal(
96
+ "```\nHello\n```",
97
+ GptTranslate::Plain.new("```\nHello\n```").to_s
98
+ )
92
99
  end
93
100
 
94
101
  def test_liquid_tags
@@ -97,7 +104,7 @@ class GptTranslate::PlainTest < Minitest::Test
97
104
  GptTranslate::Plain.new('Hello, {{ Java }}!').to_s
98
105
  )
99
106
  assert_equal(
100
- 'Hello, dude !',
107
+ 'Hello, dude !',
101
108
  GptTranslate::Plain.new('Hello, {% if a %} dude {% endif %}!').to_s
102
109
  )
103
110
  assert_equal(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko