ZMediumToMarkdown 1.7.6 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8d93a8c503846adfc16a522538443ff0d7cccdac9f762e1820c6a126577ae01
4
- data.tar.gz: ea3da670c30cb61dd06035f8a39983ff6d2e54a45273d0cc0da547e85102f47c
3
+ metadata.gz: 6f34b1b96683e25673872ff046d9baaeda079d595d5163fbcf894e0fc3bf340c
4
+ data.tar.gz: e852a11256fe0789472182bb43d0cb9a15f75439676043703dc368e0a153e06a
5
5
  SHA512:
6
- metadata.gz: 855b53acb24236730b4812e48af9b4126efd925a154e72247a69a3fc8204f10f2ac8b1a7021a56b20eeef64e6b64d19822df9dd9f35a935ce7f238140f5ddbe2
7
- data.tar.gz: 3fb8201543caee6f2e6621492db112a951863f5c93b9f6a0f5ac7c592aebbcabfbfdbdbf5d57329d6bfafe3611ce84c2225ef78236248dd020b13efd952f2990
6
+ metadata.gz: 7ba230c20dfd3f9638ed837f7a989de1c0fa0309db3865390d6b7616c6f2dcc0321c70acc49875128fb83225d8a892e51ffe7726d06c7311aae30830841d843d
7
+ data.tar.gz: f8936158de2a595047cf989f7fabaed2602aec4502f2e2480bef81659980f08ead77e0647a024d1eb4efb72cf4614448abada9d7cecec5741960a8aeb98f5048
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
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.6
4
+ version: 1.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi