Attempt at header parsing
This commit is contained in:
+17
-3
@@ -3,6 +3,10 @@ fn replace(text string, start int, len int, repl string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_header(line string) (int, string) {
|
fn parse_header(line string) (int, string) {
|
||||||
|
if line.len == 0 {
|
||||||
|
return 0, line
|
||||||
|
}
|
||||||
|
|
||||||
mut lvl := 0
|
mut lvl := 0
|
||||||
for line[lvl] == '!'[0] { // Jestem geniuszem programowania
|
for line[lvl] == '!'[0] { // Jestem geniuszem programowania
|
||||||
lvl++
|
lvl++
|
||||||
@@ -16,10 +20,20 @@ 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 {
|
||||||
if idx := line.index('2') {
|
lvl, text := parse_header(line)
|
||||||
output += replace(line, idx, 1, 'foferk') + '<br>\n'
|
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>'
|
output += '</p>'
|
||||||
return output
|
return output
|
||||||
|
|||||||
Reference in New Issue
Block a user