epwalsh / obsidian.nvim

Obsidian 🤝 Neovim
Apache License 2.0
3.3k stars 150 forks source link

:ObsidianBackLinks doesn't work when md links have %20 #585

Closed huantrinh1802 closed 1 month ago

huantrinh1802 commented 1 month ago

🐛 Describe the bug

After creating a file using cmp, the created link looks like this in ## [Background Service](pages/Background%20Service.md).

The gf/:ObsidianFollowLink works but :ObsidianBackLinks doesn't find any reference in the vault No backlinks found for note 'Background Service'

Config

    "epwalsh/obsidian.nvim",
    version = "*", -- recommended, use latest release instead of latest commit
    dependencies = {
      -- Required.
      "nvim-lua/plenary.nvim",
    },
    config = function()
      local obsidian = require("obsidian")
      obsidian.setup({
        workspaces = {
          {
            name = "work",
            path = "~/repo/huantrinh1802_note/works",
          },
          {
            name = "personal",
            path = "~/repo/huantrinh1802_note/personal",
          },
          {
            name = "no-vault",
            path = function()
              return assert(vim.fs.dirname(vim.api.nvim_buf_get_name(0)))
            end,
            overrides = {
              notes_subdir = vim.NIL, -- have to use 'vim.NIL' instead of 'nil'
              new_notes_location = "current_dir",
              templates = {
                subdir = vim.NIL,
              },
              daily_notes = { folder = vim.NIL },
              disable_frontmatter = true,
            },
          },
        },
        note_id_func = function(title)
          return title
        end,
        notes_subdir = "pages",
        daily_notes = {
          -- Optional, if you keep daily notes in a separate directory.
          folder = "journals",
          -- Optional, if you want to change the date format for the ID of daily notes.
          date_format = "%Y/%m/%d",
          -- Optional, if you want to change the date format of the default alias of daily notes.
          alias_format = "%-d %B, %Y",
          -- Optional, if you want to automatically insert a template from your template directory like 'daily.md'
          template = nil,
        },
        note_frontmatter_func = function(note)
          -- Add the title of the note as an alias.
          local out = { id = note.id, aliases = note.aliases, tags = note.tags, title = note.title }

          -- `note.metadata` contains any manually added fields in the frontmatter.
          -- So here we just make sure those fields are kept in the frontmatter.
          if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
            for k, v in pairs(note.metadata) do
              out[k] = v
            end
          end

          return out
        end,
        mappings = {
          -- Overrides the 'gf' mapping to work on markdown/wiki links within your vault.
          ["gf"] = {
            action = function()
              return require("obsidian").util.gf_passthrough()
            end,
            opts = { noremap = false, expr = true, buffer = true },
          },
        },
        ui = {
          checkboxes = {
            -- NOTE: the 'char' value has to be a single character, and the highlight groups are defined below.
            [" "] = { char = "󰄱", hl_group = "ObsidianTodo" },
            ["x"] = { char = "", hl_group = "ObsidianDone" },
            [">"] = { char = "", hl_group = "ObsidianRightArrow" },
            ["~"] = { char = "󰰱", hl_group = "ObsidianTilde" },
            -- Replace the above with this if you don't have a patched font:
            -- [" "] = { char = "☐", hl_group = "ObsidianTodo" },
            -- ["x"] = { char = "✔", hl_group = "ObsidianDone" },

            -- You can also add more custom ones...
          },
          hl_groups = {
            -- The options are passed directly to `vim.api.nvim_set_hl()`. See `:help nvim_set_hl`.
            ObsidianTodo = { bold = true, fg = "#f78c6c" },
            ObsidianDone = { bold = true, fg = "#89ddff" },
            ObsidianRightArrow = { bold = true, fg = "#f78c6c" },
            ObsidianTilde = { bold = true, fg = "#ff5370" },
            ObsidianBullet = { bold = true, fg = "#89ddff" },
            ObsidianRefText = { underline = true, fg = "#008080" },
            ObsidianExtLinkIcon = { fg = "#008080" },
            ObsidianTag = { italic = true, fg = "#89ddff" },
            ObsidianHighlightText = { bg = "#75662e" },
          },
          picker = {
            -- Set your preferred picker. Can be one of 'telescope.nvim', 'fzf-lua', or 'mini.pick'.
            name = "telescope.nvim",
            -- Optional, configure key mappings for the picker. These are the defaults.
            -- Not all pickers support all mappings.
            mappings = {
              -- Create a new note from your query.
              new = "<C-x>",
              -- Insert a link to the selected note.
              insert_link = "<C-l>",
            },
          },
        },
        attachments = {
          -- The default folder to place images in via `:ObsidianPasteImg`.
          -- If this is a relative path it will be interpreted as relative to the vault root.
          -- You can always override this per image by passing a full path to the command instead of just a filename.
          img_folder = "assets/imgs", -- This is the default
          -- A function that determines the text to insert in the note when pasting an image.
          -- It takes two arguments, the `obsidian.Client` and an `obsidian.Path` to the image file.
          -- This is the default implementation.
          ---@param client obsidian.Client
          ---@param path obsidian.Path the absolute path to the image file
          ---@return string
          img_text_func = function(client, path)
            path = client:vault_relative_path(path) or path
            local name, _ = path.name:match("(.+)%.(.*)$")
            return string.format("![%s](/%s)", name, path)
          end,
        },
      })
      local nmap = require("user.utilities").nmap
      nmap("<leader>oo", ":ObsidianOpen<CR>", "[O]bsidian [O]pen")
      nmap("<leader>ob", ":ObsidianBacklinks<CR>", "[O]bsidian [B]acklinks")
      nmap("<leader>oln", ":ObsidianLinkNew<CR>", "[O]bsidian [L]ink [N]ew", { "v" })
      nmap("<leader>os", ":ObsidianSearch<CR>", "[O]bsidian [S]earch")
      nmap("<leader>ow", ":ObsidianWorkspace<CR>", "[O]bsidian [W]orkspace")
      nmap("<leader>oen", ":ObsidianExtractNote<CR>", "[O]bsidian [E]xtract[N]ote")
      nmap("<leader>onn", ":ObsidianNew<CR>", "[O]bsidian [N]ew [N]ote")
      nmap("<leader>otd", ":ObsidianToday<CR>", "[O]bsidian [T]o[d]ay")
      nmap("<leader>otm", ":ObsidianTomorrow<CR>", "[O]bsidian [T]o[m]orrow")
      nmap("<leader>oyd", ":ObsidianYesterday<CR>", "[O]bsidian [y]ester[d]ay")
    end,

Environment

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info
Obsidian.nvim v3.7.12 (db41b1f20459293436fab510bec58c82a73bd1f7)
Status:
  • buffer directory: nil
  • working directory: [REDACTED]/works
Workspaces:
  ✓ active workspace: Workspace(name='work', path='[REDACTED]/repo/huantrinh1802_note/works', root='[REDACTED]/works')
  ✗ inactive workspace: Workspace(name='personal', path='[REDACTED]/personal', root='[REDACTED]/personal')
  ✗ inactive workspace: Workspace(name='no-vault', path='[REDACTED]/works', root='[REDACTED]/works')
Dependencies:
  ✓ plenary.nvim: 08e301982b9a057110ede7a735dd1b5285eb341f
  ✓ nvim-cmp: cd2cf0c124d3de577fb5449746568ee8e601afc8
  ✓ telescope.nvim: 6312868392331c9c0f22725041f1ec2bef57c751
Integrations:
  ✓ picker: TelescopePicker()
  ✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
    all sources:
      • cmp-dbee
      • codeium
      • nvim_lsp
      • otter
      • buffer
      • spell
      • path
      • luasnip
Tools:
  ✓ rg: ripgrep 14.1.0
Environment:
  • operating system: Darwin
Config:
  • notes_subdir: pages%
epwalsh commented 1 month ago

Hey @huantrinh1802, fixed in 6943cb4.