Skip to content

Commit

Permalink
Closes #37: Parse links correctly in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
PetoMPP committed Dec 18, 2023
1 parent 08201d7 commit 3d6f6d6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/atoms/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ pub fn edit_button(props: &EditButtonProps) -> Html {
let (resid, lang) = (props.resid.clone(), locales_store.curr);
let edit_onclick = Callback::from(move |_| {
navigator
.push_with_query(
&Route::Editor,
&ResourceId::from((resid.clone(), lang)),
)
.push_with_query(&Route::Editor, &ResourceId::from((resid.clone(), lang)))
.unwrap()
});

Expand All @@ -156,13 +153,20 @@ fn make_links_clickable(navigator: &Navigator, id: &str) {
let Some(href) = link.get_attribute("href") else {
continue;
};
if let Some(onclick) = Route::get_onclick_from_str(href.as_str(), navigator.clone()) {
link.add_event_listener_with_callback("click", onclick.as_ref().unchecked_ref())
.unwrap();
onclick.forget();
};
if href.starts_with("http") {
link.set_attribute("target", "_blank").unwrap();
match href {
href if href.starts_with("http") => link.set_attribute("target", "_blank").unwrap(),
href if href.starts_with("/") => {
if let Some(onclick) = Route::get_onclick_from_str(href.as_str(), navigator.clone())
{
link.add_event_listener_with_callback(
"click",
onclick.as_ref().unchecked_ref(),
)
.unwrap();
onclick.forget();
}
}
_ => {}
}
}
}
Expand Down

0 comments on commit 3d6f6d6

Please sign in to comment.