Skip to content

Commit

Permalink
Merge pull request #262 from AndrewCS149/markdownFix
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
The-DevBlog authored Jul 6, 2024
2 parents e91e3c2 + 1e5d114 commit f83580a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions client/src/components/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub fn markdown(props: &Props) -> Html {
let link_regex = Regex::new(r"\[([^\]]+)\]\((https?://[^\)]+)\)").unwrap();

let html = props.content.lines().map(|line| {
// replace markdown links with anchor tags
// eg: [thedevblog](https://thedevblog.net) -> <a href="https://thedevblog.net">thedevblog</a>
// Process links for the entire line
let mut line_html = vec![];
let mut last_pos = 0;
for chars in link_regex.captures_iter(line) {
Expand All @@ -36,16 +35,15 @@ pub fn markdown(props: &Props) -> Html {
let combined_html = html! { <>{for line_html}</> };

match line {
l if l.starts_with("# ") => html! {<h1>{&l[1..]}</h1>},
l if l.starts_with("## ") => html! {<h2>{&l[2..]}</h2>},
l if l.starts_with("### ") => html! {<h3>{&l[3..]}</h3>},
l if l.starts_with("#### ") => html! {<h4>{&l[4..]}</h4>},
l if l.starts_with("# ") => html! {<h1>{combined_html}</h1>},
l if l.starts_with("## ") => html! {<h2>{combined_html}</h2>},
l if l.starts_with("### ") => html! {<h3>{combined_html}</h3>},
l if l.starts_with("#### ") => html! {<h4>{combined_html}</h4>},
l if l.starts_with("```") => {
html! {<p><code lang="rust">{line.replace("```", "")}</code></p>}
}
l if l.starts_with("---") => html! {<hr/>},
l if l.starts_with("___") => html! {<hr/>},
l if l.starts_with("-") => html! {<li>{&l[1..]}</li>},
l if l.is_empty() => html! {<br/>},
_ => html! {<p>{combined_html}</p>},
}
Expand Down

0 comments on commit f83580a

Please sign in to comment.