ZMediumToMarkdown 1.9.3 → 1.9.6
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 +4 -4
- data/bin/ZMediumToMarkdown +0 -1
- data/lib/Parsers/CodeBlockParser.rb +16 -2
- data/lib/Parsers/IframeParser.rb +12 -1
- data/lib/Parsers/LinkParser.rb +16 -5
- data/lib/Parsers/PREParser.rb +14 -1
- data/lib/ZMediumFetcher.rb +7 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc5589c92b8dd859f91b98fe7c2f1073a39af102ee8ebce27f1351824ffcab7
|
4
|
+
data.tar.gz: b14f257296741edd700bf484c37da6b2e386ddfb96dffca540b60cea8c04fecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da41323a9b967724f758535d4ad8bb191cc1c015929b8af49e94851c7ff83b8a45d0ee8eb25298e2712b4acfbe1d3263cf4d327609cfc9f170e16cffadd347a9
|
7
|
+
data.tar.gz: c8a491d922669dd8ac947e658367fcbc093a007bda351ed9f7627213ad635c0d4246d36d09862ae597312147d4627f0314f12547df2c37d95a8bc400064c0897
|
data/bin/ZMediumToMarkdown
CHANGED
@@ -65,7 +65,6 @@ class Main
|
|
65
65
|
|
66
66
|
opts.on('-v', '--version', 'Print current ZMediumToMarkdown Version & Output Path') do
|
67
67
|
puts "Version:#{Helper.getLocalVersion().to_s}"
|
68
|
-
puts "Output Path:#{outputFilePath.getAbsolutePath(nil)}"
|
69
68
|
|
70
69
|
Helper.printNewVersionMessageIfExists()
|
71
70
|
end
|
@@ -4,7 +4,11 @@ require "Parsers/Parser"
|
|
4
4
|
require 'Models/Paragraph'
|
5
5
|
|
6
6
|
class CodeBlockParser < Parser
|
7
|
-
attr_accessor :nextParser
|
7
|
+
attr_accessor :nextParser, :isForJekyll
|
8
|
+
|
9
|
+
def initialize(isForJekyll)
|
10
|
+
@isForJekyll = isForJekyll
|
11
|
+
end
|
8
12
|
|
9
13
|
def self.getTypeString()
|
10
14
|
'CODE_BLOCK'
|
@@ -20,7 +24,17 @@ class CodeBlockParser < Parser
|
|
20
24
|
|
21
25
|
def parse(paragraph)
|
22
26
|
if CodeBlockParser.isCodeBlock(paragraph)
|
23
|
-
"```\n
|
27
|
+
result = "```\n"
|
28
|
+
if isForJekyll
|
29
|
+
result += "{% raw %}\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
result += paragraph.text
|
33
|
+
|
34
|
+
if isForJekyll
|
35
|
+
result += "\n{% endraw %}"
|
36
|
+
end
|
37
|
+
result += "\n```"
|
24
38
|
else
|
25
39
|
if !nextParser.nil?
|
26
40
|
nextParser.parse(paragraph)
|
data/lib/Parsers/IframeParser.rb
CHANGED
@@ -74,7 +74,18 @@ class IframeParser < Parser
|
|
74
74
|
gistHTML.search('a').each do |a|
|
75
75
|
if a.text == 'view raw'
|
76
76
|
gistRAW = Request.body(Request.URL(a['href']))
|
77
|
-
|
77
|
+
|
78
|
+
result = "```#{lang}\n"
|
79
|
+
if isForJekyll
|
80
|
+
result += "{% raw %}\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
result += gistRAW
|
84
|
+
|
85
|
+
if isForJekyll
|
86
|
+
result += "\n{% endraw %}"
|
87
|
+
end
|
88
|
+
result += "\n```"
|
78
89
|
end
|
79
90
|
end
|
80
91
|
else
|
data/lib/Parsers/LinkParser.rb
CHANGED
@@ -5,9 +5,9 @@ require 'Models/Paragraph'
|
|
5
5
|
class LinkParser
|
6
6
|
attr_accessor :usersPostURLs, :isForJekyll
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@usersPostURLs =
|
10
|
-
@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
|
-
|
40
|
+
newLinkMarkdown = "(../#{postPath})"
|
34
41
|
else
|
35
|
-
|
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
|
data/lib/Parsers/PREParser.rb
CHANGED
@@ -4,7 +4,11 @@ require "Parsers/Parser"
|
|
4
4
|
require 'Models/Paragraph'
|
5
5
|
|
6
6
|
class PREParser < Parser
|
7
|
-
attr_accessor :nextParser
|
7
|
+
attr_accessor :nextParser, :isForJekyll
|
8
|
+
|
9
|
+
def initialize(isForJekyll)
|
10
|
+
@isForJekyll = isForJekyll
|
11
|
+
end
|
8
12
|
|
9
13
|
def self.isPRE(paragraph)
|
10
14
|
if paragraph.nil?
|
@@ -17,10 +21,19 @@ class PREParser < Parser
|
|
17
21
|
def parse(paragraph)
|
18
22
|
if PREParser.isPRE(paragraph)
|
19
23
|
result = "```\n"
|
24
|
+
if isForJekyll
|
25
|
+
result += "{% raw %}\n"
|
26
|
+
end
|
27
|
+
|
20
28
|
paragraph.text.each_line do |p|
|
21
29
|
result += p
|
22
30
|
end
|
31
|
+
|
32
|
+
if isForJekyll
|
33
|
+
result += "\n{% endraw %}"
|
34
|
+
end
|
23
35
|
result += "\n```"
|
36
|
+
|
24
37
|
result
|
25
38
|
else
|
26
39
|
if !nextParser.nil?
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -71,7 +71,7 @@ class ZMediumFetcher
|
|
71
71
|
|
72
72
|
def initialize
|
73
73
|
@progress = Progress.new()
|
74
|
-
@linkParser = LinkParser.new(
|
74
|
+
@linkParser = LinkParser.new()
|
75
75
|
@isForJekyll = false
|
76
76
|
end
|
77
77
|
|
@@ -101,9 +101,9 @@ class ZMediumFetcher
|
|
101
101
|
iframeParser.setNext(imgParser)
|
102
102
|
bqParser = BQParser.new()
|
103
103
|
imgParser.setNext(bqParser)
|
104
|
-
preParser = PREParser.new()
|
104
|
+
preParser = PREParser.new(isForJekyll)
|
105
105
|
bqParser.setNext(preParser)
|
106
|
-
codeBlockParser = CodeBlockParser.new()
|
106
|
+
codeBlockParser = CodeBlockParser.new(isForJekyll)
|
107
107
|
preParser.setNext(codeBlockParser)
|
108
108
|
fallbackParser = FallbackParser.new()
|
109
109
|
codeBlockParser.setNext(fallbackParser)
|
@@ -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
|
-
|
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.
|
4
|
+
version: 1.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZhgChgLi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|