ZMediumToMarkdown 2.0.8 → 2.0.11

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: 15f4bb468ab40811678a1a7b38dc51aa6e442b28a8da0b3835dce158f6d90fd4
4
- data.tar.gz: 67715feec8e9e7c9f798a61e61529e7846b2db42c86d0c8bd9dd43f3d2de971d
3
+ metadata.gz: 3605356973101df17419ca4232f870a0bab0062f04409c78b0a267c1b799a911
4
+ data.tar.gz: 10506a2d7f3a699059869ecc7e070c63939a361ccf13007308acb7596d73b130
5
5
  SHA512:
6
- metadata.gz: 84f8eece59e468fb75768af6ed756dd96812ea81d8c6e6ecaeabf2c090db5f5bea10c39e8fc8693720322681f5ec902966371d4a95476f6f30ac8ada0782702e
7
- data.tar.gz: 66c66d9b514fd8b0c81776e3dff2a466e91d291ebd9c466de8f6ca8ad19e7ba1d89aa154fa768e746194031805bf8722dbb8f0569b143e2700d04b550c0ce35f
6
+ metadata.gz: 950325be2b1088bef87a36ceffdabce9be5d9800a9ba5d47fbeb09f2d8ff90c2a01a827b7272af5ef4ac9285a06b4de86cea2ea03e81b0984aa2a49f78a269ff
7
+ data.tar.gz: 3a448256e99ad7eb6da7a28b89be0e6984430466b04b3d0eec25a9eed24026f6b29f90f25a226f487ce0639d49192fd41e0045b597d2ef1129f505fab67a65de
@@ -76,7 +76,7 @@ end
76
76
  begin
77
77
  puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
78
78
  puts "You have read and agree with the Disclaimer."
79
- #Main.new()
79
+ Main.new()
80
80
  puts "Execute Successfully!!!"
81
81
  puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
82
82
  puts "#Thanks for using this tool."
@@ -86,9 +86,4 @@ rescue => e
86
86
  puts e.backtrace
87
87
  puts "#Please feel free to open an Issue or submit a fix/contribution via Pull Request on:\n"
88
88
  puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown\n"
89
- end
90
-
91
- obj = JSON.parse('{ "id": "e41429008434_63", "name": "35a0", "type": "ULI", "href": null, "layout": null, "metadata": null, "text": "[New] Customer reviews", "hasDropCap": null, "dropCapImage": null, "markups": [ { "type": "A", "start": 6, "end": 22, "href": "https://developer.apple.com/documentation/appstoreconnectapi/app_store/customer_reviews", "anchorType": "LINK", "userId": null, "linkMetadata": null, "__typename": "Markup" }, { "type": "STRONG", "start": 0, "end": 6, "href": null, "anchorType": null, "userId": null, "linkMetadata": null, "__typename": "Markup" } ], "__typename": "Paragraph", "iframe": null, "mixtapeMetadata": null }')
92
- p = Paragraph.new(obj, "100")
93
- r = MarkupParser.new(p, false)
94
- puts r.parse()
89
+ end
@@ -48,6 +48,51 @@ class MarkupStyleRender
48
48
  end
49
49
 
50
50
  def optimize(chars)
51
+
52
+ # remove style in codeblock e.g. `hello world **bold**` (markdown not allow style in codeblock)
53
+
54
+ while true
55
+
56
+ hasExcute = false
57
+ inCodeBlock = false
58
+ index = 0
59
+
60
+ chars.each do |char|
61
+ if char.chars.join() == "`"
62
+ if char.type == "TagStart"
63
+ inCodeBlock = true
64
+ elsif char.type == "TagEnd"
65
+ inCodeBlock = false
66
+ end
67
+ elsif inCodeBlock
68
+ if char.type == "TagStart" or char.type == "TagEnd"
69
+ chars.delete_at(index)
70
+ hasExcute = true
71
+ break
72
+ end
73
+ end
74
+
75
+ index += 1
76
+ end
77
+
78
+ if !hasExcute
79
+ break
80
+ end
81
+ end
82
+
83
+ # treat escape tag as normal text
84
+ index = 0
85
+ chars.each do |char|
86
+ if char.type == "TagEnd" && char.chars.join() == ""
87
+ chars.delete_at(index)
88
+ elsif char.type == "TagStart" && char.chars.join() == "\\"
89
+ chars[index] = TextChar.new("\\".chars, "Text")
90
+ end
91
+
92
+ index += 1
93
+ end
94
+
95
+ # append space between tag and text
51
96
  while true
