ZMediumToMarkdown 1.9.2 → 1.9.5

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: 1d7cb2d26657c6eaa7fe4bf2bb81d5800ccce3d8403dd2324127d0468da52a84
4
- data.tar.gz: 93c138a38d80cb1e141fa73840fe31e91cce89b05616ebc7867a5e59c6be62f9
3
+ metadata.gz: d96b986a3f8f82236b20c8db706b3a6b4451b5822ab4c940e855ee6e819a0087
4
+ data.tar.gz: 6cb9b1e76ba0486d4f96394c9153850185ddd9397f5b99ce29d896ad2f638e42
5
5
  SHA512:
6
- metadata.gz: d5d434403f7c4342f7f74c9a50b82d35767e0c4b9a13f92689e042eceaf432878b76781abc2f5986601eddf9916ca663eb42181be852743950b91b96c7fcaf00
7
- data.tar.gz: b4a525b9cc5f482272b601c06cecfe641cc8c7f93affaa330cbe35f1002c226e474c40befe4b67ffc1d67af7ffea897b8fd4d0c7a7843d61d1e836cfb5107455
6
+ metadata.gz: bdfdfc9d261bfc62114b799b657af0635f8c72415c040cd08934fd0fd84c7bcf73855f3204f5c6ce9248245d95e159ce4fda715f2460167f57ba53169d3b7f90
7
+ data.tar.gz: e7555c35a30e63794f00be2503d345d44ea90d432da99ed2769fb6b348825eec4663ee74ccc21831d218ac26501268a3dbfb1cf70800c0839699cd8e280fdc18
@@ -32,12 +32,12 @@ class IMGParser < Parser
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.orgTextWithEscape}](/#{relativePath}#{alt})\r\n"
35
+ result = "\r\n\r\n![#{paragraph.orgTextWithEscape}](/#{relativePath}#{alt})\r\n\r\n"
36
36
  else
37
- result = "\r\n![#{paragraph.orgTextWithEscape}](#{relativePath}#{alt})\r\n"
37
+ result = "\r\n\r\n![#{paragraph.orgTextWithEscape}](#{relativePath}#{alt})\r\n\r\n"
38
38
  end
39
39
  else
40
- result = "\r\n![#{paragraph.orgTextWithEscape}](#{imageURL}#{alt})\r\n"
40
+ result = "\r\n\r\n![#{paragraph.orgTextWithEscape}](#{imageURL}#{alt})\r\n\r\n"
41
41
  end
42
42
 
43
43
  if paragraph.text != ""
@@ -6,7 +6,7 @@ require "Request"
6
6
  require "Parsers/Parser"
7
7
  require 'Models/Paragraph'
8
8
  require 'nokogiri'
9
-
9
+ require 'Helper'
10
10
  require 'ImageDownloader'
11
11
  require 'PathPolicy'
12
12
 
@@ -19,12 +19,15 @@ class IframeParser < Parser
19
19
 
20
20
  def parse(paragraph)
21
21
  if paragraph.type == 'IFRAME'
22
+
22
23
  if !paragraph.iframe.src.nil? && paragraph.iframe.src != ""
23
24
  url = paragraph.iframe.src
24
25
  else
25
26
  url = "https://medium.com/media/#{paragraph.iframe.id}"
26
27
  end
27
28
 
29
+ result = "[#{paragraph.iframe.title}](#{url})"
30
+
28
31
  if !url[/(www\.youtube\.com)/].nil?
29
32
  # is youtube
30
33
  youtubeURL = URI(URI.decode(url)).query
@@ -38,12 +41,16 @@ class IframeParser < Parser
38
41
  imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), paragraph.postID)
39
42
  absolutePath = imagePathPolicy.getAbsolutePath(fileName)
40
43
  title = paragraph.iframe.title
44
+ if title.nil? or title == ""
45
+ title = "Youtube"
46
+ end
47
+
41
48
  if ImageDownloader.download(absolutePath, imageURL)
42
49
  relativePath = "#{pathPolicy.getRelativePath(nil)}/#{imagePathPolicy.getRelativePath(fileName)}"
43
50
  if isForJekyll
44
- result = "\r\n[![#{title}](/#{relativePath} \"#{title}\")](#{params["url"]})\r\n"
51
+ result = "\r\n\r\n[![#{title}](/#{relativePath} \"#{title}\")](#{params["url"]})\r\n\r\n"
45
52
  else
46
- result = "\r\n[![#{title}](#{relativePath} \"#{title}\")](#{params["url"]})\r\n"
53
+ result = "\r\n\r\n[![#{title}](#{relativePath} \"#{title}\")](#{params["url"]})\r\n\r\n"
47
54
  end
48
55
  else
49
56
  result = "\r\n[#{title}](#{params["url"]})\r\n"
@@ -71,18 +78,29 @@ class IframeParser < Parser
71
78
  end
72
79
  end
73
80
  else
74
- ogImageURL = Helper.fetchOGImage(url)
81
+ ogURL = url
82
+ if !url[/(cdn\.embedly\.com)/].nil?
83
+ params = URI::decode_www_form(URI(URI.decode(url)).query).to_h
84
+ if !params["url"].nil?
85
+ ogURL = params["url"]
86
+ end
87
+ end
88
+ ogImageURL = Helper.fetchOGImage(ogURL)
89
+
90
+ title = paragraph.iframe.title
91
+ if title.nil? or title == ""
92
+ title = Helper.escapeMarkdown(ogURL)
93
+ end
94
+
75
95
  if !ogImageURL.nil?
76
- result = "\r\n[![#{paragraph.iframe.title}](#{ogImageURL} \"#{paragraph.iframe.title}\")](#{url})\r\n"
96
+ result = "\r\n\r\n[![#{title}](#{ogImageURL} \"#{title}\")](#{ogURL})\r\n\r\n"
97
+ else
98
+ result = "[#{title}](#{ogURL})"
77
99
  end
