obsidian.nvim icon indicating copy to clipboard operation
obsidian.nvim copied to clipboard

`gq` breaks obsidian links

Open eblume opened this issue 1 year ago • 0 comments

🐛 Describe the bug

Markdown links are broken by gq. Is this something Obsidian.nvim can fix? As I understand it, it's possible I can set something with an Autocmd or with formatoptions but I'm at a bit of a loss.

I would also of course be happy if Obsidian.nvim was simply able to recognize links broken this way and follow them -- in fact that would probably be even nicer, as these links are often very long and very format-breaking anyway due to the conceallevel things Obsidian.nvim is doing (ie the URL may be auto-hidden or not).

What follows is an example of two lines, one uses a long filepath and one uses a long markdown url. Hold a cursor over either line, type gq, and observe that for the first line the filepath is preserved while on the second the link is broken with a newline character.

Here is a very long line with a long filepath looking thing `/an/example/long/filepath/thatis/way/past/the/max/line/length`

Here is a very long line with a [long markdown url link](http://example.com/an/example/long/filepath/)

For the example to work you'll probably have to have some textwidth value but weirdly I get textwidth=0 when I :set textwidth?, so ... maybe that's related somehow?

Config

-- Obsidian.nvim has features that require conceallevel > 0
vim.api.nvim_create_autocmd("FileType", {
    pattern = "markdown",
    callback = function()
        vim.o.conceallevel = 1
    end,
})

-- Init largely copied from:
-- https://github.com/epwalsh/obsidian.nvim
require('obsidian').setup({
    workspaces = {
        -- Attempt to use $ZK_PROJECT dynamically
        {
            name = "zk-project",
            path = function()
                return assert(os.getenv("ZK_PROJECT"))
            end,
            -- strict = true, -- might be needed if links are broken, unclear
            -- (Also there is an overrides = {...} for proj-specific settings, hmm)
        },
        -- Default workspace for my primary 'zk' knowledge base, matches last:
        {
            name = "zk",
            path = "~/code/personal/zk",
        },
    },

    -- This *should* be synced via the vault's sync community plugins setting, but if not:
    --  Enabled:
    --     * Use UID instead of file paths
    --     * Add filepath parameter
    -- This is intended to make hyperlinks work across multiple vaults, so that
    -- I can make portable cross-project links. Using a UID in the URI means
    -- that file move operations are nondestructive. Tbe tradeoff is that every
    -- link will be pretty long, but conceallevel=1 helps with that.
    use_advanced_uri = true,

    -- NOTE: :ObsidianOpen is currently broken due to nix-darwin's packaging of Obsidian.app
    -- There was a PR open that got closed without merging that would have fixed this.
    -- I've left a comment here: https://github.com/epwalsh/obsidian.nvim/issues/304

    picker = {
        name = "telescope.nvim",
        new = "<C-x>",         -- Create a new note from telescope query
        insert_link = "<C-l>", -- Create a new link to telescope selected quote
    },
    tag_mappings = {
        tag_note = "<C-x>",   -- Add tag(s) to current note
        insert_tag = "<C-l>", -- Insert a tag at the current location
    },

    -- Recommended to sort modified/true for most recent edits first
    sort_by = "modified",
    sort_reversed = true,

    -- "current", "vsplit", "hsplit"
    open_notes_in = "current",

    ui = {
        enable = true,          -- refers to all the conceallevel tricks, I think
        max_file_length = 5000, -- Large files get crunchy, I think - not seen yet
        checkboxes = {
            -- I don't quite understand this array-keyed syntax, and it stumped me for having this config in obsiadian.nix
            -- (I guess that it's not an array but some sort of literal identifier, but no time to check now how to nixify)
            [" "] = { char = "󰄱", hl_group = "ObsidianTodo" },
            ["x"] = { char = "", hl_group = "ObsidianDone" },
            [">"] = { char = "", hl_group = "ObsidianRightArrow" },
            ["~"] = { char = "󰰱", hl_group = "ObsidianTilde" },
            ["!"] = { char = "", hl_group = "ObsidianImportant" },
        },
    },

    follow_url_func = vim.ui.open,
})

Environment

dotfiles  main @ 2efc249 6s
❯ nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info

dotfiles  main @ 2efc249
❯ nvim --headless -c 'lua require("obsidian").info()' -c q
Obsidian.nvim v3.7.14 (unknown commit)
Status:
  • buffer directory: nil
  • working directory: /Users/eblume/code/personal/dotfiles
Workspaces:
  ✓ active workspace: Workspace(name='zk-project', path='/Users/eblume/code/personal/zk', root='/Users/eblume/code/personal/zk')
  ✗ inactive workspace: Workspace(name='zk', path='/Users/eblume/code/personal/zk', root='/Users/eblume/code/personal/zk')
Dependencies:
  ✓ plenary.nvim: unknown
  ✓ nvim-cmp: unknown
  ✓ telescope.nvim: unknown
Integrations:
  ✓ picker: TelescopePicker()
  ✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
    all sources:
      • nvim_lua
      • nvim_lsp
      • path
      • buffer
      • rg
Tools:
  ✓ rg: ripgrep 14.1.0
Environment:
  • operating system: Darwin
Config:
  • notes_subdir: nil⏎        

eblume avatar Aug 27 '24 21:08 eblume