ZMediumToMarkdown 1.7.4 → 1.7.7

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: 9f0456e760bcd742867a97de33738cefa1f58fadd03a2bcb3ec8488bd82a043b
4
- data.tar.gz: ab014836dcc1216baed216ffc928a05eed8a368489284d1b13dfb9cb4156c8e8
3
+ metadata.gz: 6f34b1b96683e25673872ff046d9baaeda079d595d5163fbcf894e0fc3bf340c
4
+ data.tar.gz: e852a11256fe0789472182bb43d0cb9a15f75439676043703dc368e0a153e06a
5
5
  SHA512:
6
- metadata.gz: b6fc090b46f1b20de4298762cef0e8c71f5eecd9ee672db669ac6392d617c4e259668e199666be92d4514967210c1e3e6500d843467d3588b8de19dec0333488
7
- data.tar.gz: ea38435d80577a2c253b93f49aec296ea4e4b9eed2220b0f0b3695dfb1ba3bc1f6869ba35bb1b254bea47f2e350c42be30744a471814dadb011738efb8618aa9
6
+ metadata.gz: 7ba230c20dfd3f9638ed837f7a989de1c0fa0309db3865390d6b7616c6f2dcc0321c70acc49875128fb83225d8a892e51ffe7726d06c7311aae30830841d843d
7
+ data.tar.gz: f8936158de2a595047cf989f7fabaed2602aec4502f2e2480bef81659980f08ead77e0647a024d1eb4efb72cf4614448abada9d7cecec5741960a8aeb98f5048
@@ -48,14 +48,6 @@ class Main
48
48
  Helper.printNewVersionMessageIfExists()
49
49
  end
50
50
 
51
- opts.on('-cPOST_URL', '--jekyllPostURL=POST_URL', 'Downloading single post with Jekyll friendly') do |postURL|
52
- outputFilePath = PathPolicy.new(filePath, "/")
53
- fetcher.isForJekyll = true
54
- fetcher.downloadPost(postURL, outputFilePath)
55
-
56
- Helper.printNewVersionMessageIfExists()
57
- end
58
-
59
51
  opts.on('-n', '--new', 'Update to latest version') do
60
52
  if Helper.getRemoteVersionFromGithub() > Helper.getLocalVersion()
61
53
  Helper.downloadLatestVersion()
data/lib/Helper.rb CHANGED
@@ -11,6 +11,20 @@ require 'zip'
11
11
 
12
12
  class Helper
13
13
 
