This commit is contained in:
Rakarake 2026-03-23 16:03:23 +01:00
parent e0c772db92
commit 4ae3e75ac3
3 changed files with 21 additions and 74 deletions

View file

@ -1,80 +1,8 @@
fn header(i: &str) -> Option<(&str, String)> {
let mut itr = i.chars();
if let Some(next) = itr.next() && next == '\n' {
if let Some(maybe_star) = itr.skip_while(|c| *c == ' ' || *c == '\t').next() && maybe_star == '*' {
}
}
Some((i, "<h1>".to_string()))
}
use markdown::to_html;
fn main() {
// arg 1: src, arg 2: dest
let args: Vec<String> = std::env::args().collect();
let input: String = std::fs::read_to_string(&args[1]).unwrap();
let mut output: String = String::new();
let mut is_bold = false;
let mut title: Option<usize> = None;
let mut itr = input.chars().peekable();
while let Some(c) = itr.next() {
match c {
'*' => {
if !is_bold {
output.push_str("<b>");
is_bold = true;
} else {
output.push_str("</b>");
is_bold = false;
}
}
'\n' => {
if let Some(title_count) = title {
title = None;
output.push_str(&format!("</h{title_count}>"));
} else {
let mut title_count = 0;
while let Some(c) = itr.peek() {
if *c == '#' {
title_count += 1;
} else if *c == ' ' || *c == '\t' {
// it is title
output.push_str(&format!("<h{title_count}>"));
title = Some(title_count);
} else {
}
}
}
output.push('\n');
}
_ => {
output.push(c);
}
}
}
println!("{output}");
//let output: String = input.lines().map(|l| {
// // Titles
// let count = l.chars().take_while(|c| *c == '#').count();
// if count > 0 {
// format!("<h{count}>{}</h{count}>", &l[count..])
// } else {
// l.to_string()
// }
//})
//.map(|l| {
// if l.chars().skip_while(|c| *c == ' ' || *c == '\t').next().unwrap_or('g') == '*' {
//
// } else {
// l.to_string()
// }
//})
//.collect();
// headings: replace # - newline to <h1> - </h1>
//println!("{}", output);
print!("{}", to_html(&input));
}