fn replace(text string, start int, len int, repl string) string { return text[..start] + repl + text[start + len..] } fn parse_header(line string) (int, string) { if line.len == 0 { return 0, line } mut lvl := 0 for lvl < line.len && line[lvl] == '!'.bytes()[0] { lvl++ } if lvl == 0 || lvl >= line.len || line[lvl] != ' '.bytes()[0] { return 0, line } return lvl, line[lvl + 1..] } fn parse(lines []string) string { mut output := '
'
for line in lines {
mut trimmed := line.trim_space()
if trimmed.len == 0 {
output += '
\n'
continue
}
lvl, mut text := parse_header(trimmed)
is_header := lvl > 0
if is_header {
output += '
'
}
output += '\n'
}
output += '