ZMediumToMarkdown 1.7.5 → 1.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Helper.rb +14 -0
- data/lib/Models/Paragraph.rb +5 -1
- data/lib/Parsers/IMGParser.rb +7 -3
- data/lib/Parsers/MIXTAPEEMBEDParser.rb +2 -2
- data/lib/Parsers/MarkupParser.rb +5 -4
- data/lib/Parsers/MarkupStyleRender.rb +24 -3
- data/lib/ZMediumFetcher.rb +2 -2
- 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: 38b611d86bc16468f228c710b5b7f2732b49da2178991b676c957e0aa1b8a245
|
4
|
+
data.tar.gz: fcda6c6684aad98c3b00e4d2009f4c7dc9e18a05f5a9b699a9cbee1052a2caa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36400640d1cf148e68b1852076ef0099a8f2100aaab8ad15d20848c081ad7f10db113f7ca18589eda27392d8a006e72c7f6ffe725b0f755b566883801da4fff2
|
7
|
+
data.tar.gz: 4c5341aaf24828956de14b9e4c60d88a98fabd99147069393f1d3695a3423de4cd6a5a75372cc375b8431d9cd418248db19a8c987408dafa1371c7a33d974630
|
data/lib/Helper.rb
CHANGED
@@ -11,6 +11,20 @@ require 'zip'
|
|
11
11
|
|
12
12
|
class Helper
|
13
13
|
|
14
|
+
def self.escapeMarkdown(text)
|
15
|
+
text.gsub(/(\*|_|`|\||\\|\{|\}\[|\]|\(|\)|#|\+|\-|\.|\!)/){ |x| "\\#{x}" }
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.escapeHTML(text)
|
19
|
+
if text == "<"
|
20
|
+
"<"
|
21
|
+
elsif text == ">"
|
22
|
+
">"
|
23
|
+
else
|
24
|
+
text
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
14
28
|
def self.createDirIfNotExist(dirPath)
|
15
29
|
dirs = dirPath.split("/")
|
16
30
|
currentDir = ""
|
data/lib/Models/Paragraph.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
$lib = File.expand_path('../', File.dirname(__FILE__))
|
2
2
|
|
3
|
+
require 'Helper'
|
3
4
|
require 'Parsers/PParser'
|
4
5
|
require 'securerandom'
|
5
6
|
|
6
7
|
class Paragraph
|
7
|
-
attr_accessor :postID, :name, :orgText, :text, :type, :href, :metadata, :mixtapeMetadata, :iframe, :oliIndex, :markups, :markupLinks
|
8
|
+
attr_accessor :postID, :name, :orgText, :orgTextWithEscape, :text, :type, :href, :metadata, :mixtapeMetadata, :iframe, :oliIndex, :markups, :markupLinks
|
8
9
|
|
9
10
|
class Iframe
|
10
11
|
attr_accessor :id, :title, :type, :src
|
@@ -65,6 +66,9 @@ class Paragraph
|
|
65
66
|
@href = json['href']
|
66
67
|
@postID = postID
|
67
68
|
|
69
|
+
orgTextWithEscape = Helper.escapeMarkdown(json['text'])
|
70
|
+
@orgTextWithEscape = orgTextWithEscape
|
71
|
+
|
68
72
|
if json['metadata'].nil?
|
69
73
|
@metadata = nil
|
70
74
|
else
|
data/lib/Parsers/IMGParser.rb
CHANGED
@@ -24,16 +24,20 @@ class IMGParser < Parser
|
|
24
24
|
absolutePath = imagePathPolicy.getAbsolutePath(fileName)
|
25
25
|
|
26
26
|
result = ""
|
27
|
+
alt = ""
|
28
|
+
if paragraph.orgTextWithEscape != ""
|
29
|
+
alt = " \"#{paragraph.orgTextWithEscape}\""
|
30
|
+
end
|
27
31
|
|
28
32
|
if ImageDownloader.download(absolutePath, imageURL)
|
29
33
|
relativePath = "#{pathPolicy.getRelativePath(nil)}/#{imagePathPolicy.getRelativePath(fileName)}"
|
30
34
|
if isForJekyll
|
31
|
-
result = "\r\n![#{paragraph.
|
35
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](/#{relativePath}#{alt})\r\n"
|
32
36
|
else
|
33
|
-
result = "\r\n![#{paragraph.
|
37
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](#{relativePath}#{alt})\r\n"
|
34
38
|
end
|
35
39
|
else
|
36
|
-
result = "\r\n![#{paragraph.
|
40
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](#{imageURL}#{alt})\r\n"
|
37
41
|
end
|
38
42
|
|
39
43
|
if paragraph.text != ""
|
@@ -8,9 +8,9 @@ class MIXTAPEEMBEDParser < Parser
|
|
8
8
|
def parse(paragraph)
|
9
9
|
if paragraph.type == 'MIXTAPE_EMBED'
|
10
10
|
if !paragraph.mixtapeMetadata.nil? && !paragraph.mixtapeMetadata.href.nil?
|
11
|
-
"\n[#{paragraph.
|
11
|
+
"\n[#{paragraph.orgTextWithEscape}](#{paragraph.mixtapeMetadata.href})"
|
12
12
|
else
|
13
|
-
"\n#{paragraph.
|
13
|
+
"\n#{paragraph.text}"
|
14
14
|
end
|
15
15
|
else
|
16
16
|
if !nextParser.nil?
|
data/lib/Parsers/MarkupParser.rb
CHANGED
@@ -7,16 +7,17 @@ require 'securerandom'
|
|
7
7
|
require 'User'
|
8
8
|
|
9
9
|
class MarkupParser
|
10
|
-
attr_accessor :body, :paragraph
|
11
|
-
|
12
|
-
def initialize(paragraph)
|
10
|
+
attr_accessor :body, :paragraph, :isForJekyll
|
11
|
+
|
12
|
+
def initialize(paragraph, isForJekyll)
|
13
13
|
@paragraph = paragraph
|
14
|
+
@isForJekyll = isForJekyll
|
14
15
|
end
|
15
16
|
|
16
17
|
def parse()
|
17
18
|
result = paragraph.text
|
18
19
|
if !paragraph.markups.nil? && paragraph.markups.length > 0
|
19
|
-
markupRender = MarkupStyleRender.new(paragraph)
|
20
|
+
markupRender = MarkupStyleRender.new(paragraph, isForJekyll)
|
20
21
|
|
21
22
|
begin
|
22
23
|
result = markupRender.parse()
|
@@ -2,9 +2,10 @@
|
|
2
2
|
$lib = File.expand_path('../', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
require 'Models/Paragraph'
|
5
|
+
require 'Helper'
|
5
6
|
|
6
7
|
class MarkupStyleRender
|
7
|
-
attr_accessor :paragraph, :chars, :encodeType
|
8
|
+
attr_accessor :paragraph, :chars, :encodeType, :isForJekyll
|
8
9
|
|
9
10
|
class TextChar
|
10
11
|
attr_accessor :chars, :type
|
@@ -26,8 +27,9 @@ class MarkupStyleRender
|
|
26
27
|
end
|
27
28
|
|
28
29
|
|
29
|
-
def initialize(paragraph)
|
30
|
+
def initialize(paragraph, isForJekyll)
|
30
31
|
@paragraph = paragraph
|
32
|
+
@isForJekyll = isForJekyll
|
31
33
|
|
32
34
|
chars = {}
|
33
35
|
index = 0
|
@@ -189,7 +191,12 @@ class MarkupStyleRender
|
|
189
191
|
end
|
190
192
|
|
191
193
|
if char.chars.join() != "\n"
|
192
|
-
|
194
|
+
resultChar = Helper.escapeMarkdown(char.chars.join())
|
195
|
+
if isForJekyll
|
196
|
+
resultChar = Helper.escapeHTML(resultChar)
|
197
|
+
end
|
198
|
+
|
199
|
+
response.append(TextChar.new(resultChar.chars, "Text"))
|
193
200
|
end
|
194
201
|
|
195
202
|
endTags = tags.select { |tag| tag.endIndex == index }
|
@@ -220,6 +227,20 @@ class MarkupStyleRender
|
|
220
227
|
response.push(tag.endChars)
|
221
228
|
end
|
222
229
|
|
230
|
+
response = optimize(response)
|
231
|
+
result = response.map{ |response| response.chars }.join()
|
232
|
+
|
233
|
+
else
|
234
|
+
response = []
|
235
|
+
chars.each do |index, char|
|
236
|
+
resultChar = escapeMarkdown(char)
|
237
|
+
if isForJekyll
|
238
|
+
resultChar = escapeHTML(char)
|
239
|
+
end
|
240
|
+
|
241
|
+
response.append(resultChar)
|
242
|
+
end
|
243
|
+
|
223
244
|
response = optimize(response)
|
224
245
|
result = response.map{ |response| response.chars }.join()
|
225
246
|
end
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -186,7 +186,7 @@ class ZMediumFetcher
|
|
186
186
|
groupByText += "\n"
|
187
187
|
end
|
188
188
|
|
189
|
-
markupParser = MarkupParser.new(preTypeParagraph)
|
189
|
+
markupParser = MarkupParser.new(preTypeParagraph, isForJekyll)
|
190
190
|
groupByText += markupParser.parse()
|
191
191
|
end
|
192
192
|
|
@@ -244,7 +244,7 @@ class ZMediumFetcher
|
|
244
244
|
paragraphs.each do |paragraph|
|
245
245
|
|
246
246
|
if !(CodeBlockParser.isCodeBlock(paragraph) || PREParser.isPRE(paragraph))
|
247
|
-
markupParser = MarkupParser.new(paragraph)
|
247
|
+
markupParser = MarkupParser.new(paragraph, isForJekyll)
|
248
248
|
paragraph.text = markupParser.parse()
|
249
249
|
end
|
250
250
|
|
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.7.
|
4
|
+
version: 1.7.8
|
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-
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|