ZMediumToMarkdown 1.7.6 → 1.7.9
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 +5 -5
- data/lib/Parsers/MIXTAPEEMBEDParser.rb +2 -2
- data/lib/Parsers/MarkupParser.rb +5 -4
- data/lib/Parsers/MarkupStyleRender.rb +29 -3
- data/lib/ZMediumFetcher.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278127b85a3a3d48cf145dc4fdec065b51eb95c89808c2c0d6940a0e74e8433c
|
4
|
+
data.tar.gz: 19ad4fa053fa88a66a38e44468a955d9f6262cbbcd2677f5cf9df96af2566fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f8e83735cfefddc59cab54833be99f542ec05141dc060ed8e84932738836e3ab378e0fce6de405297d214563f74cb01db32a2a9c77fe9c8463b66e69420e880
|
7
|
+
data.tar.gz: d1af70e780fa70c549777e33e8c28fccf255a9972497b827d70eb85f8322c86e54b1912d7fe0c4a4bf26efbf514f4aedfd94058b2e0401bc115a598480a45f23
|
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
@@ -25,19 +25,19 @@ class IMGParser < Parser
|
|
25
25
|
|
26
26
|
result = ""
|
27
27
|
alt = ""
|
28
|
-
if paragraph.
|
29
|
-
alt = " \"#{paragraph.
|
28
|
+
if paragraph.orgTextWithEscape != ""
|
29
|
+
alt = " \"#{paragraph.orgTextWithEscape}\""
|
30
30
|
end
|
31
31
|
|
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.
|
35
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](/#{relativePath}#{alt})\r\n"
|
36
36
|
else
|
37
|
-
result = "\r\n![#{paragraph.
|
37
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](#{relativePath}#{alt})\r\n"
|
38
38
|
end
|
39
39
|
else
|
40
|
-
result = "\r\n![#{paragraph.
|
40
|
+
result = "\r\n![#{paragraph.orgTextWithEscape}](#{imageURL}#{alt})\r\n"
|
41
41
|
end
|
42
42
|
|
43
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,17 @@ class MarkupStyleRender
|
|
189
191
|
end
|
190
192
|
|
191
193
|
if char.chars.join() != "\n"
|
192
|
-
|
194
|
+
if !stack.select { |tag| tag.startChars.chars.join() == "`" }.nil?
|
195
|
+
# is in code block
|
196
|
+
response.append(char)
|
197
|
+
else
|
198
|
+
resultChar = Helper.escapeMarkdown(char.chars.join())
|
199
|
+
if isForJekyll
|
200
|
+
resultChar = Helper.escapeHTML(resultChar)
|
201
|
+
end
|
202
|
+
|
203
|
+
response.append(TextChar.new(resultChar.chars, "Text"))
|
204
|
+
end
|
193
205
|
end
|
194
206
|
|
195
207
|
endTags = tags.select { |tag| tag.endIndex == index }
|
@@ -220,6 +232,20 @@ class MarkupStyleRender
|
|
220
232
|
response.push(tag.endChars)
|
221
233
|
end
|
222
234
|
|
235
|
+
response = optimize(response)
|
236
|
+
result = response.map{ |response| response.chars }.join()
|
237
|
+
|
238
|
+
else
|
239
|
+
response = []
|
240
|
+
chars.each do |index, char|
|
241
|
+
resultChar = escapeMarkdown(char)
|
242
|
+
if isForJekyll
|
243
|
+
resultChar = escapeHTML(char)
|
244
|
+
end
|
245
|
+
|
246
|
+
response.append(resultChar)
|
247
|
+
end
|
248
|
+
|
223
249
|
response = optimize(response)
|
224
250
|
result = response.map{ |response| response.chars }.join()
|
225
251
|
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
|
|