ZMediumToMarkdown 2.0.6 → 2.0.9

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: 64bc954d4d11fa995f0d5249e133523e97da81e38bfc009faf071daa86d888bc
4
- data.tar.gz: e8fc95d50ab0681f0fb31974b3aa3ca0ecc0ebe05515bf0c7635e8a4596742e8
3
+ metadata.gz: 9c5da608d284269b0674c80fdd4fd6d93c825937a8eff28669993b623b5fa414
4
+ data.tar.gz: 17c83bf6c50f8e35b1defe2b4ac8c212d038ab148e174f863bfff370effeb927
5
5
  SHA512:
6
- metadata.gz: 97ad008929638d94bc79abfe5a22162cd476688d53851759f44892d50349af7d43c3a6fae3c9e6c2454fe75d387223df24e92597ff4e3d63a97b11d5ec8c7d3e
7
- data.tar.gz: a3f9ce9bb64780c15fdf8d3e2402d0ce884ca184c1994024ec7b0867be472bd831d7ccd3ca2373540744b17b33c98221887a02691659d35ea9162443cb8093f5
6
+ metadata.gz: 315bf2b11ce127d096dfa981c306f6882b8bcb0db975ccc7c36c5365b579b157bf9322649495410177cdad8894e3201aa1fadc392b6bd492cd490049b1c48e9e
7
+ data.tar.gz: c2455da2a611863c1735eadd0f3a02005804228fcdaa3b588b98c75fcf80a362c609fbdaea684eb085559cd32e679c6a59a250f3fb7e116bb4217957a6dfe230
data/lib/Helper.rb CHANGED
@@ -189,9 +189,14 @@ class Helper
189
189
  end
190
190
 
191
191
 
192
- def self.createWatermark(postURL)
192
+ def self.createWatermark(postURL, isForJekyll)
193
+ jekyllOpen = ""
194
+ if isForJekyll
195
+ jekyllOpen = "{:target=\"_blank\"}"
196
+ end
197
+
193
198
  text = "\r\n\r\n\r\n"
194
- text += "_Converted [Medium Post](#{postURL}) by [ZMediumToMarkdown](https://github.com/ZhgChgLi/ZMediumToMarkdown)._"
199
+ text += "_Converted [Medium Post](#{postURL})#{jekyllOpen} by [ZMediumToMarkdown](https://github.com/ZhgChgLi/ZMediumToMarkdown)#{jekyllOpen}._"
195
200
  text += "\r\n"
196
201
 
197
202
  text
@@ -96,14 +96,23 @@ class Paragraph
96
96
  end
97
97
  end
98
98
 
