Fix header and newline parsing
This commit is contained in:
+20
-6
@@ -8,10 +8,10 @@ fn parse_header(line string) (int, string) {
|
||||
}
|
||||
|
||||
mut lvl := 0
|
||||
for line[lvl] == '!'[0] { // Jestem geniuszem programowania
|
||||
for lvl < line.len && line[lvl] == '!'.bytes()[0] {
|
||||
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 lvl, line[lvl + 1..]
|
||||
@@ -20,21 +20,35 @@ fn parse_header(line string) (int, string) {
|
||||
fn parse(lines []string) string {
|
||||
mut output := '<p>'
|
||||
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 {
|
||||
output += '<h' + lvl.str() + '>'
|
||||
}
|
||||
|
||||
if idx := text.index('2') {
|
||||
output += replace(text, idx, 1, 'foferk') + '<br>\n'
|
||||
text = replace(text, idx, 1, 'foferk')
|
||||
}
|
||||
|
||||
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>'
|
||||
return output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user