diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 6446e5d..ab42de2 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -341,6 +341,12 @@ local function save_all_tk_buffers() end end +-- strip an extension from a file name, escaping "." properly, eg: +-- strip_extension("path/Filename.md", ".md") -> "path/Filename" +local function strip_extension(str, ext) + return str:gsub("(" .. ext:gsub("%.", "%%.") .. ")$", "") +end + -- ---------------------------------------------------------------------------- -- image stuff -- ---------------------------------------------------------------------------- @@ -2009,7 +2015,7 @@ local function CreateNoteSelectTemplate(opts) -- vim.ui.input causes ppl problems - see issue #4 -- vim.ui.input({ prompt = "Title: " }, on_create_with_template) local title = vim.fn.input("Title: ") - title = title:gsub("[" .. M.Cfg.extension .. "]+$", "") + title = strip_extension(title, M.Cfg.extension) if #title > 0 then on_create_with_template(opts, title) end @@ -2086,7 +2092,7 @@ local function CreateNote(opts) end local title = vim.fn.input("Title: ") - title = title:gsub("[" .. M.Cfg.extension .. "]+$", "") + title = strip_extension(title, M.Cfg.extension) if #title > 0 then on_create(opts, title) end