Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Fixes full-pathing links and being able to linkify links (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-hansen authored Aug 14, 2021
1 parent 6ecef8b commit 634d874
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lua/zk/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ function M.create_note_link(args)
opts.title = selection.contents
end

if util.is_linkified(opts.title) then
util.error('Attempting to linkify a link, ignoring.')
return
end

print("create_note_link(title) -> ", opts.title)

if opts.title ~= nil and opts.title ~= "" then
Expand Down
8 changes: 5 additions & 3 deletions lua/zk/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end
function M.is_linkified(str)
local current_line = vim.fn.getline(".")
local patterns = {
"%[" .. str .. "%]"
"%[" .. str .. ".*%|?%]"
-- string.format("%{%s%}", str)
}

Expand All @@ -77,12 +77,14 @@ function M.make_link_text(title, path)
return
end

local relative_path = vim.fn.fnamemodify(path, ':.:gs?//?/?')

if zk_config.link_format == "markdown" then
return string.format("[%s](%s)", title, vim.fn.shellescape(path))
return string.format("[%s](%s)", title, relative_path)
elseif zk_config.link_format == "wiki" then
-- TODO: look into supporting link | description:
-- https://github.com/vimwiki/vimwiki/tree/dev#basic-markup
return string.format("[[%s|%s]]", vim.fn.shellescape(path), title)
return string.format("[[%s|%s]]", relative_path, title)
end
end

Expand Down

0 comments on commit 634d874

Please sign in to comment.