Fix link creation failing on empty text
This commit is contained in:
parent
320007e14b
commit
9f1a7eb5ad
2 changed files with 10 additions and 2 deletions
|
@ -23,6 +23,7 @@ end
|
|||
-- Returns text with surrounding whitespace trimmed. Returns empty string
|
||||
-- if only whitespace.
|
||||
local function trimmed(text)
|
||||
if not text then return end
|
||||
return text:match '^()%s*$' and '' or text:match '^%s*(.*%S)'
|
||||
end
|
||||
|
||||
|
@ -45,7 +46,8 @@ function L.style_wiki(link, text)
|
|||
return "[[" .. link .. pipe .. "]]"
|
||||
end
|
||||
|
||||
-- Returns a correctly formatted link to a new zettel.
|
||||
-- Returns a correctly formatted link to a zettel.
|
||||
-- Requires an anchor to be passed in.
|
||||
-- Takes an optional link text which will be added to the link.
|
||||
-- Takes an optional style according to which the link will be transformed.
|
||||
function L.create(anchor, text, style)
|
||||
|
|
|
@ -61,7 +61,7 @@ describe("style_wiki", function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe("create_link", function()
|
||||
describe("create", function()
|
||||
it("should create a working link using set options in vim", function()
|
||||
vim.g.zettel_extension = ".md"
|
||||
vim.g.zettel_anchor_separator = "_"
|
||||
|
@ -76,4 +76,10 @@ describe("create_link", function()
|
|||
assert.same("[[1910291645|My FILE NAME]]",
|
||||
link.create("1910291645", "My FILE NAME", "wiki"))
|
||||
end)
|
||||
it("should handle empty text", function()
|
||||
vim.g.zettel_extension = ".wiki"
|
||||
vim.g.zettel_anchor_separator = "_"
|
||||
vim.g.zettel_link_style = "wiki"
|
||||
assert.same("[[1910291645]]", link.create("1910291645"))
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue