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

Fixes full-pathing links and being able to linkify links #40

Merged
merged 1 commit into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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