diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-06 13:53:21 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-06 17:40:08 +0100 |
| commit | 149e2b055bbf19d6908d825817f2edbb6bb66abb (patch) | |
| tree | e4f1dc3bccfa987365d14d28a97b27506086e236 /docs/src/html.rs | |
| parent | 7d28e6499e1094c1e7c340fe95d3ecd543993f3b (diff) | |
Custom link callback
Diffstat (limited to 'docs/src/html.rs')
| -rw-r--r-- | docs/src/html.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/docs/src/html.rs b/docs/src/html.rs index d9826848..550e6ff8 100644 --- a/docs/src/html.rs +++ b/docs/src/html.rs @@ -48,6 +48,7 @@ impl Html { let mut raw = String::new(); md::html::push_html(&mut raw, iter); raw.truncate(raw.trim_end().len()); + Html { md: text.into(), raw, description } } @@ -171,19 +172,23 @@ impl<'a> Handler<'a> { true } - fn handle_image(&self, path: &str) -> String { - let data = IMAGES - .get_file(path) - .unwrap_or_else(|| panic!("missing image: {path}")) - .contents(); - self.resolver.image(&path, data).into() + fn handle_image(&self, link: &str) -> String { + if let Some(file) = IMAGES.get_file(link) { + self.resolver.image(&link, file.contents()).into() + } else if let Some(url) = self.resolver.link(link) { + url + } else { + panic!("missing image: {link}") + } } fn handle_link(&self, link: &str) -> Option<String> { - if link.starts_with(['#', 'h']) { + if link.starts_with('#') || link.starts_with("http") { return Some(link.into()); - } else if !link.starts_with('$') { - return None; + } + + if !link.starts_with('$') { + return self.resolver.link(link); } let root = link.split('/').next()?; @@ -196,9 +201,10 @@ impl<'a> Handler<'a> { "$styling" => "/docs/reference/styling/", "$scripting" => "/docs/reference/scripting/", "$types" => "/docs/reference/types/", - "$community" => "/docs/community/", "$type" => "/docs/reference/types/", "$func" => "/docs/reference/", + "$changelog" => "/docs/changelog/", + "$community" => "/docs/community/", _ => panic!("unknown link root: {root}"), }; @@ -221,6 +227,7 @@ impl<'a> Handler<'a> { route.push_str(info.category); route.push('/'); route.push_str(name); + route.push('/'); if let Some(param) = param { route.push_str("#parameters--"); route.push_str(param); |
