Skip to content

Commit

Permalink
Fix finding backlinks with URL encoded paths
Browse files Browse the repository at this point in the history
Closes #585.
  • Loading branch information
epwalsh committed May 16, 2024
1 parent a9978d0 commit 6943cb4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Made workspace detection more robust.
- Fixed regression where frontmatter is updated in template files.
- Fixed finding backlinks with URL-encoded path references.

## [v3.7.12](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.12) - 2024-05-02

Expand Down
56 changes: 32 additions & 24 deletions lua/obsidian/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1279,30 +1279,38 @@ Client.find_backlinks_async = function(self, note, callback, opts)

-- Prepare search terms.
local search_terms = {}
for ref in iter { tostring(note.id), note:fname(), self:vault_relative_path(note.path) } do
if ref ~= nil then
if anchor == nil and block == nil then
-- Wiki links without anchor/block.
search_terms[#search_terms + 1] = string.format("[[%s]]", ref)
search_terms[#search_terms + 1] = string.format("[[%s|", ref)
-- Markdown link without anchor/block.
search_terms[#search_terms + 1] = string.format("(%s)", ref)
-- Wiki links with anchor/block.
search_terms[#search_terms + 1] = string.format("[[%s#", ref)
-- Markdown link with anchor/block.
search_terms[#search_terms + 1] = string.format("(%s#", ref)
elseif anchor then
-- Note: Obsidian allow a lot of different forms of anchor links, so we can't assume
-- it's the standardized form here.
-- Wiki links with anchor.
search_terms[#search_terms + 1] = string.format("[[%s#", ref)
-- Markdown link with anchor.
search_terms[#search_terms + 1] = string.format("(%s#", ref)
elseif block then
-- Wiki links with block.
search_terms[#search_terms + 1] = string.format("[[%s#%s", ref, block)
-- Markdown link with block.
search_terms[#search_terms + 1] = string.format("(%s#%s", ref, block)
for raw_ref in iter { tostring(note.id), note:fname(), self:vault_relative_path(note.path) } do
for ref in
iter(util.tbl_unique {
raw_ref,
util.urlencode(tostring(raw_ref)),
util.urlencode(tostring(raw_ref), { keep_path_sep = true }),
})
do
if ref ~= nil then
if anchor == nil and block == nil then
-- Wiki links without anchor/block.
search_terms[#search_terms + 1] = string.format("[[%s]]", ref)
search_terms[#search_terms + 1] = string.format("[[%s|", ref)
-- Markdown link without anchor/block.
search_terms[#search_terms + 1] = string.format("(%s)", ref)
-- Wiki links with anchor/block.
search_terms[#search_terms + 1] = string.format("[[%s#", ref)
-- Markdown link with anchor/block.
search_terms[#search_terms + 1] = string.format("(%s#", ref)
elseif anchor then
-- Note: Obsidian allow a lot of different forms of anchor links, so we can't assume
-- it's the standardized form here.
-- Wiki links with anchor.
search_terms[#search_terms + 1] = string.format("[[%s#", ref)
-- Markdown link with anchor.
search_terms[#search_terms + 1] = string.format("(%s#", ref)
elseif block then
-- Wiki links with block.
search_terms[#search_terms + 1] = string.format("[[%s#%s", ref, block)
-- Markdown link with block.
search_terms[#search_terms + 1] = string.format("(%s#%s", ref, block)
end
end
end
end
Expand Down

0 comments on commit 6943cb4

Please sign in to comment.