ZMediumToMarkdown 2.0.10 → 2.0.11
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/Parsers/MarkupStyleRender.rb +56 -51
- 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: 3605356973101df17419ca4232f870a0bab0062f04409c78b0a267c1b799a911
|
4
|
+
data.tar.gz: 10506a2d7f3a699059869ecc7e070c63939a361ccf13007308acb7596d73b130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950325be2b1088bef87a36ceffdabce9be5d9800a9ba5d47fbeb09f2d8ff90c2a01a827b7272af5ef4ac9285a06b4de86cea2ea03e81b0984aa2a49f78a269ff
|
7
|
+
data.tar.gz: 3a448256e99ad7eb6da7a28b89be0e6984430466b04b3d0eec25a9eed24026f6b29f90f25a226f487ce0639d49192fd41e0045b597d2ef1129f505fab67a65de
|
@@ -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
|
@@ -265,12 +265,17 @@ class MarkupStyleRender
|
|
265
265
|
end
|
266
266
|
|
267
267
|
if char.chars.join() != "\n"
|
268
|
-
|
269
|
-
|
270
|
-
|
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"))
|
271
278
|
end
|
272
|
-
|
273
|
-
response.append(TextChar.new(resultChar.chars, "Text"))
|
274
279
|
end
|
275
280
|
|
276
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZhgChgLi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|