Inline files

This commit is contained in:
Pascal Engélibert 2026-07-30 23:52:20 +02:00
commit dc13ef503c
4 changed files with 234 additions and 54 deletions

View file

@ -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.");
};