ZMediumToMarkdown 2.0.6 → 2.0.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: 64bc954d4d11fa995f0d5249e133523e97da81e38bfc009faf071daa86d888bc
4
- data.tar.gz: e8fc95d50ab0681f0fb31974b3aa3ca0ecc0ebe05515bf0c7635e8a4596742e8
3
+ metadata.gz: 411d9f653e728ad8708bfdd0738e181de68085865a3860e5d5272125236e856c
4
+ data.tar.gz: 94c713a02a605b480bf63e1022a4ee53dcfca3fe4355daf401b2253354f6f194
5
5
  SHA512:
6
- metadata.gz: 97ad008929638d94bc79abfe5a22162cd476688d53851759f44892d50349af7d43c3a6fae3c9e6c2454fe75d387223df24e92597ff4e3d63a97b11d5ec8c7d3e
7
- data.tar.gz: a3f9ce9bb64780c15fdf8d3e2402d0ce884ca184c1994024ec7b0867be472bd831d7ccd3ca2373540744b17b33c98221887a02691659d35ea9162443cb8093f5
6
+ metadata.gz: 1b90384c75f6de2b1fcaaac3fcc1f3885ec6bf223698ce677c7cd621eec479eabead53794eb66d7ce2367867ef187468c733473e1e42a711eadf360a249a5803
7
+ data.tar.gz: 89c9ec47b56b047042a060716f923ad1924722d17c842ccce954252976d8112cac0c3d610f7626caadd1a4eaada5031dea17ca26dea4349e2b8e9e2ca1431b1c
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
@@ -193,7 +193,7 @@ class MarkupStyleRender
193
193
  if !lastPath.nil?
194
194
  lastQuery = lastPath.split("-").last
195
195
  end
196
-
196
+
197
197
  if !usersPostURLs.nil? && !usersPostURLs.find { |usersPostURL| usersPostURL.split("/").last.split("-").last == lastQuery }.nil?
198
198
  if isForJekyll
199
199
  url = "(../#{lastQuery}/)"
@@ -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.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-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