99
- i = 0
100
- while i = orgText.index(/(\*|_|`|\||\\|\{|\}|\[|\]|\(|\)|#|\+|\-|\.|\!)/, i + 1)
101
- escapeMarkup = {
102
- "type" => 'ESCAPE',
103
- "start" => i,
104
- "end" => i + 1
105
- }
106
- markups.append(Markup.new(escapeMarkup))
99
+ index = 0
100
+ orgText.each_char do |char|
101
+
102
+ if char.chars.join() =~ /(\*|_|`|\||\\|\{|\}|\[|\]|\(|\)|#|\+|\-|\.|\!)/
103
+ escapeMarkup = {
104
+ "type" => 'ESCAPE',
105
+ "start" => index,
106
+ "end" => index + 1
107
+ }
108
+ markups.append(Markup.new(escapeMarkup))
109
+ end
110
+
111
+ index += 1
112
+ if char.bytes.length >= 4
113
+ # some emoji need more space (in Medium)
114
+ index += 1
115
+ end
107
116
  end
108
117
 
109
118
  @markups = markups
@@ -171,11 +171,11 @@ class MarkupStyleRender
171
171
  if markup.type == "EM"
172
172
  tag = TagChar.new(2, markup.start, markup.end, "_", "_")
173
173
  elsif markup.type == "CODE"
174
- tag = TagChar.new(3, markup.start, markup.end, "`", "`")
174
+ tag = TagChar.new(0, markup.start, markup.end, "`", "`")
175
175
  elsif markup.type == "STRONG"
176
176
  tag = TagChar.new(2, markup.start, markup.end, "**", "**")
177
177
  elsif markup.type == "ESCAPE"
178
- escapeTagChar = TagChar.new(0,markup.start, markup.end,'','')
178
+ escapeTagChar = TagChar.new(999,markup.start, markup.end,'','')
179
179
  escapeTagChar.startChars = TextChar.new('\\'.chars,'Text')
180
180
  escapeTagChar.endChars = TextChar.new([],'Text')
181
181
 
@@ -271,7 +271,7 @@ class ZMediumFetcher
271
271
  progress.printLog()
272
272
  end
273
273
 
274
- postWatermark = Helper.createWatermark(postURL)
274
+ postWatermark = Helper.createWatermark(postURL, isForJekyll)
275
275
  if !postWatermark.nil?
276
276
  file.puts(postWatermark)
277
277
  end
@@ -308,7 +308,7 @@ class ZMediumFetcher
308
308
  nextID = postPageInfo["nextID"]
309
309
  end while !nextID.nil?
310
310
 
311
- usersPostURLs = postURLS
311
+ @usersPostURLs = postURLS
312
312
 
313
313
  progress.totalPostsLength = postURLS.length
314
314
  progress.currentPostIndex = 0
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.6
4
+ version: 2.0.9
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-20 00:00:00.000000000 Z
11
+ date: 2022-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -74,7 +74,6 @@ files:
74
74
  - lib/Parsers/H4Parser.rb
75
75
  - lib/Parsers/IMGParser.rb
76
76
  - lib/Parsers/IframeParser.rb
77
- - lib/Parsers/LinkParser.rb
78
77
  - lib/Parsers/MIXTAPEEMBEDParser.rb
79
78
  - lib/Parsers/MarkupParser.rb
80
79
  - lib/Parsers/MarkupStyleRender.rb
@@ -1,53 +0,0 @@
1
- $lib = File.expand_path('../', File.dirname(__FILE__))
2
-
3
- require 'Models/Paragraph'
4
-
5
- class LinkParser
6
- attr_accessor :usersPostURLs, :isForJekyll
7
-
8
- def initialize()
9
- @usersPostURLs = nil
10
- @isForJekyll = false
11
- end
12
-
13
- def parse(markdownString)
14
- matchLinks = markdownString.scan(/\[[^\[|!|\]]*\]\(([^\)]+)\)/m)
15
- if !matchLinks.nil?
16
- matchLinks.each do |matchLink|
17
- link = matchLink[0]
18
- linkMarkdown = "(#{link})"
19
- newLinkMarkdown = linkMarkdown
20
-
21
- if isForJekyll
22
- newLinkMarkdown = "(#{link}){:target=\"_blank\"}"
23
- end
24
-
25
-
26
- if !usersPostURLs.nil?
27
- # if have provide user's post urls
28
- # find & replace medium url to local post url if matched
29
-
30
- if isForJekyll
31
- postPath = link.split("/").last.split("-").last
32
- else
33
- postPath = link.split("/").last
34
- end
35
-
36
- if !usersPostURLs.find { |usersPostURL| usersPostURL.split("/").last.split("-").last == postPath.split("-").last }.nil?
37
- if isForJekyll
38
- newLinkMarkdown = "(../#{postPath}/)"
39
- else
40
- newLinkMarkdown = "(#{postPath})"
41
- end
42
- end
43
- end
44
-
45
- if linkMarkdown != newLinkMarkdown
46
- markdownString = markdownString.sub! linkMarkdown, newLinkMarkdown
47
- end
48
- end
49
- end
50
-
51
- markdownString
52
- end
53
- end