mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
refact: move escape and remove alias
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
--- Escapes Lua pattern characters for use in gsub
|
||||
function M.escape(s)
|
||||
-- return s:gsub("[^%w]", "%%%1") -- Escape everything ?
|
||||
return s:gsub("[%%%]%^%-$().[*+?]", "%%%1")
|
||||
end
|
||||
|
||||
--- Returns string with listed chars removed (= safer gsub)
|
||||
function M.strip(s, chars_to_remove)
|
||||
return s:gsub("[" .. M.escape(chars_to_remove) .. "]", "")
|
||||
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)
|
||||
|
||||
@@ -128,4 +128,15 @@ M.generate_backlink_map = function(opts)
|
||||
return ret
|
||||
end
|
||||
|
||||
-- Remove alias in links to get only link part
|
||||
-- [[my_cool_link | My Alias]] -> "my_cool_link"
|
||||
--
|
||||
function M.remove_alias(link)
|
||||
local split_index = string.find(link, "%s*|")
|
||||
if split_index ~= nil and type(split_index) == "number" then
|
||||
return string.sub(link, 0, split_index - 1)
|
||||
end
|
||||
return link
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user