From 3d6f6d69ddb4029ae265ac76e52fefee65e6b0da Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Mon, 18 Dec 2023 16:16:14 +0100 Subject: [PATCH] Closes #37: Parse links correctly in markdown --- src/components/atoms/markdown.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/atoms/markdown.rs b/src/components/atoms/markdown.rs index 9fc53db..2dad36d 100644 --- a/src/components/atoms/markdown.rs +++ b/src/components/atoms/markdown.rs @@ -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() }); @@ -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(); + } + } + _ => {} } } }