ZMediumToMarkdown 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Parsers/MarkupParser.rb +5 -5
- data/lib/Parsers/MarkupStyleRender.rb +39 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15b01478e2f941c658c49359b921f152df549fc32778b8305ccd65f05578fbe
|
4
|
+
data.tar.gz: 5707c63e3c917c8598a009b9a49952bb10f50281e085ec75f2c664e2fd6d5bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db021ec2a782ea9da912b18b78ec99295813ddc1aa64555f7026eddaf43bc42823cbc287486f2bc8ca03ccbc05022e7aa1085abdb0ae2a9af1b026661412c3f
|
7
|
+
data.tar.gz: bf7bb9132809a5361a7911667cc889adf239d9322ad1fb9e8df0a325b49875fc358530d80be43450d5dccef2c5032512f37b8b81f208544c40bbc244ab5c841e
|
data/lib/Parsers/MarkupParser.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
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
|
@@ -16,14 +16,13 @@ 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
|
20
|
+
def initialize(sort, startIndex, endIndex, startChars, endChars)
|
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
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -127,6 +126,37 @@ class MarkupStyleRender
|
|
127
126
|
end
|
128
127
|
end
|
129
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
|
+
|
130
160
|
chars
|
131
161
|
end
|
132
162
|
|
@@ -141,7 +171,7 @@ class MarkupStyleRender
|
|
141
171
|
if markup.type == "EM"
|
142
172
|
tag = TagChar.new(2, markup.start, markup.end, "_", "_")
|
143
173
|
elsif markup.type == "CODE"
|
144
|
-
tag = TagChar.new(3, markup.start, markup.end, "`", "`"
|
174
|
+
tag = TagChar.new(3, markup.start, markup.end, "`", "`")
|
145
175
|
elsif markup.type == "STRONG"
|
146
176
|
tag = TagChar.new(2, markup.start, markup.end, "**", "**")
|
147
177
|
elsif markup.type == "A"
|
@@ -167,9 +197,6 @@ class MarkupStyleRender
|
|
167
197
|
response = []
|
168
198
|
stack = []
|
169
199
|
|
170
|
-
# markdown unsupoort style in code block
|
171
|
-
inCodeBlock = false
|
172
|
-
|
173
200
|
chars.each do |index, char|
|
174
201
|
|
175
202
|
if char.chars.join() == "\n"
|
@@ -189,18 +216,13 @@ class MarkupStyleRender
|
|
189
216
|
startTags = tags.select { |tag| tag.startIndex == index }.sort_by(&:sort)
|
190
217
|
if !startTags.nil?
|
191
218
|
startTags.each do |tag|
|
192
|
-
|
193
|
-
|
194
|
-
stack.append(tag)
|
195
|
-
end
|
196
|
-
if tag.isCodeBlock
|
197
|
-
inCodeBlock = true
|
198
|
-
end
|
219
|
+
response.append(tag.startChars)
|
220
|
+
stack.append(tag)
|
199
221
|
end
|
200
222
|
end
|
201
223
|
|
202
224
|
if char.chars.join() != "\n"
|
203
|
-
if
|
225
|
+
if !stack.select { |tag| tag.startChars.chars.join() == "`" }.nil?
|
204
226
|
# is in code block
|
205
227
|
response.append(char)
|
206
228
|
else
|
@@ -223,17 +245,9 @@ class MarkupStyleRender
|
|
223
245
|
# as expected
|
224
246
|
endTags.delete_at(stackTagInEndTagsIndex)
|
225
247
|
else
|
226
|
-
|
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
|
248
|
+
mismatchTags.append(stackTag)
|
236
249
|
end
|
250
|
+
response.append(stackTag.endChars)
|
237
251
|
end
|
238
252
|
|
239
253
|
while mismatchTags.length > 0
|