aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-07-05 08:29:45 +0200
committerMartin Fischer <martin@push-f.com>2021-07-05 08:32:29 +0200
commit82dae9f41332d55a1d1fcf05aa1223dc260c6f5e (patch)
tree24269d0e59c1b71523c58adf2cf0f51241d6c276
parent61636a80ea8f2137595ae29beb5fa7616e74c58d (diff)
disable textarea spellcheck for ext not in (md, txt)
-rw-r--r--src/forms.rs12
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