202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/rsyntaxtree/markup_parser.rb', line 202
def parse(txt)
begin
parsed = @parser.parse(txt)
rescue Parslet::ParseFailed
return { status: :error, text: txt }
end
applied = @evaluator.apply(parsed)
results = { enclosure: :none, triangle: false, paths: [], contents: [], color: nil, region: false, region_color: nil }
applied.each do |h|
if h[:region]
results[:region] = true
region_color = h[:region][:region_color]
results[:region_color] = region_color[:color_value].to_s if region_color && region_color[:color_value]
end
if h[:enclosure]
results[:enclosure] = case h[:enclosure].to_s
when '###'
:brectangle
when '##'
:rectangle
when '#'
:brackets
else
:none
end
end
results[:triangle] = h[:triangle].to_s == '^' if h[:triangle]
results[:paths] = h[:paths] if h[:paths]
if h[:color] && h[:color][:color_value]
color_value = h[:color][:color_value].to_s
results[:color] = color_value
end
results[:contents] << h if h[:type] == :text || h[:type] == :border || h[:type] == :bborder
end
{ status: :success, results: results }
end
|