52
97
  hasExcute = false
53
98
 
@@ -126,37 +171,6 @@ class MarkupStyleRender
126
171
  end
127
172
  end
128
173
 
129
- # remove style in codeblock e.g. `hello world **bold**` (markdown not allow style in codeblock)
130
-
131
- while true
132
-
133
- hasExcute = false
134
- inCodeBlock = false
135
- index = 0
136
-
137
- chars.each do |char|
138
- if char.chars.join() == "`"
139
- if char.type == "TagStart"
140
- inCodeBlock = true
141
- elsif char.type == "TagEnd"
142
- inCodeBlock = false
143
- end
144
- elsif inCodeBlock
145
- if char.type == "TagStart" or char.type == "TagEnd"
146
- chars.delete_at(index)
147
- hasExcute = true
148
- break
149
- end
150
- end
151
-
152
- index += 1
153
- end
154
-
155
- if !hasExcute
156
- break
157
- end
158
- end
159
-
160
174
  chars
161
175
  end
162
176
 
@@ -175,11 +189,7 @@ class MarkupStyleRender
175
189
  elsif markup.type == "STRONG"
176
190
  tag = TagChar.new(2, markup.start, markup.end, "**", "**")
177
191
  elsif markup.type == "ESCAPE"
178
- escapeTagChar = TagChar.new(999,markup.start, markup.end,'','')
179
- escapeTagChar.startChars = TextChar.new('\\'.chars,'Text')
180
- escapeTagChar.endChars = TextChar.new([],'Text')
181
-
182
- tag = escapeTagChar
192
+ tag = TagChar.new(999, markup.start, markup.end, "\\", "")
183
193
  elsif markup.type == "A"
184
194
  url = markup.href
185
195
  if markup.anchorType == "LINK"
@@ -224,16 +234,6 @@ class MarkupStyleRender
224
234
  stack = []
225
235
 
226
236
  chars.each do |index, char|
227
-
228
- # is in code block
229
- if !stack.last.nil? && stack.last.endChars.chars.join() == "`"
230
- containEndTag = tags.select { |tag| tag.endIndex == index && tag.endChars.chars.join() == "`" }.length > 0
231
- if !containEndTag
232
- response.append(char)
233
- next
234
- end
235
- end
236
-
237
237
  if char.chars.join() == "\n"
238
238
  brStack = stack.dup
239
239
  while brStack.length > 0
@@ -250,19 +250,32 @@ class MarkupStyleRender
250
250
 
251
251
  startTags = tags.select { |tag| tag.startIndex == index }.sort_by(&:sort)
252
252
  if !startTags.nil?
253
+ hasCodeBlockTag = false
253
254
  startTags.each do |tag|
254
- response.append(tag.startChars)
255
+ if !hasCodeBlockTag
256
+ response.append(tag.startChars)
257
+ end
258
+
255
259
  stack.append(tag)
260
+
261
+ if tag.startChars.chars.join() == "`"
262
+ hasCodeBlockTag = true
263
+ end
256
264
  end
257
265
  end
258
266
 
259
267
  if char.chars.join() != "\n"
260
- resultChar = char.chars.join()
261
- if isForJekyll
262
- resultChar = Helper.escapeHTML(resultChar)
268
+ if !stack.select { |tag| tag.startChars.chars.join() == "`" }.nil?
269
+ # is in code block
270
+ response.append(char)
271
+ else
272
+ resultChar = Helper.escapeMarkdown(char.chars.join())
273
+ if isForJekyll
274
+ resultChar = Helper.escapeHTML(resultChar)
275
+ end
276
+
277
+ response.append(TextChar.new(resultChar.chars, "Text"))
263
278
  end
264
-
265
- response.append(TextChar.new(resultChar.chars, "Text"))
266
279
  end
267
280
 
268
281
  endTags = tags.select { |tag| tag.endIndex == index }
@@ -233,7 +233,7 @@ class ZMediumFetcher
233
233
  if lines.first.start_with?("---")
234
234
  dateLine = lines.select { |line| line.start_with?("last_modified_at:") }.first
235
235
  if !dateLine.nil?
236
- #fileLatestPublishedAt = Time.parse(dateLine[/^(last_modified_at:)\s+(\S*)/, 2]).to_i
236
+ fileLatestPublishedAt = Time.parse(dateLine[/^(last_modified_at:)\s+(\S*)/, 2]).to_i
237
237
  end
238
238
  end
239
239
  end
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: 2.0.8
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2022-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri