Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible encoding issue with ObsidianFollowLink #176

Closed
ErenKyojin opened this issue Aug 19, 2023 · 5 comments
Closed

Possible encoding issue with ObsidianFollowLink #176

ErenKyojin opened this issue Aug 19, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@ErenKyojin
Copy link

🐛 Describe the bug

I'm not sure if this is a bug, an inetnded feature, or something which might be editable in settings but i have a really big vault with a lot of links i wrote "manually" with different cases compared to the actual file name, the issue is that while obsidian opens the correct file without any issue, in neovim i get a new file generated in the root folder every time.

Versions

~ nvim --version
NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3
~ nvim --headless -c 'lua print("Obsidian v" .. require("obsidian").VERSION)' -c q
Obsidian v1.12.0
@ErenKyojin ErenKyojin added the bug Something isn't working label Aug 19, 2023
@epwalsh
Copy link
Owner

epwalsh commented Aug 23, 2023

It's not intended to be case sensitive, and it works as expected for me. Can you give me a particular example (note name and link) that doesn't work for you?

@ErenKyojin
Copy link
Author

Actually the issue might be with aliases, not with case sensitivity, and maybe there's also the fact that they are in sub-folders
Running ObsidianFollowLink on the link [[Tensione|differenza di potenziale]], which should bring me to the file vaultroot/elettrotecnica/tensione.md, creates a new file vaultroot/tensione.md.
The same happens for, as another example, the link [[campi di forze conservative|campo conservativo]] creates vaultroot/campi di forze conservative instead of opening vaultroot/fisica/campi di forze conservative.

Sorry about the confusion and the late reply.

@epwalsh
Copy link
Owner

epwalsh commented Sep 4, 2023

Hey @ErenKyojin, thanks for the additional info. Unfortunately I still wasn't able to reproduce the issue. If you get a chance to try to debug this yourself, the relevant logic is all in here:

local note_name = current_line:sub(open, close)
if note_name:match "^%[.-%]%(.*%)$" then
-- transform markdown link to wiki link
note_name = note_name:gsub("^%[(.-)%]%((.*)%)$", "%2|%1")
else
-- wiki link
note_name = note_name:sub(3, #note_name - 2)
end
-- Split note file name/path from note name/alias.
local note_file_name = note_name
if note_name:match "|[^%]]*" then
note_file_name = note_file_name:sub(1, note_file_name:find "|" - 1)
note_name = note_name:sub(note_name:find "|" + 1, note_name:len())
end
-- Check if it's a URL.
if note_file_name:match "^[%a%d]*%:%/%/" then
if client.opts.follow_url_func ~= nil then
client.opts.follow_url_func(note_file_name)
else
echo.warn(
"This looks like a URL. You can customize the behavior of URLs with the 'follow_url_func' option.",
client.opts.log_level
)
end
return
end
-- Remove header link from the end if there is one.
local header_link = note_file_name:match "#[%a%d-_]+$"
if header_link ~= nil then
note_file_name = note_file_name:sub(1, -header_link:len() - 1)
end
-- Ensure file name ends with suffix.
if not note_file_name:match "%.md" then
note_file_name = note_file_name .. ".md"
end
-- Search for matching notes.
local notes = util.find_note(client.dir, note_file_name)
if #notes < 1 then
local aliases = note_name == note_file_name and {} or { note_name }
local note = client:new_note(note_file_name, nil, nil, aliases)
vim.api.nvim_command("e " .. tostring(note.path))
elseif #notes == 1 then
local path = notes[1]
vim.api.nvim_command("e " .. tostring(path))
else
echo.err("Multiple notes with this name exist", client.opts.log_level)
return
end

flaviosakakibara pushed a commit to flaviosakakibara/obsidian.nvim that referenced this issue Sep 5, 2023
@lpanebr
Copy link

lpanebr commented Sep 7, 2023

Indeed the second example debunks the case sensitivity add a culprit...

I remember having this issue also but I'm very behind on my taking notes habit..

Also I'm avoiding the computer due to lower back pain ATM.

From the behavior and code above it's clear that the util.find_note(client.dir, note_file_name) is not returning anything as #notes < 1 is true.

I've reviewed the code from util.find_note to plenary s scan_dir and is_file and all seems perfect. I reached my limit at Path:_stat() in
https://github.com/nvim-lua/plenary.nvim/blob/0dbe561ae023f02c2fb772b879e905055b939ce3/lua/plenary/path.lua#L283C35-L283C35

Then I kind of remember thinking that my issue also happened when my notes filename had accented characters like essência.md (maybe it's something to do with encoding?)

@ErenKyojin ErenKyojin changed the title ObsidianFollowLink is case sensitive Possible encoding issue with ObsidianFollowLink Sep 10, 2023
@epwalsh
Copy link
Owner

epwalsh commented Feb 22, 2024

If this is still an issue I'll reopen.

@epwalsh epwalsh closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants