22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/legion/cli/chat/markdown_renderer.rb', line 22
def render(text, color: true)
return text unless color
lines = text.lines
output = String.new
i = 0
while i < lines.length
line = lines[i]
if line.match?(CODE_FENCE)
lang = line.match(CODE_FENCE)[1]
code_lines = []
i += 1
while i < lines.length && !lines[i].match?(/^```\s*$/)
code_lines << lines[i]
i += 1
end
i += 1 output << render_code_block(code_lines.join, lang)
else
output << render_line(line)
i += 1
end
end
output
end
|