testing stuff
This commit is contained in:
parent
d1b04c13d1
commit
e0c772db92
6 changed files with 199 additions and 8 deletions
76
src/main.rs
76
src/main.rs
|
|
@ -1,12 +1,80 @@
|
|||
use std::fs::read;
|
||||
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()))
|
||||
}
|
||||
|
||||
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 = input;
|
||||
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);
|
||||
|
||||
//println!("{}", output);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue