aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lua.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 70f63c5..6c68605 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -2,6 +2,7 @@ use std::fmt::Display;
use std::path::Path;
use std::str::from_utf8;
+use percent_encoding::utf8_percent_encode;
use rlua::Function;
use rlua::HookTriggers;
use rlua::Lua;
@@ -47,6 +48,13 @@ pub fn lua_context<A>(run: impl FnOnce(rlua::Context) -> rlua::Result<A>) -> rlu
.eval::<Table>()
.expect("error in api.lua");
+ api.set(
+ "encode_uri_component",
+ ctx.create_function(|_ctx, text: String| {
+ Ok(utf8_percent_encode(&text, percent_encoding::NON_ALPHANUMERIC).to_string())
+ })?,
+ )?;
+
ctx.globals().raw_set("gitpad", api).unwrap();
run(ctx)