Attempt at header parsing

This commit is contained in:
2026-07-11 20:24:42 +02:00
parent e7e156cdac
commit fd4a67d08a
+17 -3
View File
@@ -3,6 +3,10 @@ fn replace(text string, start int, len int, repl string) string {
}
fn parse_header(line string) (int, string) {
if line.len == 0 {
return 0, line
}
mut lvl := 0
for line[lvl] == '!'[0] { // Jestem geniuszem programowania
lvl++
@@ -16,10 +20,20 @@ fn parse_header(line string) (int, string) {
fn parse(lines []string) string {
mut output := '<p>'
for line in lines {
if idx := line.index('2') {
output += replace(line, idx, 1, 'foferk') + '<br>\n'
lvl, text := parse_header(line)
if lvl > 0 {
output += '<h' + lvl.str() + '>'
}
output += line + '<br>\n'
if idx := text.index('2') {
output += replace(text, idx, 1, 'foferk') + '<br>\n'
}
if lvl > 0 {
output += '</h' + lvl.str() + '>'
}
output += text + '<br>\n'
}
output += '</p>'
return output