quick links and <br/> support
This commit is contained in:
parent
590cd001be
commit
8e860b89e7
18
src/main.rs
18
src/main.rs
@ -41,6 +41,12 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
||||
result
|
||||
}).to_string();
|
||||
|
||||
// html br tag support
|
||||
let br_regex = Regex::new(r"(.*?)<br/>(.*?)").unwrap();
|
||||
parsed_line = br_regex.replace_all(&parsed_line, |caps: ®ex::Captures| {
|
||||
format!("{}{}{}", &caps[1], "\n", &caps[2])
|
||||
}).to_string();
|
||||
|
||||
// Italics
|
||||
let italic_regex = Regex::new(r"\*(.*?)\*").unwrap();
|
||||
parsed_line = italic_regex.replace_all(&parsed_line, |caps: ®ex::Captures| {
|
||||
@ -68,7 +74,7 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
||||
// Inline code
|
||||
let inline_code_regex = Regex::new(r"`(.*?)`").unwrap();
|
||||
parsed_line = inline_code_regex.replace_all(&parsed_line, |caps: ®ex::Captures| {
|
||||
format!("{}", &caps[1].red().on_white())
|
||||
format!("{}", &caps[1].magenta())
|
||||
}).to_string();
|
||||
|
||||
// HyperLink
|
||||
@ -90,6 +96,14 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
||||
}
|
||||
}).to_string();
|
||||
|
||||
let quick_hyperlink_regex = Regex::new(r"<(.*?)>").unwrap();
|
||||
parsed_line = quick_hyperlink_regex.replace_all(&parsed_line, |caps: ®ex::Captures| {
|
||||
hyperlink_number_counter += 1;
|
||||
let url = caps[1].to_string();
|
||||
links.push(url);
|
||||
format!("{}[{}]", &caps[1].blue().underline(), hyperlink_number_counter)
|
||||
}).to_string();
|
||||
|
||||
|
||||
parsed_page_content+=&(parsed_line + "\n");
|
||||
}
|
||||
@ -108,7 +122,7 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
||||
.join("\n");
|
||||
|
||||
// Return the formatted block with magenta color
|
||||
format!("{}", indented_code.red().on_white())
|
||||
format!("{}", indented_code.magenta())
|
||||
}).to_string();
|
||||
|
||||
return (parsed_page_content, links);
|
||||
|
Loading…
x
Reference in New Issue
Block a user