Skip to content
Snippets Groups Projects
Commit a86f5aa3 authored by Stephen D's avatar Stephen D
Browse files

allow specifying raw image links

parent 6c220c2c
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,7 @@ fn content_type(ext: &str) -> anyhow::Result<&'static str> {
"webm" => "video/webm",
"mp4" => "video/mp4",
"ico" => "image/x-icon",
"svg" => "image/svg+xml",
_ => bail!("Unsure how to handle extension {ext}"),
};
......
......@@ -38,6 +38,8 @@ pub struct CustomHtmlHandler {
fallback: DefaultHtmlHandler,
ps: SyntaxSet,
theme: Theme,
in_raw: bool,
}
impl CustomHtmlHandler {
......@@ -54,6 +56,8 @@ impl CustomHtmlHandler {
.themes
.remove("base16-eighties.dark")
.expect("Could not load theme"),
in_raw: false,
})
}
}
......@@ -72,12 +76,19 @@ impl HtmlHandler<Error> for CustomHtmlHandler {
write!(w, "{html}")?;
}
Element::SpecialBlock(block) => match block.name.as_ref() {
"JUSTIFYRIGHT" => {
write!(w, r#"<div class="justify-right">"#)?;
}
"RAW" => {
self.in_raw = true;
}
_ => bail!("Unrecognized special block name {}", block.name),
},
Element::Timestamp(Timestamp::Active { start, .. }) => {
let date = NaiveDate::from_ymd_opt(
start.year.into(),
......@@ -88,9 +99,15 @@ impl HtmlHandler<Error> for CustomHtmlHandler {
write!(w, "{}", date.format("%d %b %Y"))?;
}
Element::Link(Link { path, desc }) if desc.is_none() => {
write!(w, r#"<a href="/img/{path}"><img src="/thumb/{path}">"#)?;
if self.in_raw {
write!(w, r#"<a href="/img/{path}"><img src="/img/{path}">"#)?;
} else {
write!(w, r#"<a href="/img/{path}"><img src="/thumb/{path}">"#)?;
}
}
Element::Keyword(Keyword { key, value, .. }) if key == "VIDEO" => {
write!(
w,
......@@ -110,11 +127,18 @@ impl HtmlHandler<Error> for CustomHtmlHandler {
"JUSTIFYRIGHT" => {
write!(w, "</div>")?;
}
"RAW" => {
self.in_raw = false;
}
_ => bail!("Unrecognized special block name {}", block.name),
},
Element::Link(Link { desc, .. }) if desc.is_none() => {
write!(w, r#"</img></a>"#)?;
}
// fallback to default handler
_ => self.fallback.end(w, element)?,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment