ZMediumToMarkdown 1.7.8 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38b611d86bc16468f228c710b5b7f2732b49da2178991b676c957e0aa1b8a245
4
- data.tar.gz: fcda6c6684aad98c3b00e4d2009f4c7dc9e18a05f5a9b699a9cbee1052a2caa9
3
+ metadata.gz: bc5867264a6441b236d54340f34e507ef4308f99b6908f21fd975a9061c81483
4
+ data.tar.gz: 00d61d0b23a23afe0e445f5a6d98533dd41a02cc41e6ea55168a12620860203f
5
5
  SHA512:
6
- metadata.gz: 36400640d1cf148e68b1852076ef0099a8f2100aaab8ad15d20848c081ad7f10db113f7ca18589eda27392d8a006e72c7f6ffe725b0f755b566883801da4fff2
7
- data.tar.gz: 4c5341aaf24828956de14b9e4c60d88a98fabd99147069393f1d3695a3423de4cd6a5a75372cc375b8431d9cd418248db19a8c987408dafa1371c7a33d974630
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(/(\*|_|`|\||\\|\{|\}\[|\]|\(|\)|#|\+|\-|\.|\!)/){ |x| "\\#{x}" }
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)
@@ -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[![#{paragraph.iframe.title}](#{ogImageURL} \"#{paragraph.iframe.title}\")](#{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
- "\n[#{paragraph.orgTextWithEscape}](#{paragraph.mixtapeMetadata.href})"
12
+ ogImageURL = Helper.fetchOGImage(paragraph.mixtapeMetadata.href)
13
+ if !ogImageURL.nil?
14
+ "\r\n[![#{paragraph.orgTextWithEscape}](#{ogImageURL} \"#{paragraph.orgTextWithEscape}\")](#{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
- response.append(tag.startChars)
189
- stack.append(tag)
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
- resultChar = Helper.escapeMarkdown(char.chars.join())
195
- if isForJekyll
196
- resultChar = Helper.escapeHTML(resultChar)
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
- mismatchTags.append(stackTag)
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
@@ -186,8 +186,7 @@ class ZMediumFetcher
186
186
  groupByText += "\n"
187
187
  end
188
188
 
189
- markupParser = MarkupParser.new(preTypeParagraph, isForJekyll)
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), "posts")
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.7.8
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-13 00:00:00.000000000 Z
11
+ date: 2022-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri