Fix header and newline parsing

This commit is contained in:
2026-07-11 18:32:39 +02:00
parent fd4a67d08a
commit b378012aa2
+20 -6
View File
@@ -8,10 +8,10 @@ fn parse_header(line string) (int, string) {
} }
mut lvl := 0 mut lvl := 0
for line[lvl] == '!'[0] { // Jestem geniuszem programowania for lvl < line.len && line[lvl] == '!'.bytes()[0] {
lvl++ lvl++
} }
if line[lvl + 1] != ' '[0] { // String to u8 converter xd if lvl == 0 || lvl >= line.len || line[lvl] != ' '.bytes()[0] {
return 0, line return 0, line
} }
return lvl, line[lvl + 1..] return lvl, line[lvl + 1..]
@@ -20,21 +20,35 @@ fn parse_header(line string) (int, string) {
fn parse(lines []string) string { fn parse(lines []string) string {
mut output := '<p>' mut output := '<p>'
for line in lines { for line in lines {
lvl, text := parse_header(line) mut trimmed := line.trim_space()
if trimmed.len == 0 {
output += '<br>\n'
continue
}
lvl, mut text := parse_header(trimmed)
if lvl > 0 { if lvl > 0 {
output += '<h' + lvl.str() + '>' output += '<h' + lvl.str() + '>'
} }
if idx := text.index('2') { if idx := text.index('2') {
output += replace(text, idx, 1, 'foferk') + '<br>\n' text = replace(text, idx, 1, 'foferk')
} }
if lvl > 0 { if lvl > 0 {
output += '</h' + lvl.str() + '>' output += text + '</h' + lvl.str() + '>'
} else {
output += text
} }
output += text + '<br>\n' if lvl == 0 {
output += '<br>'
} }
output += '\n'
}
output += '</p>' output += '</p>'
return output return output
} }