176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/rsyntaxtree/markup_parser.rb', line 176
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
|