14
+ def self.escapeMarkdown(text)
15
+ text.gsub(/(\*|_|`|\||\\|\{|\}\[|\]|\(|\)|#|\+|\-|\.|\!)/){ |x| "\\#{x}" }
16
+ end
17
+
18
+ def self.escapeHTML(text)
19
+ if text == "<"
20
+ "&lt;"
21
+ elsif text == ">"
22
+ "&gt;"
23
+ else
24
+ text
25
+ end
26
+ end
27
+
14
28
  def self.createDirIfNotExist(dirPath)
15
29
  dirs = dirPath.split("/")
16
30
  currentDir = ""
@@ -1,5 +1,6 @@
1
1
  $lib = File.expand_path('../', File.dirname(__FILE__))
2
2
 
3
+ require 'Helper'
3
4
  require 'Parsers/PParser'
4
5
  require 'securerandom'
5
6
 
@@ -60,11 +61,13 @@ class Paragraph
60
61
  def initialize(json, postID)
61
62
  @name = json['name']
62
63
  @text = json['text']
63
- @orgText = json['text']
64
64
  @type = json['type']
65
65
  @href = json['href']
66
66
  @postID = postID
67
67
 
68
+ orgText = Helper.escapeMarkdown(json['text'])
69
+ @orgText = orgText
70
+
68
71
  if json['metadata'].nil?
69
72
  @metadata = nil
70
73
  else
@@ -24,20 +24,20 @@ class IMGParser < Parser
24
24
  absolutePath = imagePathPolicy.getAbsolutePath(fileName)
25
25
 
26
26
  result = ""
27
- comment = ""
28
- if paragraph.orgText != ""
29
- comment = " \"#{paragraph.orgText}\""
27
+ alt = ""
28
+ if paragraph.orgText != ""
29
+ alt = " \"#{paragraph.orgText}\""
30
30
  end
31
31
 
32
32
  if ImageDownloader.download(absolutePath, imageURL)
33
33
  relativePath = "#{pathPolicy.getRelativePath(nil)}/#{imagePathPolicy.getRelativePath(fileName)}"
34
34
  if isForJekyll
35
- result = "\r\n![#{paragraph.text}](/#{relativePath}#{comment})\r\n"
35
+ result = "\r\n![#{paragraph.orgText}](/#{relativePath}#{alt})\r\n"
36
36
  else
37
- result = "\r\n![#{paragraph.text}](#{relativePath}#{comment})\r\n"
37
+ result = "\r\n![#{paragraph.orgText}](#{relativePath}#{alt})\r\n"
38
38
  end
39
39
  else
40
- result = "\r\n![#{paragraph.text}](#{imageURL}#{comment})\r\n"
40
+ result = "\r\n![#{paragraph.orgText}](#{imageURL}#{alt})\r\n"
41
41
  end
42
42
 
43
43
  if paragraph.text != ""
@@ -7,16 +7,17 @@ require 'securerandom'
7
7
  require 'User'
8
8
 
9
9
  class MarkupParser
10
- attr_accessor :body, :paragraph
11
-
12
- def initialize(paragraph)
10
+ attr_accessor :body, :paragraph, :isForJekyll
11
+
12
+ def initialize(paragraph, isForJekyll)
13
13
  @paragraph = paragraph
14
+ @isForJekyll = isForJekyll
14
15
  end
15
16
 
16
17
  def parse()
17
18
  result = paragraph.text
18
19
  if !paragraph.markups.nil? && paragraph.markups.length > 0
19
- markupRender = MarkupStyleRender.new(paragraph)
20
+ markupRender = MarkupStyleRender.new(paragraph, isForJekyll)
20
21
 
21
22
  begin
22
23
  result = markupRender.parse()
@@ -2,9 +2,10 @@
2
2
  $lib = File.expand_path('../', File.dirname(__FILE__))
3
3
 
4
4
  require 'Models/Paragraph'
5
+ require 'Helper'
5
6
 
6
7
  class MarkupStyleRender
7
- attr_accessor :paragraph, :chars, :encodeType
8
+ attr_accessor :paragraph, :chars, :encodeType, :isForJekyll
8
9
 
9
10
  class TextChar
10
11
  attr_accessor :chars, :type
@@ -26,8 +27,9 @@ class MarkupStyleRender
26
27
  end
27
28
 
28
29
 
29
- def initialize(paragraph)
30
+ def initialize(paragraph, isForJekyll)
30
31
  @paragraph = paragraph
32
+ @isForJekyll = isForJekyll
31
33
 
32
34
  chars = {}
33
35
  index = 0
@@ -189,7 +191,12 @@ class MarkupStyleRender
189
191
  end
190
192
 
191
193
  if char.chars.join() != "\n"
192
- response.append(TextChar.new(char.chars, 'Text'))
194
+ resultChar = Helper.escapeMarkdown(char.chars.join())
195
+ if isForJekyll
196
+ resultChar = Helper.escapeHTML(resultChar)
197
+ end
198
+
199
+ response.append(TextChar.new(resultChar.chars, "Text"))
193
200
  end
194
201
 
195
202
  endTags = tags.select { |tag| tag.endIndex == index }
@@ -220,6 +227,20 @@ class MarkupStyleRender
220
227
  response.push(tag.endChars)
221
228
  end
222
229
 
230
+ response = optimize(response)
231
+ result = response.map{ |response| response.chars }.join()
232
+
233
+ else
234
+ response = []
235
+ chars.each do |index, char|
236
+ resultChar = escapeMarkdown(char)
237
+ if isForJekyll
238
+ resultChar = escapeHTML(char)
239
+ end
240
+
241
+ response.append(resultChar)
242
+ end
243
+
223
244
  response = optimize(response)
224
245
  result = response.map{ |response| response.chars }.join()
225
246
  end
@@ -186,7 +186,7 @@ class ZMediumFetcher
186
186
  groupByText += "\n"
187
187
  end
188
188
 
189
- markupParser = MarkupParser.new(preTypeParagraph)
189
+ markupParser = MarkupParser.new(preTypeParagraph, isForJekyll)
190
190
  groupByText += markupParser.parse()
191
191
  end
192
192
 
@@ -244,7 +244,7 @@ class ZMediumFetcher
244
244
  paragraphs.each do |paragraph|
245
245
 
246
246
  if !(CodeBlockParser.isCodeBlock(paragraph) || PREParser.isPRE(paragraph))
247
- markupParser = MarkupParser.new(paragraph)
247
+ markupParser = MarkupParser.new(paragraph, isForJekyll)
248
248
  paragraph.text = markupParser.parse()
249
249
  end
250
250
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-12 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri