ZMediumToMarkdown 1.8.0 → 1.9.2

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: dd013ec3e5d14a70bde7a740c1bf706aab2b2f9d1cb8d51f6dba4d91de6e1a64
4
- data.tar.gz: dcb1fd33caff28304fffd152ee4e5027dfa36a149a54230a37cdb93520c0461d
3
+ metadata.gz: 1d7cb2d26657c6eaa7fe4bf2bb81d5800ccce3d8403dd2324127d0468da52a84
4
+ data.tar.gz: 93c138a38d80cb1e141fa73840fe31e91cce89b05616ebc7867a5e59c6be62f9
5
5
  SHA512:
6
- metadata.gz: be39a4ea0bef517393348fe00cb61f9b6360197567a2edb30810909e743b833bd948b16fd42cc9bd05b4320500ab7ac54ec1da8ecdedcdc6f3c377eecc17d36e
7
- data.tar.gz: 279eb3fdbe72c3569e13b4da3411376d952ccdb835abb1d219f2b77f97ee4a620c952273c0f3831a7dd1b3954af6fb7155226f10c8b85c26e2cd655bc4d30005
6
+ metadata.gz: d5d434403f7c4342f7f74c9a50b82d35767e0c4b9a13f92689e042eceaf432878b76781abc2f5986601eddf9916ca663eb42181be852743950b91b96c7fcaf00
7
+ data.tar.gz: b4a525b9cc5f482272b601c06cecfe641cc8c7f93affaa330cbe35f1002c226e474c40befe4b67ffc1d67af7ffea897b8fd4d0c7a7843d61d1e836cfb5107455
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
@@ -126,6 +126,37 @@ class MarkupStyleRender
126
126
  end
127
127
  end
128
128
 
129
+ # remove style in codeblock e.g. `hello world **bold**` (markdown not allow style in codeblock)
130
+
131
+ while true
132
+
133
+ hasExcute = false
134
+ inCodeBlock = false
135
+ index = 0
136
+
137
+ chars.each do |char|
138
+ if char.chars.join() == "`"
139
+ if char.type == "TagStart"
140
+ inCodeBlock = true
141
+ elsif char.type == "TagEnd"
142
+ inCodeBlock = false
143
+ end
144
+ elsif inCodeBlock
145
+ if char.type == "TagStart" or char.type == "TagEnd"
146
+ chars.delete_at(index)
147
+ hasExcute = true
148
+ break
149
+ end
150
+ end
151
+
152
+ index += 1
153
+ end
154
+
155
+ if !hasExcute
156
+ break
157
+ end
158
+ end
159
+
129
160
  chars
130
161
  end
131
162
 
@@ -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}"
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.8.0
4
+ version: 1.9.2
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-16 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