Created
May 23, 2021 20:47
-
-
Save rawnly/3932f2fad04a40608a8567eb340a5e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn parse_markdown_link(_str_with_link: String) -> String { | |
let chars = _str_with_link.chars(); | |
let mut is_text = false; | |
let mut is_url = false; | |
let mut text : String = String::new(); | |
let mut url : String = String::new(); | |
for c in chars { | |
let char = String::from(c); | |
if char == "[" { | |
is_text = true; | |
continue; | |
} | |
if char == "]" { | |
is_text = false; | |
continue; | |
} | |
if char == "(" { | |
is_url = true; | |
continue; | |
} | |
if char == ")" { | |
is_url = false; | |
continue; | |
} | |
if is_text { | |
text.push_str(&char); | |
continue; | |
} | |
if is_url { | |
url.push_str(&char); | |
continue; | |
} | |
} | |
return format!("<a href=\"{}\">{}</a>", url, text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment