blob: 4a56e6bbbb0c0f7c204aa3e69ff6654201d0c589 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
use crate::error::SiteError;
use crate::page::PageMeta;
use crate::site::Site;
use crate::wikitext::ParsedDirective;
use log::trace;
use std::path::Path;
#[derive(Debug, Eq, PartialEq)]
pub struct Img {
src: String,
}
impl Img {
pub const REQUIRED: &'static [&'static str] = &[];
pub const ALLOWED: &'static [&'static str] = &["class"];
pub const ALLOW_ANY_UNNAMED: bool = true;
pub fn new(src: String) -> Self {
Self {
src,
}
}
pub fn process(&self, site: &Site, meta: &mut PageMeta) -> Result<String, SiteError> {
trace!("verify image exists: {}", self.src);
let src = site.resolve(meta.path(), Path::new(&self.src))?;
trace!("img src={:?}", src.display());
Ok(format!("![]({})", self.src))
}
}
impl From<ParsedDirective> for Img {
fn from(p: ParsedDirective) -> Self {
Img::new(p.unnamed_arg().expect("img must have filename argument").into())
}
}
|