cool
This commit is contained in:
parent
e0c772db92
commit
4ae3e75ac3
3 changed files with 21 additions and 74 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
|
@ -2,6 +2,24 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "markdown"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a5cab8f2cadc416a82d2e783a1946388b31654d391d1c7d92cc1f03e295b1deb"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-id",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mdf-blog"
|
name = "mdf-blog"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"markdown",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-id"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ba288e709927c043cbe476718d37be306be53fb1fafecd0dbe36d072be2580"
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
markdown = "*"
|
||||||
|
|
|
||||||
76
src/main.rs
76
src/main.rs
|
|
@ -1,80 +1,8 @@
|
||||||
fn header(i: &str) -> Option<(&str, String)> {
|
use markdown::to_html;
|
||||||
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() {
|
fn main() {
|
||||||
// arg 1: src, arg 2: dest
|
// arg 1: src, arg 2: dest
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
let input: String = std::fs::read_to_string(&args[1]).unwrap();
|
let input: String = std::fs::read_to_string(&args[1]).unwrap();
|
||||||
let mut output: String = String::new();
|
print!("{}", to_html(&input));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue