aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-10-28 12:56:03 +0200
committerMartin Fischer <martin@push-f.com>2022-10-28 12:56:27 +0200
commitf47ccc6bb07e8f5f2a71f50633c0c6bac4dfde37 (patch)
tree317a8aad10b457233ac71e22d7036bfda4eabb90 /src
parent3433e3dda8917fe02b3b225d5e2829d0ec64946e (diff)
add gitpad.encode_uri_component Lua function
Diffstat (limited to 'src')
-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)