diff --git a/demo/issue-1/first.md b/demo/issue-1/first.md index 50b7d5e..257470f 100644 --- a/demo/issue-1/first.md +++ b/demo/issue-1/first.md @@ -1,4 +1,3 @@ - # The first article of Issue 1 Hello Zine. @@ -17,4 +16,9 @@ Text 2 fn main() { println!("{}", "Hello, Zine!"); } -``` \ No newline at end of file +``` + +```gallery +/static/duck.png +/static/zine.png +``` diff --git a/src/code_blocks/gallery.rs b/src/code_blocks/gallery.rs new file mode 100644 index 0000000..04b2d05 --- /dev/null +++ b/src/code_blocks/gallery.rs @@ -0,0 +1,32 @@ +use std::fmt::Write; + +use super::CodeBlock; + +pub struct GalleryBlock<'a> { + images: Vec<&'a str>, +} + +// enum GalleryMode { +// Grid, +// Slide, +// } + +impl<'a> GalleryBlock<'a> { + pub fn new(block: &'a str) -> Self { + let images = block.lines().collect(); + GalleryBlock { images } + } +} + +impl<'a> CodeBlock for GalleryBlock<'a> { + fn render(&self) -> anyhow::Result { + let mut html = String::new(); + + writeln!(&mut html, r#""#)?; + Ok(html) + } +} diff --git a/src/code_blocks/mod.rs b/src/code_blocks/mod.rs index 3c1c9b5..74e76d4 100644 --- a/src/code_blocks/mod.rs +++ b/src/code_blocks/mod.rs @@ -4,10 +4,12 @@ use anyhow::{bail, Result}; mod author; mod callout; +mod gallery; mod url_preview; use crate::{data, engine::Vistor, helpers, html}; pub use author::AuthorCode; +use gallery::GalleryBlock; use url_preview::{UrlPreviewBlock, UrlPreviewError}; use self::callout::CalloutBlock; @@ -17,9 +19,10 @@ pub trait CodeBlock { } const CALLOUT: &str = "callout"; +const GALLERY: &str = "gallery"; const URL_PREVIEW: &str = "urlpreview"; -const ALL_CODE_BLOCKS: &[&str] = &[CALLOUT, URL_PREVIEW]; +const ALL_CODE_BLOCKS: &[&str] = &[CALLOUT, GALLERY, URL_PREVIEW]; #[derive(Debug, Default, PartialEq, Eq)] pub struct Fenced<'a> { @@ -78,6 +81,10 @@ impl<'a> Fenced<'a> { .unwrap(); Some(html) } + GALLERY => { + let html = GalleryBlock::new(block).render().unwrap(); + Some(html) + } _ => None, } }