Inline files
This commit is contained in:
parent
ed769102de
commit
dc13ef503c
4 changed files with 234 additions and 54 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use crate::config::Config;
|
||||
|
||||
use linemd::Parser;
|
||||
|
||||
pub struct Renderer {
|
||||
|
|
@ -10,7 +12,14 @@ impl Renderer {
|
|||
hl_registry.link_grammars();
|
||||
Self { hl_registry }
|
||||
}
|
||||
pub fn render(&self, filetype: &str, content: &[u8], pretty: bool) -> String {
|
||||
pub fn render(&self, config: &Config, filetype: &str, content: &[u8], pretty: bool, repo_hash_str: &str, file_path: &str) -> String {
|
||||
if config.image_extensions.contains_key(filetype) {
|
||||
return format!(r#"<img alt="No description" src="/inline/{repo_hash_str}/{file_path}"/>"#)
|
||||
} else if config.video_extensions.contains_key(filetype) {
|
||||
return format!(r#"<video src="/inline/{repo_hash_str}/{file_path}"></video>"#)
|
||||
} else if config.audio_extensions.contains_key(filetype) {
|
||||
return format!(r#"<audio src="/inline/{repo_hash_str}/{file_path}"></audio>"#)
|
||||
}
|
||||
let Ok(content) = str::from_utf8(content) else {
|
||||
return String::from("Cannot render file as it is not valid UTF-8.");
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue