From 382b0bef72cbad2e4f199795075636df1e2c782c Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 6 Nov 2020 16:52:57 +0100 Subject: [PATCH] Add anchor extraction to link string extraction --- lua/zettelkasten/link.lua | 5 ++--- lua/zettelkasten/link_spec.lua | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lua/zettelkasten/link.lua b/lua/zettelkasten/link.lua index 0ea2082..5172a5e 100644 --- a/lua/zettelkasten/link.lua +++ b/lua/zettelkasten/link.lua @@ -77,7 +77,8 @@ function L.extract_all(input) ref = ref, text = text, startpos = startpos, - endpos = endpos + endpos = endpos, + anchor = a.extract(ref) }) curpos = endpos end @@ -88,8 +89,6 @@ end return { new = L.new, create = L.create, - style_wiki = L.style_wiki, - style_markdown = L.style_markdown, append_extension = L.append_extension, urlify = L.urlify, extract_all = L.extract_all diff --git a/lua/zettelkasten/link_spec.lua b/lua/zettelkasten/link_spec.lua index 256bf47..f28033c 100644 --- a/lua/zettelkasten/link_spec.lua +++ b/lua/zettelkasten/link_spec.lua @@ -91,3 +91,26 @@ describe("new", function() assert.is_not_nil(result:match("%[%[[^|]+%]%]")) end) end) + +describe("extract_all", function() + it("should get all links input string", function() + local input = "[Some text](2003042042_my-link.md) and another, [with more text](2001261123 another-link.md), and done. " + local expected = { + { + endpos = 34, + ref = "2003042042_my-link.md", + startpos = 1, + text = "Some text", + anchor = "2003042042" + }, { + endpos = 92, + ref = "2001261123 another-link.md", + startpos = 49, + text = "with more text", + anchor = "2001261123" + } + } + + assert.same(expected, link.extract_all(input)) + end) +end)