ZMediumToMarkdown 1.7.9 → 1.9.1

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: 278127b85a3a3d48cf145dc4fdec065b51eb95c89808c2c0d6940a0e74e8433c
4
- data.tar.gz: 19ad4fa053fa88a66a38e44468a955d9f6262cbbcd2677f5cf9df96af2566fb5
3
+ metadata.gz: f15b01478e2f941c658c49359b921f152df549fc32778b8305ccd65f05578fbe
4
+ data.tar.gz: 5707c63e3c917c8598a009b9a49952bb10f50281e085ec75f2c664e2fd6d5bb2
5
5
  SHA512:
6
- metadata.gz: 2f8e83735cfefddc59cab54833be99f542ec05141dc060ed8e84932738836e3ab378e0fce6de405297d214563f74cb01db32a2a9c77fe9c8463b66e69420e880
7
- data.tar.gz: d1af70e780fa70c549777e33e8c28fccf255a9972497b827d70eb85f8322c86e54b1912d7fe0c4a4bf26efbf514f4aedfd94058b2e0401bc115a598480a45f23
6
+ metadata.gz: 1db021ec2a782ea9da912b18b78ec99295813ddc1aa64555f7026eddaf43bc42823cbc287486f2bc8ca03ccbc05022e7aa1085abdb0ae2a9af1b026661412c3f
7
+ data.tar.gz: bf7bb9132809a5361a7911667cc889adf239d9322ad1fb9e8df0a325b49875fc358530d80be43450d5dccef2c5032512f37b8b81f208544c40bbc244ab5c841e
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
@@ -19,12 +19,12 @@ class MarkupParser
19
19
  if !paragraph.markups.nil? && paragraph.markups.length > 0
20
20
  markupRender = MarkupStyleRender.new(paragraph, isForJekyll)
21
21
 
22
- begin
22
+ #begin
23
23
  result = markupRender.parse()
24
- rescue => e
25
- puts e.backtrace
26
- Helper.makeWarningText("Error occurred during render markup text, please help to open an issue on github.")
27
- end
24
+ #rescue => e
25
+ # puts e.backtrace
26
+ # Helper.makeWarningText("Error occurred during render markup text, please help to open an issue on github.")
27
+ #end
28
28
  end
29
29
 
30
30
  result
@@ -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}"
@@ -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.9
4
+ version: 1.9.1
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