78
100
  end
79
101
  end
80
102
 
81
- if result.nil?
82
- "[#{paragraph.iframe.title}](#{url})"
83
- else
84
- result
85
- end
103
+ result
86
104
  else
87
105
  if !nextParser.nil?
88
106
  nextParser.parse(paragraph)
@@ -5,9 +5,9 @@ require 'Models/Paragraph'
5
5
  class LinkParser
6
6
  attr_accessor :usersPostURLs, :isForJekyll
7
7
 
8
- def initialize(usersPostURLs, isForJekyll)
9
- @usersPostURLs = usersPostURLs
10
- @isForJekyll = isForJekyll
8
+ def initialize()
9
+ @usersPostURLs = nil
10
+ @isForJekyll = false
11
11
  end
12
12
 
13
13
  def parse(markdownString, markupLinks)
@@ -17,6 +17,13 @@ class LinkParser
17
17
 
18
18
  matchLinks.each do |matchLink|
19
19
  link = matchLink[0]
20
+ linkMarkdown = "(#{link})"
21
+ newLinkMarkdown = linkMarkdown
22
+
23
+ if isForJekyll
24
+ newLinkMarkdown = "(#{link}){:target=\"_blank\"}"
25
+ end
26
+
20
27
 
21
28
  if !usersPostURLs.nil?
22
29
  # if have provide user's post urls
@@ -30,12 +37,16 @@ class LinkParser
30
37
 
31
38
  if !usersPostURLs.find { |usersPostURL| usersPostURL.split("/").last.split("-").last == postPath.split("-").last }.nil?
32
39
  if isForJekyll
33
- markdownString = markdownString.sub! link, "../#{postPath}"
40
+ newLinkMarkdown = "(../#{postPath})"
34
41
  else
35
- markdownString = markdownString.sub! link, "#{postPath}"
42
+ newLinkMarkdown = "(#{postPath})"
36
43
  end
37
44
  end
38
45
  end
46
+
47
+ if linkMarkdown != newLinkMarkdown
48
+ markdownString = markdownString.sub! linkMarkdown, newLinkMarkdown
49
+ end
39
50
  end
40
51
  end
41
52
  end
@@ -11,7 +11,7 @@ class MIXTAPEEMBEDParser < Parser
11
11
  if !paragraph.mixtapeMetadata.nil? && !paragraph.mixtapeMetadata.href.nil?
12
12
  ogImageURL = Helper.fetchOGImage(paragraph.mixtapeMetadata.href)
13
13
  if !ogImageURL.nil?
14
- "\r\n[![#{paragraph.orgTextWithEscape}](#{ogImageURL} \"#{paragraph.orgTextWithEscape}\")](#{paragraph.mixtapeMetadata.href})\r\n"
14
+ "\r\n\r\n[![#{paragraph.orgTextWithEscape}](#{ogImageURL} \"#{paragraph.orgTextWithEscape}\")](#{paragraph.mixtapeMetadata.href})\r\n\r\n"
15
15
  else
16
16
  "\n[#{paragraph.orgTextWithEscape}](#{paragraph.mixtapeMetadata.href})"
17
17
  end
@@ -4,7 +4,7 @@ require "Parsers/Parser"
4
4
  require 'Models/Paragraph'
5
5
 
6
6
  class OLIParser < Parser
7
- attr_accessor :nextParser, :oliIndex
7
+ attr_accessor :nextParser
8
8
 
9
9
  def self.isOLI(paragraph)
10
10
  if paragraph.nil?
@@ -16,7 +16,7 @@ class OLIParser < Parser
16
16
 
17
17
  def parse(paragraph)
18
18
  if OLIParser.isOLI(paragraph)
19
- "#{oliIndex}. #{paragraph.text}"
19
+ "#{paragraph.oliIndex}. #{paragraph.text}"
20
20
  else
21
21
  if !nextParser.nil?
22
22
  nextParser.parse(paragraph)
@@ -71,7 +71,7 @@ class ZMediumFetcher
71
71
 
72
72
  def initialize
73
73
  @progress = Progress.new()
74
- @linkParser = LinkParser.new(nil, false)
74
+ @linkParser = LinkParser.new()
75
75
  @isForJekyll = false
76
76
  end
77
77
 
@@ -223,6 +223,8 @@ class ZMediumFetcher
223
223
  progress.message = "Converting Post..."
224
224
  progress.printLog()
225
225
 
226
+ linkParser.isForJekyll = isForJekyll
227
+
226
228
  postWithDatePath = "#{postInfo.firstPublishedAt.strftime("%Y-%m-%d")}-#{postPath}"
227
229
 
228
230
  absolutePath = postPathPolicy.getAbsolutePath("#{postWithDatePath}.md")
@@ -248,10 +250,7 @@ class ZMediumFetcher
248
250
  end
249
251
 
250
252
  result = startParser.parse(paragraph)
251
-
252
- if !linkParser.nil?
253
- result = linkParser.parse(result, paragraph.markupLinks)
254
- end
253
+ result = linkParser.parse(result, paragraph.markupLinks)
255
254
 
256
255
  file.puts(result)
257
256
 
@@ -295,7 +294,7 @@ class ZMediumFetcher
295
294
  nextID = postPageInfo["nextID"]
296
295
  end while !nextID.nil?
297
296
 
298
- @linkParser = LinkParser.new(postURLS, isForJekyll)
297
+ linkParser.usersPostURLs = postURLS
299
298
 
300
299
  progress.totalPostsLength = postURLS.length
301
300
  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: 1.9.2
4
+ version: 1.9.5
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-20 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri