diff options
Diffstat (limited to 'src/forms.rs')
-rw-r--r-- | src/forms.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/forms.rs b/src/forms.rs index 15a22cf..b987aca 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -1,9 +1,13 @@ +use std::os::unix::prelude::OsStrExt; + use hyper::http::request::Parts; use serde::Deserialize; use sputnik::html_escape; use crate::{action_links, controller::Controller, get_renderer, Context, Error, Page, Response}; +const FILE_EXT_WITH_SPELLCHECK: &[&[u8]] = &[b"md", b"txt"]; + fn render_error(message: &str) -> String { format!("<div class=error>error: {}</div>", html_escape(message)) } @@ -53,7 +57,13 @@ pub fn edit_text_form<'a, C: Controller>( } page.body.push_str(&format!( "<form method=post action='?action=edit' class=edit-form>\ - <textarea name=text autofocus autocomplete=off>{}</textarea>", + <textarea name=text autofocus autocomplete=off spellcheck={}>{}</textarea>", + FILE_EXT_WITH_SPELLCHECK.contains( + &ctx.path + .extension() + .map(|e| e.as_bytes()) + .unwrap_or_default() + ), html_escape(&data.text) )); page.body |