diff --git a/.env.example b/.env.example
index 451521b..48f9687 100644
--- a/.env.example
+++ b/.env.example
@@ -87,3 +87,15 @@
# Custom HTML template file with {{title}}, {{form}}, {{entries}}, and {{style}} placeholders.
# Uses built-in default if unset.
# BOOK_TEMPLATE=./templates/default.html
+
+# Enable drawing canvas in submission form. Drawings are stored as PNG files in DATA_DIR/drawings/.
+# BOOK_ENABLE_DRAWINGS=false
+
+# Label for the drawing canvas.
+# BOOK_LABEL_DRAWING=Draw (optional):
+
+# Drawing canvas width in pixels.
+# BOOK_CANVAS_WIDTH=400
+
+# Drawing canvas height in pixels.
+# BOOK_CANVAS_HEIGHT=200
diff --git a/src/render.rs b/src/render.rs
index ed72b41..338f756 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -38,6 +38,48 @@ pub fn render_form(config: &Config) -> String {
String::new()
};
+ let drawing_section = if config.enable_drawings {
+ format!(
+ r##"
+
+
+Reset
+
+"##,
+ label = config.label_drawing,
+ w = config.canvas_width,
+ h = config.canvas_height,
+ )
+ } else {
+ String::new()
+ };
+
format!(
r#"{prompt}
"#,
@@ -57,6 +100,7 @@ pub fn render_form(config: &Config) -> String {
rows = config.textarea_rows,
cols = config.textarea_cols,
captcha_section = captcha_section,
+ drawing_section = drawing_section,
button = config.button_text,
)
}
@@ -100,8 +144,16 @@ fn render_entry(entry: &Entry, config: &Config) -> String {
} else {
escape_html(&entry.body)
};
+ let drawing_html = if !entry.meta.drawing.is_empty() {
+ format!(
+ "\n
",
+ escape_html(&entry.meta.drawing)
+ )
+ } else {
+ String::new()
+ };
format!(
- "\n{header}\n\n{body}\n\n{}\n",
+ "\n{header}\n\n{body}{drawing_html}\n\n{}\n",
config.separator
)
}
@@ -322,4 +374,56 @@ mod tests {
"<b>test</b> & "quotes" 'apos'"
);
}
+
+ #[test]
+ fn test_render_form_shows_canvas_when_drawings_enabled() {
+ let mut config = test_config();
+ config.enable_drawings = true;
+ let form = render_form(&config);
+ assert!(form.contains("