ZMediumToMarkdown 1.7.8 → 1.9.0
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/lib/Helper.rb +9 -1
- data/lib/Parsers/IframeParser.rb +5 -0
- data/lib/Parsers/MIXTAPEEMBEDParser.rb +7 -1
- data/lib/Parsers/MarkupStyleRender.rb +34 -12
- data/lib/ZMediumFetcher.rb +3 -4
- 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: bc5867264a6441b236d54340f34e507ef4308f99b6908f21fd975a9061c81483
|
4
|
+
data.tar.gz: 00d61d0b23a23afe0e445f5a6d98533dd41a02cc41e6ea55168a12620860203f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e6f4244d5c291872bcfcedfe961b30e377638e812dade41a9ade68c9e83d66dfe7e1061e2131d106b2605f61014cacc632e4a6984c09b1089e458d0d88cfda
|
7
|
+
data.tar.gz: b5577f2dd3cec3ce63f15e531b0b9a0574ff74fef8981d21d32badac236a562d1a4ad3cf14757aee8073da9877119b7f3fe64b5ef4a37abf94cbcbcdc1f409f1
|
data/lib/Helper.rb
CHANGED
@@ -8,11 +8,19 @@ require "Request"
|
|
8
8
|
require 'json'
|
9
9
|
require 'open-uri'
|
10
10
|
require 'zip'
|
11
|
+
require 'nokogiri'
|
11
12
|
|
12
13
|
class Helper
|
13
14
|
|
14
15
|
def self.escapeMarkdown(text)
|
15
|
-
text.gsub(/(\*|_|`|\||\\|\{|\}
|
16
|
+
text.gsub(/(\*|_|`|\||\\|\{|\}|\[|\]|\(|\)|#|\+|\-|\.|\!)/){ |x| "\\#{x}" }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.fetchOGImage(url)
|
20
|
+
html = Request.html(Request.URL(url))
|
21
|
+
content = html.search("meta[property='og:image']").attribute('content')
|
22
|
+
|
23
|
+
content
|
16
24
|
end
|
17
25
|
|
18
26
|
def self.escapeHTML(text)
|
data/lib/Parsers/IframeParser.rb
CHANGED
@@ -70,6 +70,11 @@ class IframeParser < Parser
|
|
70
70
|
result = "```#{lang}\n#{gistRAW}\n```"
|
71
71
|
end
|
72
72
|
end
|
73
|
+
else
|
74
|
+
ogImageURL = Helper.fetchOGImage(url)
|
75
|
+
if !ogImageURL.nil?
|
76
|
+
result = "\r\n[](#{url})\r\n"
|
77
|
+
end
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
$lib = File.expand_path('../', File.dirname(__FILE__))
|
2
2
|
|
3
|
+
require "Helper"
|
3
4
|
require "Parsers/Parser"
|
4
5
|
require 'Models/Paragraph'
|
5
6
|
|
@@ -8,7 +9,12 @@ class MIXTAPEEMBEDParser < Parser
|
|
8
9
|
def parse(paragraph)
|
9
10
|
if paragraph.type == 'MIXTAPE_EMBED'
|
10
11
|
if !paragraph.mixtapeMetadata.nil? && !paragraph.mixtapeMetadata.href.nil?
|
11
|
-
|
12
|
+
ogImageURL = Helper.fetchOGImage(paragraph.mixtapeMetadata.href)
|
13
|
+
if !ogImageURL.nil?
|
14
|
+
"\r\n[](#{paragraph.mixtapeMetadata.href})\r\n"
|
15
|
+
else
|
16
|
+
"\n[#{paragraph.orgTextWithEscape}](#{paragraph.mixtapeMetadata.href})"
|
17
|
+
end
|
12
18
|
else
|
13
19
|
"\n#{paragraph.text}"
|
14
20
|
end
|
@@ -16,13 +16,14 @@ class MarkupStyleRender
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class TagChar < TextChar
|
19
|
-
attr_accessor :sort, :startIndex, :endIndex, :startChars, :endChars
|
20
|
-
def initialize(sort, startIndex, endIndex, startChars, endChars)
|
19
|
+
attr_accessor :sort, :startIndex, :endIndex, :startChars, :endChars, :isCodeBlock
|
20
|
+
def initialize(sort, startIndex, endIndex, startChars, endChars, isCodeBlock = false)
|
21
21
|
@sort = sort
|
22
22
|
@startIndex = startIndex
|
23
23
|
@endIndex = endIndex - 1
|
24
24
|
@startChars = TextChar.new(startChars.chars, 'TagStart')
|
25
25
|
@endChars = TextChar.new(endChars.chars, 'TagEnd')
|
26
|
+
@isCodeBlock = isCodeBlock
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -140,7 +141,7 @@ class MarkupStyleRender
|
|
140
141
|
if markup.type == "EM"
|
141
142
|
tag = TagChar.new(2, markup.start, markup.end, "_", "_")
|
142
143
|
elsif markup.type == "CODE"
|
143
|
-
tag = TagChar.new(3, markup.start, markup.end, "`", "`")
|
144
|
+
tag = TagChar.new(3, markup.start, markup.end, "`", "`", true)
|
144
145
|
elsif markup.type == "STRONG"
|
145
146
|
tag = TagChar.new(2, markup.start, markup.end, "**", "**")
|
146
147
|
elsif markup.type == "A"
|
@@ -166,6 +167,9 @@ class MarkupStyleRender
|
|
166
167
|
response = []
|
167
168
|
stack = []
|
168
169
|
|
170
|
+
# markdown unsupoort style in code block
|
171
|
+
inCodeBlock = false
|
172
|
+
|
169
173
|
chars.each do |index, char|
|
170
174
|
|
171
175
|
if char.chars.join() == "\n"
|
@@ -185,18 +189,28 @@ class MarkupStyleRender
|
|
185
189
|
startTags = tags.select { |tag| tag.startIndex == index }.sort_by(&:sort)
|
186
190
|
if !startTags.nil?
|
187
191
|
startTags.each do |tag|
|
188
|
-
|
189
|
-
|
192
|
+
if inCodeBlock == false
|
193
|
+
response.append(tag.startChars)
|
194
|
+
stack.append(tag)
|
195
|
+
end
|
196
|
+
if tag.isCodeBlock
|
197
|
+
inCodeBlock = true
|
198
|
+
end
|
190
199
|
end
|
191
200
|
end
|
192
201
|
|
193
202
|
if char.chars.join() != "\n"
|
194
|
-
|
195
|
-
|
196
|
-
|
203
|
+
if inCodeBlock
|
204
|
+
# is in code block
|
205
|
+
response.append(char)
|
206
|
+
else
|
207
|
+
resultChar = Helper.escapeMarkdown(char.chars.join())
|
208
|
+
if isForJekyll
|
209
|
+
resultChar = Helper.escapeHTML(resultChar)
|
210
|
+
end
|
211
|
+
|
212
|
+
response.append(TextChar.new(resultChar.chars, "Text"))
|
197
213
|
end
|
198
|
-
|
199
|
-
response.append(TextChar.new(resultChar.chars, "Text"))
|
200
214
|
end
|
201
215
|
|
202
216
|
endTags = tags.select { |tag| tag.endIndex == index }
|
@@ -209,9 +223,17 @@ class MarkupStyleRender
|
|
209
223
|
# as expected
|
210
224
|
endTags.delete_at(stackTagInEndTagsIndex)
|
211
225
|
else
|
212
|
-
|
226
|
+
if inCodeBlock == false or stackTag.isCodeBlock == true
|
227
|
+
mismatchTags.append(stackTag)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
if inCodeBlock == false or stackTag.isCodeBlock == true
|
231
|
+
response.append(stackTag.endChars)
|
232
|
+
end
|
233
|
+
|
234
|
+
if stackTag.isCodeBlock
|
235
|
+
inCodeBlock = false
|
213
236
|
end
|
214
|
-
response.append(stackTag.endChars)
|
215
237
|
end
|
216
238
|
|
217
239
|
while mismatchTags.length > 0
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -186,8 +186,7 @@ class ZMediumFetcher
|
|
186
186
|
groupByText += "\n"
|
187
187
|
end
|
188
188
|
|
189
|
-
|
190
|
-
groupByText += markupParser.parse()
|
189
|
+
groupByText += preTypeParagraph.orgText
|
191
190
|
end
|
192
191
|
|
193
192
|
lastPreTypeParagraph.text = "#{groupByText}"
|
@@ -210,10 +209,10 @@ class ZMediumFetcher
|
|
210
209
|
end
|
211
210
|
|
212
211
|
if isForJekyll
|
213
|
-
postPathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "_posts")
|
212
|
+
postPathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "_posts/zmediumtomarkdown")
|
214
213
|
imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "assets")
|
215
214
|
else
|
216
|
-
postPathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "
|
215
|
+
postPathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "zmediumtomarkdown")
|
217
216
|
imagePathPolicy = PathPolicy.new(postPathPolicy.getAbsolutePath(nil), "assets")
|
218
217
|
end
|
219
218
|
|
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.
|
4
|
+
version: 1.9.0
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|