ZMediumToMarkdown 2.0.9 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Parsers/BQParser.rb +5 -1
- data/lib/Parsers/MarkupStyleRender.rb +65 -52
- 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: 8b93c95279c2e90820d9e0e9048c79f1fa5e5dd0a94dba690cf8a3c3b8679589
|
4
|
+
data.tar.gz: e28c0042b45bf6f29377e3c8acf4e39dff68cda0b3d1b11cba153e95c97dc5aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f24fbe044fe188d121ca6486173ccd15cd8ca1de6aea5f3ef625a0929615ba33fb890a39b144d0d0914c5c78bb30d94007629b364f87577098607651bd0f4f6
|
7
|
+
data.tar.gz: b4d939b9288c0f57ce3dd0b78bcb6d9abf672a7375cc5b3191d3820a80c9b43558f31fbafd2d5884b1b6b31b8bc9ac40406ef9fe8414964bcda4905f0b405c91
|
data/lib/Parsers/BQParser.rb
CHANGED
@@ -16,7 +16,11 @@ class BQParser < Parser
|
|
16
16
|
|
17
17
|
def parse(paragraph)
|
18
18
|
if BQParser.isBQ(paragraph)
|
19
|
-
result = "
|
19
|
+
result = "\r\n\r\n"
|
20
|
+
paragraph.text.each_line do |p|
|
21
|
+
result += "> #{p} \n\n"
|
22
|
+
end
|
23
|
+
result += "\r\n\r\n"
|
20
24
|
result
|
21
25
|
else
|
22
26
|
if !nextParser.nil?
|
@@ -48,6 +48,51 @@ class MarkupStyleRender
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def optimize(chars)
|
51
|
+
|
52
|
+
# remove style in codeblock e.g. `hello world **bold**` (markdown not allow style in codeblock)
|
53
|
+
|
54
|
+
while true
|
55
|
+
|
56
|
+
hasExcute = false
|
57
|
+
inCodeBlock = false
|
58
|
+
index = 0
|
59
|
+
|
60
|
+
chars.each do |char|
|
61
|
+
if char.chars.join() == "`"
|
62
|
+
if char.type == "TagStart"
|
63
|
+
inCodeBlock = true
|
64
|
+
elsif char.type == "TagEnd"
|
65
|
+
inCodeBlock = false
|
66
|
+
end
|
67
|
+
elsif inCodeBlock
|
68
|
+
if char.type == "TagStart" or char.type == "TagEnd"
|
69
|
+
chars.delete_at(index)
|
70
|
+
hasExcute = true
|
71
|
+
break
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
index += 1
|
76
|
+
end
|
77
|
+
|
78
|
+
if !hasExcute
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# treat escape tag as normal text
|
84
|
+
index = 0
|
85
|
+
chars.each do |char|
|
86
|
+
if char.type == "TagEnd" && char.chars.join() == ""
|
87
|
+
chars.delete_at(index)
|
88
|
+
elsif char.type == "TagStart" && char.chars.join() == "\\"
|
89
|
+
chars[index] = TextChar.new("\\".chars, "Text")
|
90
|
+
end
|
91
|
+
|
92
|
+
index += 1
|
93
|
+
end
|
94
|
+
|
95
|
+
# append space between tag and text
|
51
96
|
while true
|
52
97
|
hasExcute = false
|
53
98
|
|
@@ -126,37 +171,6 @@ class MarkupStyleRender
|
|
126
171
|
end
|
127
172
|
end
|
128
173
|
|
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
|
-
|
160
174
|
chars
|
161
175
|
end
|
162
176
|
|
@@ -175,11 +189,7 @@ class MarkupStyleRender
|
|
175
189
|
elsif markup.type == "STRONG"
|
176
190
|
tag = TagChar.new(2, markup.start, markup.end, "**", "**")
|
177
191
|
elsif markup.type == "ESCAPE"
|
178
|
-
|
179
|
-
escapeTagChar.startChars = TextChar.new('\\'.chars,'Text')
|
180
|
-
escapeTagChar.endChars = TextChar.new([],'Text')
|
181
|
-
|
182
|
-
tag = escapeTagChar
|
192
|
+
tag = TagChar.new(999, markup.start, markup.end, "\\", "")
|
183
193
|
elsif markup.type == "A"
|
184
194
|
url = markup.href
|
185
195
|
if markup.anchorType == "LINK"
|
@@ -224,16 +234,6 @@ class MarkupStyleRender
|
|
224
234
|
stack = []
|
225
235
|
|
226
236
|
chars.each do |index, char|
|
227
|
-
|
228
|
-
# is in code block
|
229
|
-
if !stack.last.nil? && stack.last.endChars.chars.join() == "`"
|
230
|
-
containEndTag = tags.select { |tag| tag.endIndex == index && tag.endChars.chars.join() == "`" }.length > 0
|
231
|
-
if !containEndTag
|
232
|
-
response.append(char)
|
233
|
-
next
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
237
|
if char.chars.join() == "\n"
|
238
238
|
brStack = stack.dup
|
239
239
|
while brStack.length > 0
|
@@ -250,19 +250,32 @@ class MarkupStyleRender
|
|
250
250
|
|
251
251
|
startTags = tags.select { |tag| tag.startIndex == index }.sort_by(&:sort)
|
252
252
|
if !startTags.nil?
|
253
|
+
hasCodeBlockTag = false
|
253
254
|
startTags.each do |tag|
|
254
|
-
|
255
|
+
if !hasCodeBlockTag
|
256
|
+
response.append(tag.startChars)
|
257
|
+
end
|
258
|
+
|
255
259
|
stack.append(tag)
|
260
|
+
|
261
|
+
if tag.startChars.chars.join() == "`"
|
262
|
+
hasCodeBlockTag = true
|
263
|
+
end
|
256
264
|
end
|
257
265
|
end
|
258
266
|
|
259
267
|
if char.chars.join() != "\n"
|
260
|
-
|
261
|
-
|
262
|
-
|
268
|
+
if !stack.select { |tag| tag.startChars.chars.join() == "`" }.nil?
|
269
|
+
# is in code block
|
270
|
+
response.append(char)
|
271
|
+
else
|
272
|
+
resultChar = Helper.escapeMarkdown(char.chars.join())
|
273
|
+
if isForJekyll
|
274
|
+
resultChar = Helper.escapeHTML(resultChar)
|
275
|
+
end
|
276
|
+
|
277
|
+
response.append(TextChar.new(resultChar.chars, "Text"))
|
263
278
|
end
|
264
|
-
|
265
|
-
response.append(TextChar.new(resultChar.chars, "Text"))
|
266
279
|
end
|
267
280
|
|
268
281
|
endTags = tags.select { |tag| tag.endIndex == index }
|
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: 2.0.
|
4
|
+
version: 2.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZhgChgLi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|