Add anchor extraction to link string extraction

This commit is contained in:
Marty Oehme 2020-11-06 16:52:57 +01:00
parent 30e0519a1f
commit 382b0bef72
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 25 additions and 3 deletions

View file

@ -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

View file

@ -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)